Surya Posted January 10, 2015 Posted January 10, 2015 i have gone through many forums related to speech recognition but i did'nt find what i needed My problem is that i want to add grammar to my speech recognition script ,when i say something my computer interprints it as something else like mom for dad so i want to make grammar for my speech recognition script .How can i import the grammar builder to autoit like it does in C# And also i have trained my computer several times from control panel speech recognition Thanx in advance:-) No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)
water Posted January 10, 2015 Posted January 10, 2015 Welcome to AutoIt and the forum! Could you please stick to a single thread? Posting a question in multiple forums is nothing we would like to see here. May I point you to the forum rules? A link can be found in the bottom right corner of each page. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Surya Posted January 11, 2015 Author Posted January 11, 2015 Sorry ;-) i did'nt see it No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)
Solution Surya Posted April 23, 2015 Author Solution Posted April 23, 2015 Finally found a Solution got lot of help from the forum '?do=embed' frameborder='0' data-embedContent>>I took the parts and made it to a UDF for speech recognition and other sapi stuffs expandcollapse popup#cs -------------------------------------------------------------------------- (Utter UDF) Utter UDF (SAPI.au3)needs SAPI installed (mostly pre-installed)on your computer to work properly.You can use and manage SAPI (Speech Recognition API).Please remember to shutdown the function before starting another insatnce of the engine. Current Functions:- _Utter_Speech_StartEngine() _Utter_Speech_CreateGrammar() _Utter_Speech_CreateTokens() _Utter_Speech_GrammarRecognize() _Utter_Speech_Pass() _Utter_Speech_ShutdownEngine() _Utter_Speech_CreateFreeGrammar() _Utter_Speech_FreegrammarPass() _Utter_Speech_ShutdownFreeGrammar() _Utter_Voice_Setvolume() _Utter_Voice_GetCurrentvoice() _Utter_Voice_Setvoice () _Utter_Voice_Getvoice () _Utter_Voice_StartEngine() _Utter_Voice_SetRate() _Utter_Voice_Transcribe() _Utter_Voice_Shutdown() _Utter_DebugOut() Internal Functions ---------------------------------------------------- _getpath($file) _Fetchextension($file) _checkgrammar($atb) _CheckObject($ark) MyErrFunc() RecoContext_Recognition($iStr, $vStr, $iRec, $iRe) SpRecEvent_Recognition($iStr, $vStr, $iRec, $iRe) Variables ------------------------------------------------------------- $UTTER_SPEECH_RECOGNIZE :- Contains currently recognised word _Utter_Speech_CreateFreeGrammar() function can also set this variable as well as the _Utter_Speech_GrammarRecognize() function this variable is changed when each time the user speaks a different word.Changes to empty string when you shutdown the function or start a new instance of the engine $UTTER_SPEECH_VAR :- The word to be recognized the recognition variable changes to empty string each time you create a new instance of the speech engine $UTTER_SPEECH_RECOSTATE :- This variable is set to 0 If the recognition verb matches the currently recognised verb $UTTER_SPEECH_ERROR :- Shows the @error instance of the _Utter_Speech_GrammarRecognize() function $UTTER_SPEECH_RESPONSE :- Sets variable to 0 if any thing is recognised and 1 if Not $UTTER_SPEECH_FUNC :- Function to call for after recognising a word and to send that word to a function as paramter.NOTE THE FUNCTION To BE CALLED MUST ACCEPT ONLY ONE PARAMETER. $UTTER_SPEECH_PASS :- Sets the value to 1 if pause parameter (1) is issued to _Utter_Speech_Pass() function and To 0 if resume parameter (1) is issued to _Utter_Speech_Pass() $UTTER_SPEECH_DEBUG :- Debug Variable change to true by calling _Utter_DebugOut(True) to print out output to console ----------Examples----------- (Transcription Audio) $hm = _Utter_Voice_StartEngine() _Utter_Voice_Transcribe($hm,@ScriptDir &"\intro.mp3","This is an example for transcription of audio",0,@ScriptDir &"\lame.exe") _Utter_Voice_Shutdown() SoundPlay (@ScriptDir &"\intro.mp3",1) (Grammar Example) Local $handl = _Utter_Speech_StartEngine() Local $txt1 = "Red is my favourite|Yellow is fine|blue colour reveals excitement|black is for speed|Green Colour" Local $txt2 = "Colors|Animals are good|Regions|Country" _Utter_Speech_CreateGrammar($handl,$txt1,$txt2) _Utter_Speech_CreateTokens($handl) _Utter_Speech_GrammarRecognize($handl,"Red",0) While 1 Sleep (50) ConsoleWrite (@CRLF &"Recognised=" &$UTTER_SPEECH_RECOGNIZE) WEnd _Utter_Speech_ShutdownEngine() -------------Examples-------------------- Author ..........: SuryaSaradhi.B Modified ........: 18/02/2015 #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include-once Global $UTTER_SPEECH_RECOGNIZE Global $UTTER_SPEECH_VAR Global $UTTER_SPEECH_ERROR Global $UTTER_SPEECH_RECOSTATE Global $UTTER_SPEECH_RESPONSE Global $UTTER_SPEECH_FUNC Global $UTTER_SPEECH_PASS = 0 Global $UTTER_SPEECH_DEBUG = False Global Const $SAFT48kHz16BitMono = 38 Global Const $SSFMCreateForWrite = 3 Global Const $SVSFPurgeBeforeSpeak = 2 Global Const $SVSFNLPSpeakPunc = 64 ;#FUNCTION# ;=============================================================================== ; Function Name: _Utter_Speech_StartEngine() ; Description: Creates a new instance of Speech Recognition Grammar Object. ; ; Parameter(s): Null ; Requirement(s): SAPI Installed on your computer ; Return Value(s): Returns an empty array of handles to Recognition objects ; this array handle is given to other functions in the ; group for adding grammar ; Author ........: Surya Saradhi.B ; Modified.......: 18/02/15 by Surya ;============================================================================================ Func _Utter_Speech_StartEngine() Global $h_Context = ObjCreate("SAPI.SpInProcRecoContext") $comer = @error Global $h_Recognizer = $h_Context.Recognizer ;Global $h_Grammar = $h_Context.CreateGrammar(1) $oRecoContext = $h_Context ;ObjCreate('SAPI.SpSharedRecoContext') Global $oVBS = ObjCreate("ScriptControl") $oVBS.Language = "VBScript" Global $oNothing = $oVBS.Eval("Nothing") $oRecoContext.CreateGrammar(0) $oGrammar = $oRecoContext.CreateGrammar() Global $h_Grammar = $oGrammar Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") _nullifyvariable() Global $array[8] $array[0] = $oRecoContext ;spinprorecocontext $array[1] = $h_Recognizer ;main recognizer $array[2] = 'null' ;Null handler $array[3] = $oVBS ;Script $array[4] = $oNothing ;Nothing $array[5] = $h_Grammar ;Grammar verbs $array[6] = "Error:" &$comer ;error notifications $array[7] = $oMyError Return $array EndFunc ;#FUNCTION# ;=============================================================================== ; Function Name: _Utter_Speech_CreateGrammar($ark,$gramr="",$trn="") ; Description: Adds Grammar to the Speech Recognition Dictionary for recognition ; the computer will recognize the word only making recognition more ; specific and accurate. ; ; Parameter(s): $ark : Array handle from _Utter_Speech_StartEngine() function ; $gramr :- (Main Phrase)Grammar to add to the input grammar can be a one ; dimensional array (two or more dimensions will return an error) ; word or string seperated by '|' delimeter.Without the paramter ; grammar added is an empty String. ; $trn :- (transitional Verb)Word to be said after the main verb.This word is recognised to ; be coming after the first verb ; Requirement(s): SAPI Installed on your computer For Accurate Recognition Train your computer before ; adding grammar and starting the recognition procedure. ; Return Value(s): Returns an empty array of handles to Dictionary Objects ; this array handle is given to other functions in the ; Author ........: Surya Saradhi.B ; Modified.......: 18/02/15 by Surya ;============================================================================================ Func _Utter_Speech_CreateGrammar($ark,$gramr="",$trn="") ;run a check function _CheckObject($ark) $ftr = _checkgrammar($gramr) $btr = _checkgrammar($trn) $oGrammar = $ark[5] $oTopRule = $oGrammar.Rules.Add('RUN', 1, 0) $oWordsRule = $oGrammar.Rules.Add('WORDS', BitOR(1, 32), 1) $oAfterCmdState = $oTopRule.AddState() For $i = 0 To UBound ($ftr)-1 $oTopRule.InitialState.AddWordTransition($oAfterCmdState, $ftr[$i]) $oAfterCmdState.AddRuleTransition($ark[4], $oWordsRule) Next For $i = 0 To UBound ($btr) -1 $oWordsRule.InitialState.AddWordTransition($ark[4], $btr[$i]) Next ;~ $oWordsRule.InitialState.AddWordTransition($oNothing, 'whatever') $oGrammar.Rules.Commit() $oGrammar.CmdSetRuleState('RUN', 1) Local $array[3] $array[0] = $oTopRule $array[1] = $oAfterCmdState $array[2] = $oWordsRule Return $array[2] EndFunc ;#FUNCTION# ;=============================================================================== ; Function Name: _Utter_Speech_CreateTokens($ark) ; Description: Creates tokens for redirecting the input of Microphone into the ; main recognition channel. ; ; Parameter(s): $ark :- Handle from the _Utter_Speech_StartEngine() function ; Requirement(s): SAPI Installed on your computer,Microphone installed on your computer ; Return Value(s): Returns an empty array of handles to token objects ; this array handle is given to other functions in the ; group for adding grammar ; Author ........: Surya Saradhi.B ; Modified.......: 18/02/15 by Surya ;============================================================================================ Func _Utter_Speech_CreateTokens($ark) $h_Recognizer = $ark[1] Global $h_Category = ObjCreate("SAPI.SpObjectTokenCategory") $h_Category.SetId("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\AudioInput\TokenEnums\MMAudioIn\") Global $h_Token = ObjCreate("SAPI.SpObjectToken") $h_Token.SetId("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\AudioInput\TokenEnums\MMAudioIn\") $h_Recognizer.AudioInput = $h_Token Local $array[2] $array[0] = $h_Category $array[1] = $h_Token Return $array[1] EndFunc ;#FUNCTION# ;=============================================================================== ; Function Name: _Utter_Speech_GrammarRecognize($ark,$grm="",$delay=1000,$func=False) ; Description: Starts the Speech recognition procedure.$UTTER_SPEECH_ERROR is set To ; the @error of the Object Handler and $UTTER_SPEECH_VAR is set to The ; recognising verb. ; ; Parameter(s): $ark :- Handle from the _Utter_Speech_StartEngine() function ; $grm :- Grammar to Recognise without this parameter the grammar ; to recognise is an empty String ; $delay :- The time to stop the script for the object handler to ; recognise phrases and word said by the user.you can issue ; 0 to this paramter if there is a While...WEnd loop after this ; function ; $func :- The function to be called after recognising the word.Defaulty ; it will not call any function but will only set a recognized ; verb $UTTER_SPEECH_RECOGNIZE variable.If a parameter or a function ; name is issued when the user speaks and when it is recognised the ; function will be called with the recognised verb as the parameter ; NOTE:THE FUNCTION MUST EXIST AND THE FUNCTION SHOULD ONLY ACCEPT ; ONE PARAMETER.Issuing this parameter will also set the function ; variable $UTTER_SPEECH_FUNC to the function name.Function name ; must be given in quotes ; Requirement(s): SAPI Installed on your computer,For Better acuuracy train your computers ; speech recognition module. ; Return Value(s): Returns empty variable containing handle to event handler module. ; Author ........: Surya Saradhi.B ; Modified.......: 18/02/15 by Surya ;============================================================================================ Func _Utter_Speech_GrammarRecognize($ark,$grm="",$delay=1000,$func="") $hk = ObjEvent($ark[0], 'RecoContext_') $UTTER_SPEECH_ERROR = @error $UTTER_SPEECH_VAR = $grm $UTTER_SPEECH_FUNC = "" If Not $func = "" Then $UTTER_SPEECH_FUNC = $func Sleep ($delay) Return $hk EndFunc ;#FUNCTION# ;=============================================================================== ; Function Name: _Utter_Speech_Pass($in = 0) ; Description: Pauses and resumes the recognition instance. ; ; Parameter(s): $in = Defaultly 0 if issued 1 Then recognition instance will stop ; giving output which will resume on giving 0 to the function ; as a parameter.This will also set the $UTTER_SPEECH_PASS variable. ; Return Value(s): Null ; Author ........: Surya Saradhi.B ; Modified.......: 18/02/15 by Surya ;============================================================================================ Func _Utter_Speech_Pass($in = 0) If $in = 0 Then $UTTER_SPEECH_PASS = 0 ElseIf $in = 1 Then $UTTER_SPEECH_PASS = 1 Else $UTTER_SPEECH_PASS = 1 EndIf EndFunc ;#FUNCTION# ;=============================================================================== ; Function Name: _Utter_Speech_ShutdownEngine() ; Description: Shuts down the handles created by _Utter_Speech_StartEngine() function ; and nullifies every object. ; ; Parameter(s): Null ; Requirement(s): Already called the _Utter_Speech_StartEngine() function ; Return Value(s): Null ; Author ........: Surya Saradhi.B ; Modified.......: 18/02/15 by Surya ;============================================================================================ Func _Utter_Speech_ShutdownEngine() _nullifyvariable() Global $hk = 0 Global $h_Context = 0 Global $h_Recognizer = 0 Global $oRecoContext = 0 Global $oVBS = 0 Global $oGrammar = 0 Global $oMyError = 0 Global $oTopRule = 0 Global $oWordsRule = 0 Global $oAfterCmdState = 0 Global $h_Category = 0 Global $h_Token = 0 Global $hk = 0 Global $oNothing = 0 EndFunc ;#FUNCTION# ;=============================================================================== ; Function Name: _Utter_Speech_CreateFreeGrammar($delay = 3000,$func = "") ; Description: Starts the Speech recognition Module with system dictionary loaded ; no grammar has to be specified by the user.Delay time can be set to ; 0 if called before a While...WEnd loop.All variables are changed by ; the function.Accuracy is very low for this type of recognition ; ; Parameter(s): $delay :- The delay time for the script to wait for the verb ; recognition you can issue 0 if there is a While...WEnd ; loop after calling this Function. ; $func :- The function to be called after recognising the word.Defaulty ; it will not call any function but will only set a recognized ; verb $UTTER_SPEECH_RECOGNIZE variable.If a parameter or a function ; name is issued when the user speaks and when it is recognised the ; function will be called with the recognised verb as the parameter ; NOTE:THE FUNCTION MUST EXIST AND THE FUNCTION SHOULD ONLY ACCEPT ; ONE PARAMETER.Issuing this parameter will also set the function ; variable $UTTER_SPEECH_FUNC to the function name.Function name ; must be given in quotes ; Requirement(s): SAPI installed in your computer it is also highly recommended to train ; your computer before starting the procedure. ; Return Value(s): @error of The main Event Handler. ; Author ........: Surya Saradhi.B ; Modified.......: 18/02/15 by Surya ;============================================================================================ Func _Utter_Speech_CreateFreeGrammar($delay = 3000,$func = "") _nullifyvariable() If Not $func = "" Then $UTTER_SPEECH_FUNC = $func Global $h_Contextm = ObjCreate("SAPI.SpInProcRecoContext") Global $h_Recognizerm = $h_Contextm.Recognizer Global $h_Grammarm = $h_Contextm.CreateGrammar(1) $h_Grammarm.Dictationload $h_Grammarm.DictationSetState(1) ;Create a token for the default audio input device and set it Global $h_Categorym = ObjCreate("SAPI.SpObjectTokenCategory") $h_Categorym.SetId("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\AudioInput\TokenEnums\MMAudioIn\") Global $h_Tokenm = ObjCreate("SAPI.SpObjectToken") $h_Tokenm.SetId("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\AudioInput\TokenEnums\MMAudioIn\") $h_Recognizerm.AudioInput = $h_Tokenm Global $i_ObjInitializedm = 0 Global $h_ObjectEventsm = ObjEvent($h_Contextm, "SpRecEvent_") If @error Then $i_ObjInitializedm = 0 Else $i_ObjInitializedm = 1 EndIf $UTTER_SPEECH_ERROR = $i_ObjInitializedm Sleep ($delay) Return $i_ObjInitializedm EndFunc ;#FUNCTION# ;=============================================================================== ; Function Name: _Utter_Speech_FreegrammarPass($in = 0) ; Description: Pauses and resumes the recognition instance. ; ; Parameter(s): $in = Defaultly 0 if issued 1 Then recognition instance will stop ; giving output which will resume on giving 0 to the function ; as a parameter.This will also set the $UTTER_SPEECH_PASS variable. ; Return Value(s): Null ; Author ........: Surya Saradhi.B ; Modified.......: 18/02/15 by Surya ;============================================================================================ Func _Utter_Speech_FreegrammarPass($in = 0) If $in = 0 Then $UTTER_SPEECH_PASS = 0 ElseIf $in = 1 Then $UTTER_SPEECH_PASS = 1 Else $UTTER_SPEECH_PASS = 1 EndIf EndFunc ;#FUNCTION# ;=============================================================================== ; Function Name: _Utter_Speech_ShutdownFreeGrammar() ; Description: Nullifies all variables and shutsdown the objects created by ; the _Utter_Speech_CreateFreeGrammar() function. ; ; Parameter(s): Null ; Requirement(s): Already Called _Utter_Speech_CreateFreeGrammar() function ; Return Value(s): Null ; Author ........: Surya Saradhi.B ; Modified.......: 18/02/15 by Surya ;============================================================================================ Func _Utter_Speech_ShutdownFreeGrammar() _nullifyvariable() Global $h_Contextm = 0 Global $h_Recognizerm = 0 Global $h_Grammarm = 0 Global $h_Categorym = 0 Global $h_Tokenm = 0 Global $i_ObjInitializedm = 0 Global $h_ObjectEventsm = 0 EndFunc ;#FUNCTION# ;=============================================================================== ; Function Name: _Utter_Voice_Shutdown() ; Description: Shutsdown Objects created by the _Utter_Voice_StartEngine() function ; ; Parameter(s): Null ; Requirement(s): Already Called _Utter_Voice_StartEngine() function ; Return Value(s): Null ; Author ........: Surya Saradhi.B ; Modified.......: 18/02/15 by Surya ;============================================================================================ Func _Utter_Voice_Shutdown() Global $lop = 0 EndFunc ;#FUNCTION# ;=============================================================================== ; Function Name: _Utter_Voice_Setvolume(ByRef $ark,$val) ; Description: Sets Volume of _Utter_Voice_StartEngine() function TTS Engine ; ; Parameter(s): $ark :- Handle returned from _Utter_Voice_StartEngine() ; $val :- Volume to be set (0-100) ; Requirement(s): Already Called _Utter_Voice_StartEngine() function,SAPI installed ; Return Value(s): Null ; Author ........: Surya Saradhi.B ; Modified.......: 18/02/15 by Surya ;============================================================================================ Func _Utter_Voice_Setvolume(ByRef $ark,$val) $oSpeech = $ark $oSpeech.Volume = $val EndFunc ;#FUNCTION# ;=============================================================================== ; Function Name: _Utter_Voice_GetCurrentvoice(ByRef $ark) ; Description: Gets the current voice Activated in TTS (Text to Speech) Engine ; ; Parameter(s): $ark :- Handle returned from _Utter_Voice_StartEngine() ; Requirement(s): Already Called _Utter_Voice_StartEngine() function,SAPI installed ; Return Value(s): Current Active Voice Profile ; Author ........: Surya Saradhi.B ; Modified.......: 18/02/15 by Surya ;============================================================================================ Func _Utter_Voice_GetCurrentvoice(ByRef $ark) $hl = $ark.getvoices.item (0) $ml = $hl.GetDescription() Return $ml EndFunc ;#FUNCTION# ;=============================================================================== ; Function Name: _Utter_Voice_Setvoice (ByRef $Object, $sVoiceName) ; Description: Sets an available voice from library as active current TTS voice ; ; Parameter(s): $ark :- Handle returned from _Utter_Voice_StartEngine() ; $sVoiceName :- Voice Profile Name returned from _Utter_Voice_Getvoice() ; function ; Requirement(s): Already Called _Utter_Voice_StartEngine() function,SAPI installed ; Return Value(s): Null ; Author ........: Surya Saradhi.B ; Modified.......: 18/02/15 by Surya ;============================================================================================ Func _Utter_Voice_Setvoice (ByRef $Object, $sVoiceName) Local $VoiceNames, $VoiceGroup = $Object.GetVoices For $VoiceNames In $VoiceGroup If $VoiceNames.GetDescription() = $sVoiceName Then $Object.Voice = $VoiceNames Return EndIf Next EndFunc ;#FUNCTION# ;=============================================================================== ; Function Name: _Utter_Voice_Getvoice(ByRef $ark,$bReturn = True) ; Description: Gets available voice profile names installed on your Computer ; ; Parameter(s): $ark :- Handle returned from _Utter_Voice_StartEngine() ; $bReturn :- Boolean value paramater if True is issued returns an ; array containing the available installed profile names ; If False is issued returns a String consisting of profile ; names seperated by the '|' character ; Requirement(s): Already Called _Utter_Voice_StartEngine() function,SAPI installed ; Return Value(s): Returns an array or String (seperated by '|' delimeter) containing ; available profile names installed in your computer ; Author ........: Surya Saradhi.B ; Modified.......: 18/02/15 by Surya ;============================================================================================ Func _Utter_Voice_Getvoice (ByRef $ark,$bReturn = True) $oSpeech = $ark Local $sVoices, $VoiceGroup = $oSpeech.GetVoices For $Voices In $VoiceGroup $sVoices &= $Voices.GetDescription() & '|' Next If $bReturn Then Return StringSplit(StringTrimRight($sVoices, 1), '|', 2) Return StringTrimRight($sVoices, 1) EndFunc ;#FUNCTION# ;=============================================================================== ; Function Name: _Utter_Voice_StartEngine() ; Description: Starts an instance of TTS Engine Object ; ; Parameter(s): Null ; Requirement(s): SAPI installed ; Return Value(s): Returns a handle to TTS Engine Object. ; Author ........: Surya Saradhi.B ; Modified.......: 18/02/15 by Surya ;============================================================================================ Func _Utter_Voice_StartEngine() $lop = ObjCreate ("SAPI.spVoice") Return $lop EndFunc ;#FUNCTION# ;=============================================================================== ; Function Name: _Utter_Voice_SetRate(ByRef $ark,$val) ; Description: Sets the rate of voice OR how fast the voice speaks. ; ; Parameter(s): $ark :- Handle returned by the _Utter_Voice_StartEngine() function ; $val :- Rate or Speed of the voice (-10 to 10) ; Requirement(s): Already called _Utter_Voice_StartEngine(),SAPI installed ; Return Value(s): Null ; Author ........: Surya Saradhi.B ; Modified.......: 18/02/15 by Surya ;============================================================================================ Func _Utter_Voice_SetRate(ByRef $ark,$val) $oSpeech = $ark $oSpeech.Rate = $val EndFunc ;#FUNCTION# ;=============================================================================== ; Function Name: _Utter_Voice_Transcribe(ByRef $ark,$file,$txt,$comp = 1,$lame="") ; Description: Transcribes speech to audio OR Converts text to Speech which is ; being saved to an mp3 or wav fileNo other formats than .wav and .mp3 ; are allowed.System can save the audio as wav only if you want the file ; to be an mp3 then you will have to issue the lame parameter. ; ; Parameter(s): $ark :- Handle returned by the _Utter_Voice_StartEngine() function ; $file :- The path with the name of the file to be saved to if to Be ; saved as an mp3 then specify the file extension as .mp3 ; otherwise as .wav ; $txt :- The text to convert to audio ; $comp :- Without issuing the parameter (value = 1) the file will be ; saved as .wav issue the parameter with 0 value to save the ; audio as .mp3 also specify the lame location otherwise this ; will return an error. ; $lame :- Location of the Lame.exe file for converting the .wav to .mp3 ; Requirement(s): Already called _Utter_Voice_StartEngine(),SAPI installed ; Return Value(s): Null ; Author ........: Surya Saradhi.B ; Modified.......: 18/02/15 by Surya ;============================================================================================ Func _Utter_Voice_Transcribe(ByRef $ark,$file,$txt,$comp = 1,$lame="") $ext = _Fetchextension($file) If $ext=0 Or $ext = 2 Then $oStream = ObjCreate ( "SAPI.SpFileStream" ) $ark.AllowAudioOutputFormatChangesOnNextSet = True $oStream.Format.Type = $SAFT48kHz16BitMono If $ext = 2 Then $mh = ".wav" Else $mh = "" EndIf $oStream.Open ( $file &$mh, $SSFMCreateForWrite, True ) $ark.AudioOutputStream = $oStream $ark.Speak ( $txt, $SVSFPurgeBeforeSpeak + $SVSFNLPSpeakPunc ) $oStream.Close ( ) $ark.AudioOutput = $ark.GetAudioOutputs ( '' ).Item ( 0 ) If $ext &$comp = 20 Then If FileExists ($lame ) Then RunWait ( '"' &$lame &'"' &' -q0 "' & $file &'.wav" "' &_getpath($file) & '.mp3"', '', @SW_HIDE) FileDelete ($file &".wav") Else $txt = "Utter Cant Perform conversion operation because lame directory you enterd is not valid") ConsoleWrite ($txt) EndIf EndIf Else $msg = "Utter cant convert text to other formats than .wav lame is required to convert to .mp3" ConsoleWrite (@CRLF &$msg) EndIf EndFunc ;#FUNCTION# ;=============================================================================== ; Function Name: _Utter_DebugOut($ffl=False) ; Description: turns on Printing recognised words to the console stream for debugging. ; ; Parameter(s): $ffl :- Defaultly False if set to True will print out recognised ; words to the console strem. ; Requirement(s): Null ; Return Value(s): Null ; Author ........: Surya Saradhi.B ; Modified.......: 18/02/15 by Surya ;============================================================================================ Func _Utter_DebugOut($ffl=False) $UTTER_SPEECH_DEBUG = $ffl EndFunc ;#INTERNAL FUNCTION# ;=============================================================================== ; Below Functions are called by the functions which are in the group and are not to be called by the ; User.These are support functions which provide help with the main function. ;============================================================================================ #Region :Internal Functions Start Func _nullifyvariable() Global $UTTER_SPEECH_RECOGNIZE = "" Global $UTTER_SPEECH_VAR = "" Global $UTTER_SPEECH_ERROR = "" Global $UTTER_SPEECH_RECOSTATE = "" Global $UTTER_SPEECH_RESPONSE = "" Global $UTTER_SPEECH_FUNC = "" Global $UTTER_SPEECH_PASS = "" EndFunc Func _getpath($file) Local $spk = StringRegExp($file, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", 1) Return $spk[1] &$spk[2] &$spk[3] EndFunc Func _Fetchextension($file) Local $aArray = StringRegExp($file, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", 1) If $aArray[4] = ".wav" Then Return 0 ElseIf $aArray[4] = ".mp3" Then Return 2 Else Return 1 EndIf EndFunc Func _checkgrammar($atb) If IsArray($atb) Then Return $atb ElseIf StringInStr ($atb,"|") Then $split = StringSplit ($atb,"|",$STR_NOCOUNT) Return $split Else Local $ark[1] $ark[0] = $atb Return $ark EndIf EndFunc Func _CheckObject($ark) ObjName ($ark[0]) If @error Then MsgBox ("","Utter","Handler not valid") EndFunc Func MyErrFunc() Msgbox(0,"Utter COM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & hex($oMyError.number,8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) Local $err = $oMyError.number If $err = 0 Then $err = -1 $g_eventerror = $err ; to check for after this function returns Endfunc Func SpRecEvent_SoundStart($StreamNumber, $StreamPosition) $UTTER_SPEECH_RESPONSE = 0 EndFunc Func SpRecEvent_SoundEnd($StreamNumber, $StreamPosition) $UTTER_SPEECH_RESPONSE = 1 EndFunc Func RecoContext_SoundStart($StreamNumber, $StreamPosition) $UTTER_SPEECH_RESPONSE = 0 EndFunc Func RecoContext_SoundEnd($StreamNumber, $StreamPosition) $UTTER_SPEECH_RESPONSE = 1 EndFunc Func RecoContext_Recognition($iStreamNumber, $vStreamPosition, $iRecognitionType, $iResult) $said = $iResult.PhraseInfo.GetText() If $UTTER_SPEECH_PASS = 0 Then If $UTTER_SPEECH_DEBUG Then ConsoleWrite( @CRLF &"--UTTER NOTIFIED:" &$said) If Not $UTTER_SPEECH_FUNC = "" Then Call ($UTTER_SPEECH_FUNC,$said) EndIf If $UTTER_SPEECH_VAR = $UTTER_SPEECH_RECOGNIZE Then $UTTER_SPEECH_RECOSTATE = 0 Else $UTTER_SPEECH_RECOSTATE = 1 EndIf $UTTER_SPEECH_RECOGNIZE = $said Else If $UTTER_SPEECH_DEBUG Then ConsoleWrite( @CRLF &"--UTTER PAUSED RECOGNITION STATE") EndIf EndFunc Func SpRecEvent_Recognition($StreamNumber, $StreamPosition, $RecognitionType, $Result) $said = $iResult.PhraseInfo.GetText() If $UTTER_SPEECH_PASS = 0 Then If Not $UTTER_SPEECH_FUNC = "" Then Call ($UTTER_SPEECH_FUNC,$said) EndIf If $UTTER_SPEECH_DEBUG Then ConsoleWrite( @CRLF &"--UTTER NOTIFIED:" &$said) $UTTER_SPEECH_VAR = $said $UTTER_SPEECH_RECOGNIZE = $said Else If $UTTER_SPEECH_DEBUG Then ConsoleWrite( @CRLF &"--UTTER PAUSED RECOGNITION STATE") EndIf EndFunc #EndRegion :Internal Functions End If any bugs please report No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)
Surya Posted August 22, 2015 Author Posted August 22, 2015 Utter updated here at:https://www.autoitscript.com/forum/topic/175719-utter-utilizing-more-of-sapi/ No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)
Moderators Melba23 Posted August 22, 2015 Moderators Posted August 22, 2015 Surya,That is enough self=advertisement for today - please do not necro any more threads to tell us about your updated UDF.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Surya Posted August 23, 2015 Author Posted August 23, 2015 Sir I think you have misunderstood all I was trying to do was to help someone out who has the same problem with speech recognition if somebody knows about the UDF then can they use it I am terribly sorry sir if I have caused any trouble No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)
Surya Posted August 23, 2015 Author Posted August 23, 2015 And sir advertising was never my intention No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)
Moderators Melba23 Posted August 23, 2015 Moderators Posted August 23, 2015 Surya,No problem - but please remember that, unlike some "sochul meedja" sites, your reputation here is based on the content and not on the number of your posts.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Surya Posted August 24, 2015 Author Posted August 24, 2015 I understand sir No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)
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