local f0_local0 = module local f0_local1, f0_local2 = ... f0_local0( f0_local1, package.seeall ) CoD.PrintModuleLoad( _NAME ) DEBUG_DISABLE_LUI_SPEECH_PROCESSING = false waitingForOutstandingCommandConfirmation = false root = 0 timerElement = 0 defaultConfidence = 0.16 whatCanISayConfidence = 0.65 pauseConfidence = 0.65 changeViewConfidence = 0.65 showMenuConfidence = 0.65 goBackConfidence = 0.65 muteConfidence = 0.65 compareConfidence = 0.65 shortcutMenuConfidence = 0.65 function EnableGrammars( f1_arg0 ) local f1_local0 = nil f1_local0 = 0 if Engine.HasSpeechFeature() then if f1_arg0 then if 0 < #f1_arg0 then for f1_local4, f1_local5 in ipairs( f1_arg0 ) do Engine.SpeechEnableGrammar( f1_local5, true ) f1_local0 = f1_local0 + 1 end end else DebugPrint( "Speech: WARNING! EnableGrammars() called with no grammar file array!" ) end if 0 < f1_local0 then Engine.SpeechEnable( true ) end end end function DisableGrammars( f2_arg0 ) if Engine.HasSpeechFeature() then if f2_arg0 and #f2_arg0 > 0 then for f2_local3, f2_local4 in ipairs( f2_arg0 ) do Engine.SpeechEnableGrammar( f2_local4, false ) end end Engine.SpeechEnable( false ) end end function Restart( f3_arg0 ) if Engine.HasSpeechFeature() then DisableGrammars( f3_arg0 ) EnableGrammars( f3_arg0 ) end end function PlayGoodSound() if Engine.HasSpeechFeature() and Engine.InFrontend() then if Engine.IsVideoPlaying and Engine.IsVideoPlaying() == true then return end Engine.PlaySound( CoD.SFX.UIKinectCommandGood ) end end function PlayBadSound() if Engine.HasSpeechFeature() and Engine.InFrontend() then if Engine.IsVideoPlaying and Engine.IsVideoPlaying() == true then return end Engine.PlaySound( CoD.SFX.UIKinectCommandBad ) end end function PerformingSpeechAction() if Engine.HasSpeechFeature() then PlayGoodSound() waitingForOutstandingCommandConfirmation = false CancelSpeechFailTimer() end end function SquelchSpeechAction() if Engine.HasSpeechFeature() then waitingForOutstandingCommandConfirmation = false CancelSpeechFailTimer() end end function LaunchSpeechFailTimer() if Engine.HasSpeechFeature() then local f8_local0 = Engine.GetLuiRoot() if f8_local0 then CancelSpeechFailTimer() local self = LUI.UITimer.new( 250, { name = "speech_fail_timer" } ) self.id = "MenuSpeechFailTimer" root = f8_local0 timerElement = self waitingForOutstandingCommandConfirmation = true root:addElement( timerElement ) end end end function CancelSpeechFailTimer() if Engine.HasSpeechFeature() then waitingForOutstandingCommandConfirmation = false if timerElement and timerElement ~= 0 and root and 0 ~= root then root:removeElement( timerElement ) timerElement:close() end root = 0 timerElement = 0 end end ConfidenceOverrideForLanguageTable = { LANGUAGE_ITALIAN = { pause = { overriddenConfidence = 0.32 } }, LANGUAGE_SPANISH = { pause = { overriddenConfidence = 0.32 } }, LANGUAGE_SPANISHNA = { pause = { overriddenConfidence = 0.32 } } } function GetOverriddenConfidenceLevelForLanguage( f10_arg0, f10_arg1, f10_arg2 ) local f10_local0 = ConfidenceOverrideForLanguageTable[f10_arg2] if f10_local0 ~= nil then local f10_local1 = f10_local0[f10_arg0] if f10_local1 ~= nil then DebugPrint( "Speech: Overriding default confidence of " .. tostring( f10_arg1 ) .. " for action \"" .. tostring( f10_local1 ) .. "\" and instead using " .. tostring( f10_local1.overriddenConfidence ) .. " because our language is \"" .. tostring( f10_arg2 ) .. "\"." ) return f10_local1.overriddenConfidence end end return f10_arg1 end function IsOKToProcessSpeechActionForThisController( f11_arg0 ) local f11_local0 = Engine.GetLuiRoot() if not f11_local0 then return false end local f11_local1 = f11_local0.flowManager if f11_local1 and f11_local1.menuInfoStack then for f11_local5, f11_local6 in ipairs( f11_local1.menuInfoStack ) do if f11_local6.menu ~= nil and f11_local6.menu.properties.exclusiveController ~= nil and f11_local6.menu.properties.exclusiveController ~= f11_arg0 then return false end end end return true end function ProcessActionEvent( f12_arg0, f12_arg1, f12_arg2 ) if Engine.HasSpeechFeature() then if DEBUG_DISABLE_LUI_SPEECH_PROCESSING == true then DebugPrint( "Speech: LUI SPEECH IS DISABLED. TOSSING EVENT " .. f12_arg1.action .. " (" .. f12_arg1.confidence .. ")" ) return true elseif IsOKToProcessSpeechActionForThisController( f12_arg1.controller ) == false then DebugPrint( "Speech: AN EXCLUSIVE MENU IS OPEN FOR A CONTROLLER THAT IS NOT CONTROLLER #" .. f12_arg1.controller .. ", THEREFORE WE ARE IGNORING THIS SPEECH COMMAND!" ) return false elseif f12_arg2 and #f12_arg2 > 0 then local f12_local0 = Languages[Engine.GetCurrentLanguage()] local f12_local1 = nil for f12_local5, f12_local6 in ipairs( f12_arg2 ) do if string.lower( f12_arg1.action ) == string.lower( f12_local6.action ) then if GetOverriddenConfidenceLevelForLanguage( f12_arg1.action, f12_local6.confidence, f12_local0 ) <= f12_arg1.confidence then f12_local6.handler( f12_arg0, f12_arg1, f12_local6.extradata ) return true end DebugPrint( "Speech: WARNING! Ignoring \"" .. tostring( f12_arg1.action ) .. "\" because confidence level " .. tostring( f12_arg1.confidence ) .. " < " .. tostring( f12_local6.confidence ) .. "!" ) end end end end return false end LockTable( _M )