Jump to content

Simplified SAPI Speech Recogniton


ConsultingJoe
 Share

Recommended Posts

OK, I took one I found in the support forum and shrunk it way down and made it easier.

If you get a error about how it can't create object then goto control panel setup microphone and train it really quick, If you don't have Speech Recognition download it from microsofts site:

http://www.microsoft.com/speech/download/sdk51/

This should be the exact file:

http://download.microsoft.com/download/spe...speechsdk51.exe (68MB)

Compiled write.exe

Its 2 scripts one compiled and you need to pause a second to speak again

The first script will be compiled to write.exe and the second script can be anything.

make sure you have to write.exe in the same dir

give it a try

current commands:

Change Voice

Hello

Exit

write.exe

#NoTrayIcon
$RecoContext=ObjCreate("SAPI.SpSharedRecoContext")
$SinkObject=ObjEvent($RecoContext,"MYEvent_")
  $Grammar = $RecoContext.CreateGrammar(1)
  $Grammar.Dictationload
  $Grammar.DictationSetState(1)
  sleep(5000) 
  $Grammar.DictationSetState(0)

Func MYEvent_Recognition($StreamNumber,$StreamPosition,$RecognitionType,$Result)
    $file = FileOpen ( "heard.txt", 2)
    FileWrite ( $file, $Result.PhraseInfo.GetText )
    FileClose ( $file )
    exit
EndFunc

main script

CODE
AutoItSetOption ( "TrayAutoPause", 0)

Local $o_speech = ObjCreate ("SAPI.SpVoice")

$voice = $o_speech.GetVoices().Item(1)

$o_speech.Voice = $voice

Global $text

While 1

gettext()

TrayTip ( "Heard:", $text, 5, 1 )

Select

Case $text = "exit"

$o_speech.Speak ('<rate speed="4">' & 'goodbye' & '</rate>', 8)

Exit

Case $text = "hello"

TrayTip ( "Respond", "Hi There", 5, 1 )

$o_speech.Speak ('<rate speed="4">' & $text & '</rate>', 8)

Sleep(300)

Case $text = "change voice"

$o_speech.Speak ('<rate speed="4">' & 'Mary, Mike, or Sam' & '</rate>', 8)

gettext()

Select

case $text = "mary"

$voice = $o_speech.GetVoices().Item(1)

$o_speech.Voice = $voice

$o_speech.Speak ('<rate speed="4">' & 'Mary' & '</rate>', 8)

case $text = "mike"

$voice = $o_speech.GetVoices().Item(2)

$o_speech.Voice = $voice

$o_speech.Speak ('<rate speed="4">' & 'mike' & '</rate>', 8)

case $text = "sam"

$voice = $o_speech.GetVoices().Item(3)

$o_speech.Voice = $voice

$o_speech.Speak ('<rate speed="4">' & 'sam' & '</rate>', 8)

case Else

$o_speech.Speak ('<rate speed="4">' & 'The Voice Was Not changed' & '</rate>', 8)

EndSelect

case else

TrayTip ( $voice.GetAttribute("Name"), $text, 5, 1 )

$o_speech.Speak ('<rate speed="4">' & $text & '</rate>', 8)

EndSelect

WEnd

Func OnAutoItExit ( )

FileDelete ( @ScriptDir & "\heard.txt" )

EndFunc

Func gettext()

RunWait(@ScriptDir & "\write.exe")

$file = FileOpen ( "heard.txt", 0 )

$text = FileRead ($file )

FileClose ( $file )

$file = FileOpen ( "heard.txt", 2 )

FileWrite ($file, "")

FileClose ( $file )

EndFunc

And here's the original code:

CODE
Global $recog = "PLEASE SPEAK NOW" ;SET GLOBAL

$RecoContext=ObjCreate("SAPI.SpSharedRecoContext")

if @error then

Msgbox(0,"","Error opening $RecoContext: " & @error);ERROR CHECK

exit

endif

$SinkObject=ObjEvent($RecoContext,"MYEvent_")

$SPRS_INACTIVE = 0

$SPRS_ACTIVE = 1

$SGDSActive=$SPRS_ACTIVE

$SGDSInactive=$SPRS_INACTIVE

$Grammar = $RecoContext.CreateGrammar(1)

$Grammar.Dictationload

$Grammar.DictationSetState($SGDSActive);LISTEN

while 1

Sleep(100)

if $recog <> "" Then

Select

Case $recog = "exit"

exit;HEAR EXIT

Case $recog = "hello"

MsgBox(0,"hi","HI",1);HEAR HELLO

Case $recog = "I love you"

MsgBox(0,"","I love you too",1)

Case $recog = "test"

MsgBox(0,"","What are you testing LOSER",1)

EndSelect

;_talkOBJ($recog, 3); TALKS AFTER IT HEARS SOMETHING, The mic hears the pc and affects the recognition

