Sign in to follow this  
Followers 0

Simplified SAPI Speech Recogniton

60 posts in this topic

Posted

if anyone is interested, here is my AIML bot put together with this script, attached to this post.

But, unfortunately, it has the same problem. Just stops listening.

Share this post


Link to post
Share on other sites



Posted

if anyone is interested, here is my AIML bot put together with this script, attached to this post.

But, unfortunately, it has the same problem. Just stops listening.

I Don't See It :o

Share this post


Link to post
Share on other sites

Posted

OK THIS WORKS :o

The only problem with this is its 2 scripts one compiled and you need to pause a second to speak again

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

Share this post


Link to post
Share on other sites

Posted (edited)

I added more to the main script. You still need write.exe

I want to add a brain file function like the aiml bot

but use an ini file to make it easy

the commands are:

Slow down

Speed up

What time is it

What's the time

Give me the time

How are you (FUNNY) READ THAT SECTION

How're you

Exit

Hello

What is your name

What's your name

AutoItSetOption ( "TrayAutoPause", 0)
Local $o_speech = ObjCreate ("SAPI.SpVoice")
$voice = $o_speech.GetVoices().Item(0)
$o_speech.Voice = $voice
$speed = 2
Global $text
While 1
	gettext()
	TrayTip ( "Heard:", $text, 5, 1 )
	Select
	Case $text = "exit"
		$o_speech.Speak ('<rate speed="'& $speed &'">' & 'goodbye' & '</rate>', 8)
		Exit
	Case $text = "slow down"
		$speed = $speed - 3
		$o_speech.Speak ('<rate speed="'& $speed &'">' & 'I will talk slower for you' & '</rate>', 8)
	Case $text = "speed up"
		$speed = $speed + 3
		$o_speech.Speak ('<rate speed="'& $speed &'">' & 'I will talk faster for you' & '</rate>', 8)
	Case $text = "hello"
		TrayTip ( "Respond", "Hi There", 5, 1 )
		$o_speech.Speak ('<rate speed="'& $speed &'">' & "Hi There" & '</rate>', 8)
		Sleep(300)
	Case $text = "what is your name" or $text = "what's your name"
		TrayTip ( "Respond", "My Name is " & $voice.GetAttribute("Name"), 5, 1 )
		$o_speech.Speak ('<rate speed="'& $speed &'">' & "My Name is " & $voice.GetAttribute("Name") & '</rate>', 8)
		Sleep(300)
	Case $text = "change voice"
		$o_speech.Speak ('<rate speed="'& $speed &'">' & 'Anna, Mary, Mike, or Sam' & '</rate>', 8)
		gettext()
		changevoice()
	Case $text = "what time is it" or $text = "what's the time" or $text = "Give me the time"
		$o_speech.Speak ('<rate speed="'& $speed &'">' & "The time is now " & @HOUR & @MIN & '</rate>', 8)
	Case $text = "How are you" or $text = "How're you"
		$o_speech.Speak ('<rate speed="'& $speed &'">' & "Well I have to listen to this stupid human" & '</rate>', 8)
		gettext()
		if $text = "what" Then
		$o_speech.Speak ('<rate speed="'& $speed &'">' & "Yeah I said it, what are you going to do bitch" & '</rate>', 8)
		gettext()
		if $text = "kill you" Then	$o_speech.Speak ('<rate speed="'& $speed &'">' & "haha, fuck off" & '</rate>', 8)
		EndIf
	case else
		TrayTip ( $voice.GetAttribute("Name"), $text, 5, 1 )
		$o_speech.Speak ('<rate speed="'& $speed &'">' & $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

Func changevoice()
	TrayTip ( $voice.GetAttribute("Name"), "Change voice to Anna, Mary, Mike, or Sam", 5, 1 )
	Select
		case $text = "Anna"
			$voice = $o_speech.GetVoices().Item(0)
			$o_speech.Voice = $voice
			$o_speech.Speak ('<rate speed="'& $speed &'">' & 'Anna' & '</rate>', 8)
		case $text = "mary"
			$voice = $o_speech.GetVoices().Item(1)
			$o_speech.Voice = $voice
			$o_speech.Speak ('<rate speed="'& $speed &'">' & 'Mary' & '</rate>', 8)
		case $text = "mike"
			$voice = $o_speech.GetVoices().Item(2)
			$o_speech.Voice = $voice	
			$o_speech.Speak ('<rate speed="'& $speed &'">' & 'mike' & '</rate>', 8)
		case $text = "sam"
			$voice = $o_speech.GetVoices().Item(3)
			$o_speech.Voice = $voice	
			$o_speech.Speak ('<rate speed="'& $speed &'">' & 'sam' & '</rate>', 8)
		case Else
		$o_speech.Speak ('<rate speed="'& $speed &'">' & 'try again' & '</rate>', 8)
		gettext()
		changevoice()
	EndSelect
EndFunc
Edited by zerocool60544

Share this post


Link to post
Share on other sites

Posted (edited)

So what do you guys think of my solution.

FYI:I am Almost done with my Voice Command

FYI: I will be soon in about no more than a week.

I will Post the code and I will start a new topic on the program

It is about half way done

Posted Image

Posted Image

Edited by zerocool60544

Share this post


Link to post
Share on other sites

Posted

yeah, lets see if we can get this thing figured out...

what I find interesting is that it not only stops listening, but the process itself completely stops responding.

By the Way.....I got my AIML bot to work with this, but still same problem.

I have SDK 5.1 installed, so what code do I need beside your AIML script to get the bot to answer me back while I talk to it? could you put the code together with your script or do I have to edit anything?

Btw, good job guys!

Share this post


Link to post
Share on other sites

Posted

I have SDK 5.1 installed, so what code do I need beside your AIML script to get the bot to answer me back while I talk to it? could you put the code together with your script or do I have to edit anything?

Btw, good job guys!

I am waiting to get the updated code for the AIML bot and it wouldn't be much to add SR and TTS

If you want to mess with SR and TTS try this

just compile the second code to write.exe and read the first code for the commands

CODE
AutoItSetOption ( "TrayAutoPause", 0)

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

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

$o_speech.Voice = $voice

$speed = 2

Global $text

While 1

gettext()

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

Select

Case $text = "exit"

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

Exit

Case $text = "slow down"

$speed = $speed - 3

$o_speech.Speak ('<rate speed="'& $speed &'">' & 'I will talk slower for you' & '</rate>', 8)

Case $text = "speed up"

$speed = $speed + 3

$o_speech.Speak ('<rate speed="'& $speed &'">' & 'I will talk faster for you' & '</rate>', 8)

Case $text = "hello"

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

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

Sleep(300)

Case $text = "what is your name" or $text = "what's your name"

TrayTip ( "Respond", "My Name is " & $voice.GetAttribute("Name"), 5, 1 )

$o_speech.Speak ('<rate speed="'& $speed &'">' & "My Name is " & $voice.GetAttribute("Name") & '</rate>', 8)

Sleep(300)

Case $text = "change voice"

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

gettext()

changevoice()

Case $text = "what time is it" or $text = "what's the time" or $text = "Give me the time"

$o_speech.Speak ('<rate speed="'& $speed &'">' & "The time is now " & @HOUR & @MIN & '</rate>', 8)

Case $text = "How are you" or $text = "How're you"

$o_speech.Speak ('<rate speed="'& $speed &'">' & "Well I have to listen to this stupid human" & '</rate>', 8)

gettext()

if $text = "what" Then

$o_speech.Speak ('<rate speed="'& $speed &'">' & "Yeah I said it, what are you going to do bitch" & '</rate>', 8)

gettext()

if $text = "kill you" Then $o_speech.Speak ('<rate speed="'& $speed &'">' & "haha, fuck off" & '</rate>', 8)

EndIf

case $text = "memory load"

$mem = MemGetStats()

$memory = $mem[0] & " percent load"

TrayTip ( "memory load", $memory, 5, 1 )

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

case $text = "available memory"

$mem = MemGetStats()

$memory = $mem[2] & " kilobytes available"

TrayTip ( "available memory", $memory, 5, 1 )

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

case else

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

$o_speech.Speak ('<rate speed="'& $speed &'">' & $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

Func changevoice()

TrayTip ( $voice.GetAttribute("Name"), "Change voice to Anna, Mary, Mike, or Sam", 5, 1 )

Select

case $text = "Anna"

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

$o_speech.Voice = $voice

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

case $text = "mary"

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

$o_speech.Voice = $voice

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

case $text = "mike"

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

$o_speech.Voice = $voice

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

case $text = "sam"

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

$o_speech.Voice = $voice

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

case Else

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

gettext()

changevoice()

EndSelect

EndFunc

CODE
;COMPILE THIS TO 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

Share this post


Link to post
Share on other sites

Posted

I am waiting to get the updated code for the AIML bot and it wouldn't be much to add SR and TTS

If you want to mess with SR and TTS try this

just compile the second code to write.exe and read the first code for the commands

CODE
AutoItSetOption ( "TrayAutoPause", 0)

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

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

$o_speech.Voice = $voice

$speed = 2

Global $text

While 1

gettext()

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

Select

Case $text = "exit"

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

Exit

Case $text = "slow down"

$speed = $speed - 3

$o_speech.Speak ('<rate speed="'& $speed &'">' & 'I will talk slower for you' & '</rate>', 8)

Case $text = "speed up"

$speed = $speed + 3

$o_speech.Speak ('<rate speed="'& $speed &'">' & 'I will talk faster for you' & '</rate>', 8)

Case $text = "hello"

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

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

Sleep(300)

Case $text = "what is your name" or $text = "what's your name"

TrayTip ( "Respond", "My Name is " & $voice.GetAttribute("Name"), 5, 1 )

$o_speech.Speak ('<rate speed="'& $speed &'">' & "My Name is " & $voice.GetAttribute("Name") & '</rate>', 8)

Sleep(300)

Case $text = "change voice"

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

gettext()

changevoice()

Case $text = "what time is it" or $text = "what's the time" or $text = "Give me the time"

$o_speech.Speak ('<rate speed="'& $speed &'">' & "The time is now " & @HOUR & @MIN & '</rate>', 8)

Case $text = "How are you" or $text = "How're you"

$o_speech.Speak ('<rate speed="'& $speed &'">' & "Well I have to listen to this stupid human" & '</rate>', 8)

gettext()

if $text = "what" Then

$o_speech.Speak ('<rate speed="'& $speed &'">' & "Yeah I said it, what are you going to do bitch" & '</rate>', 8)

gettext()

if $text = "kill you" Then $o_speech.Speak ('<rate speed="'& $speed &'">' & "haha, fuck off" & '</rate>', 8)

EndIf

case $text = "memory load"

$mem = MemGetStats()

$memory = $mem[0] & " percent load"

TrayTip ( "memory load", $memory, 5, 1 )

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

case $text = "available memory"

$mem = MemGetStats()

$memory = $mem[2] & " kilobytes available"

TrayTip ( "available memory", $memory, 5, 1 )

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

case else

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

$o_speech.Speak ('<rate speed="'& $speed &'">' & $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

Func changevoice()

TrayTip ( $voice.GetAttribute("Name"), "Change voice to Anna, Mary, Mike, or Sam", 5, 1 )

Select

case $text = "Anna"

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

$o_speech.Voice = $voice

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

case $text = "mary"

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

$o_speech.Voice = $voice

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

case $text = "mike"

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

$o_speech.Voice = $voice

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

case $text = "sam"

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

$o_speech.Voice = $voice

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

case Else

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

gettext()

changevoice()

EndSelect

EndFunc

CODE
;COMPILE THIS TO 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

Ok thanks, where do I put the brain.aiml file? I have a few of those but with diffrent brain categories.

I could upload them to be used with this talk to bot engine if you want.

Share this post


Link to post
Share on other sites

Posted

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???

Try WinAlice Pro out... where are AIML files...

http://www.autoitscript.com/fileman/users/nfwu/WIN_ALICE_AIML.zip

Got it when i bought by "Virtual Humans" book last year when i was researching Artificial Intellegence

#)

Share this post


Link to post
Share on other sites

Posted

Try WinAlice Pro out... where are AIML files...

http://www.autoitscript.com/fileman/users/nfwu/WIN_ALICE_AIML.zip

Got it when i bought by "Virtual Humans" book last year when i was researching Artificial Intellegence

Hmm, those are the ones I was talking about, had a few more ones though :)

Share this post


Link to post
Share on other sites

Posted

zerocool, i forget which one of your scripts i had running, but i noticed, that when i spoke into the mic the mic volume would lower to 0

Share this post


Link to post
Share on other sites

Posted

:)

Hey..I might be way off the mark here. But I use the Opera Browser, which has a voice command button. You can set up your own voice commands that run your auto it scripts. For instance, i just say.."Baby, run time."... and Opera will run my time.au3 script, which talks back to me and tells me the time. I have many short scripts for my voice commands .. Opera recognizes my voice almost without flaw. Yep..Its a work around, but why reinvent the wheel?

Share this post


Link to post
Share on other sites

Posted

zerocool, i forget which one of your scripts i had running, but i noticed, that when i spoke into the mic the mic volume would lower to 0

Wow thats odd, I don't think i added volume control to any of my scripts. umm let me know which one, and remember to train your profile.

Share this post


Link to post
Share on other sites

Posted (edited)

zerocool, you might want to update your first post with the most recent program...make it noob-friendly :)

