oMBRa Posted August 16, 2010 Posted August 16, 2010 Hi, I was trying to do script for recognizing word's decided dynamically during run-time. I have tried doing it in various ways with no result. it will work if you say "open one", but it won't for the word added during run-time. Here is the script: expandcollapse popup$oRecoContext = ObjCreate('SAPI.SpSharedRecoContext') ObjEvent($oRecoContext, 'RecoContext_') $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ConsoleWrite('Error: ' & @error & @CRLF) $oGrammar = $oRecoContext.CreateGrammar() $oGrammar.CmdLoadFromFile(@DesktopDir & '\Dynamic Grammar.xml', 1) $oTopRule = $oGrammar.Rules.FindRule('OPEN') $oFileRule = $oGrammar.Rules.FindRule('FILE_NAME') ;~ $oRule = $oGrammar.Rules.Add('HI', 1, 1) $oState = $oFileRule.InitialState() ;~ $state2 = $oRule.AddState() $oState.AddwordTransition($oState, 'desk') $oGrammar.CmdSetRuleState('OPEN', 1) $oGrammar.Rules.Commit() $oGrammar.CmdSetRuleState('OPEN', 1) ;$oTransitions = $oState.Transitions ;$oGrammar.CmdSetRuleState('OPEN', 1) ;$oTransition = $oTransitions.Item(0) ;$a = $oTransition.PropertyNAME() ;MsgBox(0, '', $a) While 1 Sleep(10) WEnd Func RecoContext_FalseRecognition($iStreamNumber, $vStreamPosition, $iResult) ConsoleWrite("(no recognition)" & @CRLF) EndFunc ;==>RecoContext_FalseRecognition Func RecoContext_Recognition($iStreamNumber, $vStreamPosition, $iRecognitionType , $iResult) ConsoleWrite($iResult.PhraseInfo.GetText() &@CRLF) EndFunc ;==>RecoContext_Recognition Func RecoContext_StartStream($iStreamNumber, $vStreamPosition) ConsoleWrite(Number($iStreamNumber) & @CRLF) EndFunc ;==>RecoContext_StartStream Func MyErrFunc() Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & hex($oMyError.number,8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) Local $err = $oMyError.number If $err = 0 Then $err = -1 $g_eventerror = $err ; to check for after this function returns Exit Endfunc here is the XML file: (save it to a txt file and rename it "Dynamic Grammar.xml") <GRAMMAR LANGID="409"> <RULE NAME="OPEN" TOPLEVEL="ACTIVE"> <PHRASE>open</PHRASE> <RULEREF NAME="FILE_NAME" PROPNAME="NAME"/> </RULE> <RULE NAME="FILE_NAME" DYNAMIC="TRUE"> <L PROPNAME="RANDOM_NAME"> <P VAL="7">one</P> </L> </RULE> </GRAMMAR> I have another question: the SAPI 5.1 documentation says that the "SpSharedRecoContext" implements the "ISpRecoContext" interfaces... but, how can I use it?
oMBRa Posted August 18, 2010 Author Posted August 18, 2010 I think I have found what is the problem... looking here: http://msdn.microsoft.com/en-us/library/ee125282%28v=VS.85%29.aspx The first parameter accepts the "Nothing" keyword... I have tried using 0 or "", but I keep getting the same error: "incompatible types".So, is there a way to translate it?
Juvigy Posted August 18, 2010 Posted August 18, 2010 try this workaround for nothing : Local $oVBS = ObjCreate("ScriptControl") $oVBS.language = "VBScript" Global Const $Nothing = $oVBS.eval("Nothing") $oVBS = $Nothing
oMBRa Posted August 18, 2010 Author Posted August 18, 2010 try this workaround for nothing : Local $oVBS = ObjCreate("ScriptControl") $oVBS.language = "VBScript" Global Const $Nothing = $oVBS.eval("Nothing") $oVBS = $Nothing wow, it worked, nice workaround... thx
oMBRa Posted August 18, 2010 Author Posted August 18, 2010 Can you please post the whole working script? I'm very interested in this, are you planning to post something in the examples forum? Playlet Below there is a little example. In order to use it you obviously need the SAPI SDK 5.1. Just say at the microphone "run notepad" and if the phrase is recognized, notepad should open. expandcollapse popup$oRecoContext = ObjCreate('SAPI.SpSharedRecoContext') If @error Then MsgBox(0, '', 'Object Creation Failed') Exit EndIf ConsoleWrite('You can speak now' & @CRLF) ObjEvent($oRecoContext, 'RecoContext_') Global $oVBS = ObjCreate("ScriptControl") $oVBS.Language = "VBScript" Global Const $oNothing = $oVBS.Eval("Nothing") $oGrammar = $oRecoContext.CreateGrammar() $oTopRule = $oGrammar.Rules.Add('RUN', 1, 0) $oWordsRule = $oGrammar.Rules.Add('WORDS', BitOR(1, 32), 1) $oAfterCmdState = $oTopRule.AddState() $oTopRule.InitialState.AddWordTransition($oAfterCmdState, 'run') $oAfterCmdState.AddRuleTransition($oNothing, $oWordsRule) $oWordsRule.InitialState.AddWordTransition($oNothing, 'notepad') ;~ $oWordsRule.InitialState.AddWordTransition($oNothing, 'whatever') $oGrammar.Rules.Commit() $oGrammar.CmdSetRuleState('RUN', 1) While 1 Sleep(10) WEnd Func RecoContext_FalseRecognition($iStreamNumber, $vStreamPosition, $iResult) ConsoleWrite("(no recognition)" & @CRLF) EndFunc ;==>RecoContext_FalseRecognition Func RecoContext_Recognition($iStreamNumber, $vStreamPosition, $iRecognitionType, $iResult) ConsoleWrite($iResult.PhraseInfo.GetText() & @CRLF) If $iResult.PhraseInfo.Elements.Item(1).DisplayText = 'notepad' Then Run('notepad.exe') EndIf EndFunc ;==>RecoContext_Recognition
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now