А такой код?
Может зависит от битности автохотки? У меня 32 бита.
#Persistent
#SingleInstance
; For voice recognition to work you need Microsoft SAPI installed in your PC, some versions of Windows don't support voice recognition though.
; You may also need to train voice recognition in Windows so that it will understand your voice.
MsgBox, Please wait until voice recognition is activated. You will be notified when that happens. Press OK to continue.
pspeaker := ComObjCreate("SAPI.SpVoice")
;plistener := ComObjCreate("SAPI.SpSharedRecognizer")
plistener:= ComObjCreate("SAPI.SpInprocRecognizer") ; For not showing Windows Voice Recognition widget.
paudioinputs := plistener.GetAudioInputs() ; For not showing Windows Voice Recognition widget.
plistener.AudioInput := paudioinputs.Item(0) ; For not showing Windows Voice Recognition widget.
ObjRelease(paudioinputs) ; Release object from memory, it is not needed anymore.
pcontext := plistener.CreateRecoContext()
pgrammar := pcontext.CreateGrammar()
pgrammar.DictationSetState(0)
prules := pgrammar.Rules()
prulec := prules.Add("wordsRule", 0x1|0x20)
prulec.Clear()
pstate := prulec.InitialState()
; Add here the words to be recognized! Looks like it understands the null pointer.
pstate.AddWordTransition( ComObjParameter(13,0) , "Apple") ; ComObjParemeter(13,0) is value Null for AHK_L
pstate.AddWordTransition( ComObjParameter(13,0) , "Banana") ; ComObjParemeter(13,0) is value Null for AHK_L
prules.Commit()
pgrammar.CmdSetRuleState( "wordsRule", 1)
prules.Commit()
ComObjConnect(pcontext, "On")
If (pspeaker && plistener && pcontext && pgrammar && prules && prulec && pstate)
{
pspeaker.speak("Voice recognition initialisation succeeded. Available voice commands:")
MsgBox, Available Voice recognition initialisation succeeded. Available Voice Commands:`nApple`nBanana
}
Else
{
pspeaker.speak("Starting voice recognition initialisation failed")
MsgBox, Starting voice recognition initialisation failed
}
return
OnRecognition(StreamNum,StreamPos,RecogType,Result)
{
Global pspeaker
Msgbox Command Recognised.
; Grab the text we just spoke and go to that subroutine
pphrase := Result.PhraseInfo()
sText := pphrase.GetText()
pspeaker.Speak("You said " sText)
MsgBox, Command is %sText%
voice_command = %sText%
; Send voice command to execute a code block.
; check if it is a Label
if(IsLabel(voice_command))
gosub, %voice_command%
ObjRelease(pphrase) ;release object from memory
ObjRelease(sText)
}
;;;; Voice command Labels
Apple:
Msgbox, Command Activated: Apple. It could be a function here, but it doesn't do anything.
Return
Banana:
Msgbox, Command Activated: Banana. It could be a function here, but it doesn't do anything.
Return