Wow thats odd, I don't think i added volume control to any of my scripts. umm let me know which one, and remember to train your profile.

he could have just found the problem with our first script and why it stopped listening :mellow:

and, there is a problem with your code on page 3. When my microphone is OFF, it thinks that I say as "Per"...

Edited by theguy0000

Share this post


Link to post
Share on other sites

Posted

now we just beed a way train it with a script :)

Share this post


Link to post
Share on other sites

Posted

now we just beed a way train it with a script :)

sounds like a good idea but if wouldn't using a link that would open the training profile be easier.

I don't know what the CLSID would be for that though

Share this post


Link to post
Share on other sites

Posted

Just out of curiosity... anyone want to try this...

http://www.voiceflux.net/download.vx

...and let me know how well it works?

Lar.

wow, I used to use this but forgot what it was called, thanks for the link maybe we could control it with autoit

Share this post


Link to post
Share on other sites

Posted

Did you guys manage to get it to work :?

Share this post


Link to post
Share on other sites

Posted (edited)

Did you guys manage to get it to work :?

I use this and it works in intervals. very responsive though

heres the post:

http://www.autoitscript.com/forum/index.ph...ndpost&p=158375

Edited by zerocool60544

Share this post


Link to post
Share on other sites

Posted

Here's a very very late reply :idea:

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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0