Sean wrote:
As I said, to use SpInProcRecognizer you have to explicitly claim the (non-trivial) audio input device. I recently added the code to claim it, but didn't add the code to obtain it as I didn't want to encourage using SpInProcRecognizer which would incur another several posts why it causes this or that. As no one posted any other workarounds in Vista, however, there seems to be no choice. To obtain the default audio input device, use
Code:
paudioin := COM_Invoke(paudioinputs:=COM_Invoke(plistener, "GetAudioInputs"), "Item", 0), COM_Release(paudioinputs)
; COM_Release(paudioin) ; add this in an appropriate place!
before
Code:
COM_Invoke(plistener, "AudioInput", paudioin ? "+" . paudioin : "+0")
BTW, not tested.
I know I'm digging up an old post, but I have spent hours now trying to fix this by referencing MSDN.
I am on Windows 7 SP1 and when I try this I get the following error:
Function Name: "AudioInput"
ERROR: (0x80045001)
PROG:
DESC:
HELP: ,0
ERROR2: Type Mismatch.
(0x80020005)
Will Continue?If I apply the line:
Code:
MsgBox % COM_Invoke(paudioin, "GetDescription")
I get the following result:
Microphone (Realtek High Definition Audio)If I apply this line, however:
Code:
MsgBox % paudioin
The following result is a blank Message Box.
I am not sure what I am doing wrong. Below is the exact code I am looking at:
Code:
#Persistent
OnExit, CleanUp
COM_Init()
plistener:= COM_CreateObject("SAPI.SpInProcRecognizer")
;plistener:= COM_CreateObject("SAPI.SpSharedRecognizer")
paudioin := COM_Invoke(paudioinputs:=COM_Invoke(plistener, "GetAudioInputs"), "Item", 0), COM_Release(paudioinputs)
MsgBox % COM_Invoke(paudioin, "GetDescription")
COM_Invoke(plistener, "AudioInput", (paudioin) ? "+" . paudioin : "+0")
pcontext := COM_Invoke(plistener, "CreateRecoContext")
pgrammar := COM_Invoke(pcontext , "CreateGrammar")
COM_Invoke(pgrammar, "DictationSetState", 1)
prules := COM_Invoke(pgrammar, "Rules")
prulec := COM_Invoke(prules, "Add", "wordsRule", 0x1|0x20)
COM_Invoke(prulec, "Clear")
pstate := COM_Invoke(prulec, "InitialState")
; Add here the words to be recognized!
COM_Invoke(pstate, "AddWordTransition", "+" . 0, "Computer")
COM_Invoke(pstate, "AddWordTransition", "+" . 0, "Two")
COM_Invoke(pstate, "AddWordTransition", "+" . 0, "Three")
;;
;COM_Invoke(prules, "Commit")
;COM_Invoke(pgrammar, "CmdSetRuleState", "wordsRule", 1)
;COM_Invoke(prules, "Commit")
pevent := COM_ConnectObject(pcontext, "On")
Return
CleanUp:
COM_Release(paudioin)
COM_Release(pevent)
;COM_Release(pstate)
;COM_Release(prulec)
;COM_Release(prules)
;COM_Release(pgrammar)
COM_Release(pcontext)
COM_Release(plistener)
COM_Term()
ExitApp
OnRecognition(prms, this)
{
presult := COM_DispGetParam(prms, 3, 9)
pphrase := COM_Invoke(presult, "PhraseInfo")
sText := COM_Invoke(pphrase, "GetText")
COM_Release(pphrase)
; Add custom operations from here!
if IsLabel(sText)
GoSub, %sText%
}
Computer:
MsgBox, You Said Computer
return
#Include COM.ahk