Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Voice triger
#2
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
Code:
Copy      Help
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


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)