monte Posted April 1, 2006 Posted April 1, 2006 Hello, I've finally found a solution to my problem, I actually had to completely remove my old version and only install the beta of autoit for it to work. However I have a new question. My ouput is displayed/spoken 4 times, I only want it displayed/spoken once. Anyone got any ideas? expandcollapse popup; AutoItCOM 3.1.1.x beta ; ; COM Test file ; ; Test usage of Events with SAPI ; ; NOTE: To be able to run this example, you must first ; download and install the Microsoft SAPI SDK 5.1 ; http://www.microsoft.com/speech/download/sdk51/ ; ; See also: http://www.microsoft.com/speech/techinfo/apioverview/ ; ; And..READ the documentation carefully! Speech recognition is very complex stuff ! #include "GUIConstants.au3" ; Create a simple GUI for our output GUICreate ( "Event Speech API Test", 640, 480 ) $GUIEdit=GUICtrlCreateEdit ( "Debug Log:" & @CRLF, 10, 10 , 600 , 400 ) GUISetState () ;Show GUI $RecoContext=ObjCreate("SAPI.SpSharedRecoContext") if @error then Msgbox(0,"","Error opening $RecoContext: " & @error) exit endif ; Initialize our Event Handler ; Note: The default outgoing event interface will be: _ISpeechRecoContextEvents $SinkObject=ObjEvent($RecoContext,"MYEvent_") if @error then GUICtrlSetData ( $GUIEdit, "ObjEvent error: " & @error & @CRLF , "append" ) else GUICtrlSetData ( $GUIEdit, "ObjEvent created Successfully!" & @CRLF , "append" ) ;Imported from: SAPI.H $SPRS_INACTIVE = 0 $SPRS_ACTIVE = 1 $SGDSActive=$SPRS_ACTIVE $SGDSInactive=$SPRS_INACTIVE $Grammar = $RecoContext.CreateGrammar(1) $Grammar.Dictationload ;$Grammar.DictationSetState($SGDSActive) ; start dictation GUICtrlSetData ( $GUIEdit, "You have 5 seconds of speaking time. So say something!", "append" ) dim $strText = "You have 5 seconds of speaking time. So say something!" dim $speak = ObjCreate("SAPI.SpVoice") $speak.Speak($strText) $Grammar.DictationSetState($SGDSActive) sleep(5000) ; Stop dictation $Grammar.DictationSetState($SGDSInactive) endif sleep (1000); Some events arrive late... GUICtrlSetData ( $GUIEdit, @CRLF & "End of dictation time." & @CRLF , "append" ) GUICtrlSetData ( $GUIEdit, "You may close this window now !" & @CRLF , "append" ) ; Waiting for user to close the window While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend GUIDelete () exit ;-------------------- ; SAPI Event functions Func MYEvent_StartStream($StreamNumber, $StreamPosition) ;StreamNumber As Long, ;StreamPosition As Variant GUICtrlSetData ( $GUIEdit, "StartStream(): StreamNumber is:" & $StreamNumber & @CRLF , "append" ) EndFunc Func MYEvent_Hypothesis($StreamNumber,$StreamPosition,$Result) ;StreamNumber As Long, ;StreamPosition As Variant, ;Result As ISpeechRecoResult GUICtrlSetData ( $GUIEdit, "Hypothesis(): Hypothized text is: " & $Result.PhraseInfo.GetText & @CRLF , "append" ) if $Result.PhraseInfo.GetText = "desktop" then dim $speak = ObjCreate("SAPI.SpVoice") $speak.Speak("You said.") $speak.Speak($Result.PhraseInfo.GetText) ;send("^d") endif EndFunc
monte Posted April 1, 2006 Author Posted April 1, 2006 up north gave me the answer! Thanks up north! Use Recognition instead of hypothesis. Func MYEvent_Recognition($StreamNumber,$StreamPosition,$RecognitionType,$Result) if $Result.PhraseInfo.GetText = "desktop" then dim $speak = ObjCreate("SAPI.SpVoice") $speak.Speak("You said.") $speak.Speak($Result.PhraseInfo.GetText) send("^d") endif EndFunc
ConsultingJoe Posted April 1, 2006 Posted April 1, 2006 does your Speech recognition lag on you and stop listening at all? Check out ConsultingJoe.com
seangriffin Posted May 21, 2010 Posted May 21, 2010 Here's a very very late reply I've just created a SAPIListBox UDF that will allow an AutoIT script to respond to a spoken words / phrases from a predefined list of items. Click on this link to access the UDF. Cheers, Sean. See my other UDFs: Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax See my other Tools: Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia
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