_talkOBJ($recog, 3, "dont talk"); JUST POP-UP

Endif

$recog = "";SET TO NULL FOR REPEATED COMMANDS

WEnd

;$Grammar.DictationSetState($SGDSInactive);STOP LITENING

Func MYEvent_Recognition($StreamNumber,$StreamPosition,$RecognitionType,$Result)

$recog = $Result.PhraseInfo.GetText;SET $recog VAR

EndFunc

Func _TalkOBJ($s_text, $s_voice = 3, $s_dont = "")

Local $quite = 0

Local $o_speech = ObjCreate ("SAPI.SpVoice")

Select

Case $s_voice == 1

$o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Mary", "Language=409").Item(0)

TrayTip("Female Reader",$s_text,1)

Case $s_voice == 2

$o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Mike", "Language=409").Item(0)

TrayTip("Male Reader",$s_text,1)

Case $s_voice == 3

$o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Sam", "Language=409").Item(0)

TrayTip("OldMan Reader",$s_text,1)

EndSelect

if $s_dont <> "dont talk" then

$o_speech.Speak ($s_text)

$o_speech = ""

ENDif

Sleep(1000)

TrayTip("","",1)

EndFunc ;==>_TalkOBJ

Edited by zerocool60544

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

  • Replies 59
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Thats so ODD no one is interested in SR

WHY IT IS SO GREAT

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

I would like to create an AI-SR-TTS system for my computer without spending any money. I could combine this script with a self-created MS Agent script, and also the "AIML Bot!" script by theguy0000, with slight additions (variables and learning). Hey, I could entertain my friends with this!

[size="4"]YOU SHALL NOT PARSE!![/size]
Link to comment
Share on other sites

I would like to create an AI-SR-TTS system for my computer without spending any money. I could combine this script with a self-created MS Agent script, and also the "AIML Bot!" script by theguy0000, with slight additions (variables and learning). Hey, I could entertain my friends with this!

That sounds cool, Could you please help us figure out why it stops listening after a while

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

hey, now that would be a great idea to put SR into my "AIML Bot"...and I could make it talk too.

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

hey, now that would be a great idea to put SR into my "AIML Bot"...and I could make it talk too.

hey, by the way, i was just checking out yout bot script very nice, do you know if there is a very big full brain file i can play with???

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

well, there's always ALICE, but it is very, very, very big, and it takes a really long time to load...but I can get it for you if you want.

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

well, there's always ALICE, but it is very, very, very big, and it takes a really long time to load...but I can get it for you if you want.

Yeah that would be cool thanks, and do you know about sr. because i have change and messed with everything to get it to continue listening. would you know what to do

heres and example

You can say Sam, Mary, Mike, and Exit

CODE
$RecoContext=ObjCreate("SAPI.SpSharedRecoContext")

if @error then

Msgbox(0,"","Error opening $RecoContext: " & @error)

exit

endif

$SinkObject=ObjEvent($RecoContext,"MYEvent_")

$SPRS_INACTIVE = 0

$SPRS_ACTIVE = 1

$SGDSActive=$SPRS_ACTIVE

$SGDSInactive=$SPRS_INACTIVE

$Grammar = $RecoContext.CreateGrammar(1)

$Grammar.Dictationload

$Grammar.DictationSetState($SGDSActive)

Global $recog, $s_voice = 3

While 1

Sleep(1000)

WEnd

Func MYEvent_Recognition($StreamNumber,$StreamPosition,$RecognitionType,$Result)

$recog = $Result.PhraseInfo.GetText

Select

Case $Result.PhraseInfo.GetText = "exit"

exit

Case $Result.PhraseInfo.GetText = "Mary"

$s_voice = 1

_TalkOBJ("Hello, Mary here", $s_voice)

Case $Result.PhraseInfo.GetText = "Mike"

$s_voice = 2

_TalkOBJ("Hello, Mike here", $s_voice)

Case $Result.PhraseInfo.GetText = "Sam"

$s_voice = 3

_TalkOBJ("Hello, Sam here", $s_voice)

Case else

_TalkOBJ($Result.PhraseInfo.GetText, $s_voice)

EndSelect

EndFunc

Func _TalkOBJ($s_text, $s_voice = 3)

$Grammar.DictationSetState($SGDSInactive)

Local $quite = 0

Local $o_speech = ObjCreate ("SAPI.SpVoice")

Select

Case $s_voice == 0

Return

Case $s_voice == 1

$o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Mary", "Language=409").Item(0)

TrayTip("MARY",$s_text,1)

Case $s_voice == 2

$o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Mike", "Language=409").Item(0)

TrayTip("MIKE",$s_text,1)

Case $s_voice == 3

$o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Sam", "Language=409").Item(0)

TrayTip("SAM",$s_text,1)

EndSelect

$o_speech.Speak ($s_text)

$o_speech = ""

Sleep(1000)

TrayTip("","",1)

