Posts: 34
Threads: 14
Joined: Feb 2017
Hello guys!
Help please, can I run macros with voice trigger like that- I talk in microphone word, for example "book," and macros is run?
Posts: 12,071
Threads: 140
Joined: Dec 2002
Simplest example. Uses SAPI -Windows speech engine.
But in my tests it rarely recognized words correctly. Maybe I don't speak English correctly, or need some more settings, or need training, or bad sound level, I don't know.
Function
Speech_recognition
if(getopt(nthreads)>1) ;;allow single instance
,if('Y'=mes("Already running. Exit?" "Speech_recognition" "YN")) EndThread "Speech_recognition"
,ret
typelib SpeechLib {C866CA3A-32F7-11D2-9602-00C04F8EE628} 5.4
SpeechLib.SpSharedRecoContext src._create
ISpRecoContext isrc=+src
;isrc.SetInterest ;;default - only Recognition event
ISpRecoGrammar g
long idGrammar=82658417
isrc.CreateGrammar(idGrammar g)
g.LoadDictation(0 SPLO_STATIC)
g.SetDictationState(SPRS_ACTIVE)
src._setevents("sub.src")
;now wait and process messages. Can either:
;1. Show a message box or dialog.
;2. opt waitmsg 1; wait ...
;3. MessageLoop.
if 1
,mes "QM speech recognition example.[][]Say something while this message box is alive."
else
,AddTrayIcon "$qm$\sound.ico" "QM speech recognition example.[]Ctrl+click to exit."
,opt waitmsg 1
,wait -1 ;;or can wait for some event
#sub src_Recognition
function StreamNumber `StreamPosition RecognitionType SpeechLib.ISpeechRecoResult'Result ;;SpeechLib.ISpeechRecoContext'src
SpeechLib.ISpRecoResult k=+Result
word* w; byte attr
k.GetText(-1 -1 1 &w &attr)
str s.ansi(w)
CoTaskMemFree w
out s ;;the recognized word
;To start a macro, use mac. Don't put macro code here. This function must exit ASAP.
sel s 1
,case "example"
,mac "Example20"
,
,case "simple"
,mac "Simple5"
err+ out _error.description
Posts: 53
Threads: 18
Joined: Feb 2014
Hello,
Gintaras, I want to test this macro but I get this error message
Error in <open ":3092: /1111">Test_voice_command
rc_Recognition: unknown identifier.
Thank you
Great work
Posts: 12,071
Threads: 140
Joined: Dec 2002
Replace these SP_... with -1.
Posts: 53
Threads: 18
Joined: Feb 2014
Posts: 53
Threads: 18
Joined: Feb 2014
Hello
Can it be made to listen just when you keep a key pressed as opposed to having the box with Ok button?
Thanks
Posts: 12,071
Threads: 140
Joined: Dec 2002
Replace 'if 1' with 'if 0'.
Below 'function' line add:
ifk-(J 1) ret ;;do nothing if key ScrollLock is not toggled
Posts: 53
Threads: 18
Joined: Feb 2014
One more thing.
Can it be done with just one key press - same key to trigger the macro and to start listening in Windows Listening app and also evaluate the recognized word in quick macros - all in one go, long press. After processing, stop listening in Windows listening app stop the macro.
Thank you for taking the time.