$Grammar.DictationSetState($SGDSActive)

EndFunc ;==>_TalkOBJ

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

these SR scripts just aren't working for me...it never recognizes what I say.

I have SR installed from the link you gave me, and I trained it.

Microsoft's Dictation Pad program works great, but these scripts just arent doing anything.

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

these SR scripts just aren't working for me...it never recognizes what I say.

I have SR installed from the link you gave me, and I trained it.

Microsoft's Dictation Pad program works great, but these scripts just arent doing anything.

umm, if you have a mic in you task bar make sure it is on that gave me problems

you didn't get an error though right???

and make sure you have 5.1sdk, the link is at the top

Edited by zerocool60544

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

hmm, no mic in the task bar...

And you have 5.1 sdk

try this script

CODE
; 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)

; Dictation starts here...you may speak now !

GUICtrlSetData ( $GUIEdit, "You have 10 seconds speaking time now...open your microphone and say something !" & @CRLF , "append" )

sleep(10000)

; Stop dictation

$Grammar.DictationSetState($SGDSInactive)

endif

sleep (5000); 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" )

EndFunc

Func MYEvent_Interference($StreamNumber,$StreamPosition,$Interference)

; StreamNumber As Long,

; StreamPosition As Variant,

; Interference As SpeechInterference

GUICtrlSetData ( $GUIEdit, "Interference(): StreamNumber is:" & $StreamNumber & @CRLF , "append" )

EndFunc

Func MYEvent_Recognition($StreamNumber,$StreamPosition,$RecognitionType,$Result)

GUICtrlSetData ( $GUIEdit, "Recognition(): Recognized text is: " & $Result.PhraseInfo.GetText & @CRLF , "append" )

_TalkOBJ($Result.PhraseInfo.GetText, 3)

sleep(2000)

EndFunc

Func MYEvent_SoundEnd($StreamNumber,$StreamPosition)

EndFunc

Func MYEvent_EndStream($StreamNumber,$StreamPosition,$StreamReleased)

EndFunc

Func MYEvent_SoundStart($StreamNumber,$StreamPosition)

EndFunc

Func MYEvent_PhraseStart($StreamNumber,$StreamPosition)

EndFunc

Func _TalkOBJ($s_text, $s_voice = 3)

Local $quite = 0

Local $o_speech = ObjCreate ("SAPI.SpVoice")

Select

Case $s_voice == 0

Return

Case $s_voice == 1

$o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Mary", "Language=409").Item(0)

TrayTip("Female Reader",$s_text,1)

Case $s_voice == 2

$o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Mike", "Language=409").Item(0)

TrayTip("Male Reader",$s_text,1)

Case $s_voice == 3

$o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Sam", "Language=409").Item(0)

TrayTip("OldMan Reader",$s_text,1)

EndSelect

$o_speech.Speak ($s_text)

$o_speech = ""

Sleep(1000)

TrayTip("","",1)

EndFunc ;==>_TalkOBJ

Edited by zerocool60544

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

Debug Log:
ObjEvent created Successfully!
You have 10 seconds speaking time now...open your microphone and say something !
StartStream(): StreamNumber is:1

End of dictation time.
You may close this window now !

It didn't recognize anything...

but, like I said, still no mic in the taskbar

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

Debug Log:
ObjEvent created Successfully!
You have 10 seconds speaking time now...open your microphone and say something !
StartStream(): StreamNumber is:1

End of dictation time.
You may close this window now !

It didn't recognize anything...

but, like I said, still no mic in the taskbar

wow I don't know then, you don't have to have a mic in the task but it happens. um what I would say is make sure the SR engine is set to 5.1sdk and shutoff any other SR programs and tell me what that script said when you ran it

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

hmm, it turned out to be a music program I had running...which is really wierd considering that program doesn't even use SR...

anyway, the test script you just gave me works, but none of the other scripts do...

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

hmm, it turned out to be a music program I had running...which is really wierd considering that program doesn't even use SR...

anyway, the test script you just gave me works, but none of the other scripts do...

I don't know man, sorry

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

I got it to work...I guess I wasn't talking clearly enough or something.

but I have a queestion...

ase $recog = "exit"
exit;HEAR EXIT
Case $recog = "hello"
MsgBox(0,"hi","HI",1);HEAR HELLO
Case $recog = "I love you"
MsgBox(0,"","I love you too",1)
Case $recog = "test"
MsgBox(0,"","What are you testing LOSER",1)

where on earth is $recog defined? I see [[Global $recog = "PLEASE SPEAK NOW" ;SET GLOBAL]] but nothing else...how does it know what the user says?

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

Func MYEvent_Recognition($StreamNumber,$StreamPosition,$RecognitionType,$Result)
    $recog = $Result.PhraseInfo.GetText

Right there, when the script recognizes a word or phrase the MYEvent_Recognition func is call which then sets the $recog var

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...