Zohar

[Solved] The Simplest Example for Speech Recognition

8 posts in this topic

#1 ·  Posted (edited)

Hi

I am trying to start with the simplest code for speech recognition,

so later I can start improving it and making it more useful.

I am trying this code:

$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)
MsgBox(0,"",$Result.PhraseInfo.GetText)
EndFunc

My goal, is to have a simple program, that hears a word, and then outputs it with MsgBox..

When running it, I am getting:

speechrecognition.au3 (3) : ==> Variable must be of type "Object".:
$Grammar = $RecoContext.CreateGrammar(1)
$Grammar = $RecoContext^ ERROR
>Exit code: 1   Time: 0.340

What do I need to do to make it work?

Edited by Zohar

Share this post


Link to post
Share on other sites



Zohar,

I think that you are using a "class" as an "object" (see this MSDN link http://msdn.microsoft.com/en-us/library/ms723627(v=vs.85).aspx).

Also, you should ALWAYS check return codes...

Good Luck,

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi kylomas

Thank you for your reply.

Actually I am using it right.. that waas not the problem.

The problem was that I needed to install Microsoft Speech SDK 5.1:

http://www.microsoft.com/downloads/detai...0ee-6583171b4530&displaylang=e

After installed, that solved the problem.

My program is now working, and what it does is it hears a word, and then outputs it via a MsgBox.

Local $RecoContext =ObjCreate("SAPI.SpSharedRecoContext")
If @Error Then
    Msgbox(0,"","Error Creating $RecoContext: "&@Error)
    Exit
EndIf

Local $SinkObject =ObjEvent($RecoContext,"MyEvent_")
Local $Grammar =$RecoContext.CreateGrammar(1)
$Grammar.DictationLoad
$Grammar.DictationSetState(1)  ;Start Listening
Sleep(5000)
$Grammar.DictationSetState(0)  ;Stop  Listening

Func MyEvent_Recognition($StreamNumber,$StreamPosition,$RecognitionType,$Result)
    MsgBox(0,"",$Result.PhraseInfo.GetText)
EndFunc

Note that it needs training, via ControlPanel, Speech tab.

This is the simplest implementation for Speech Recognition.

For anyone who's starting, and succeeded with this one, and wants to advance,

please see CyberZeroCool's article, for continuing:

Edited by Zohar

Share this post


Link to post
Share on other sites

Zohar,

Glad you got it working...I'll look forward to learning something from this thread, if it takes off

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

"if it takes off"?

So you mean the fact that it's working now is not taking off enough? :)

Share this post


Link to post
Share on other sites

I'm so busy finalizing my md5 license keys on Vista and probably Win7 too. I will defiantly look into this speech recognition. I just want to add once again and clarify that my gmail email account and my cricket carrier cell phone can communicate without my cell phone having internet (I do not paid for any internet feature on my phone). Speech recognition is awesome though, and if your only testing two tone button presses should be fool proof. I'm glad you have it working sounds really fun.


I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hi Xandy

Yes the method you mentioned in my other thread, that you send SMS, indeed does not require a Data Plan.

Tho please remember that SMSes do cost money :)

Edited by Zohar

Share this post


Link to post
Share on other sites

I just wanted to say thank you for getting this to work! I can't wait to try it! I've been looking for a simple way to do this for a long time and my personal efforts weren't fruitful.

Thank you.

Hi kylomas

Thank you for your reply.

Actually I am using it right.. that waas not the problem.

The problem was that I needed to install Microsoft Speech SDK 5.1:

http://www.microsoft.com/downloads/detai...0ee-6583171b4530&displaylang=e

After installed, that solved the problem.

My program is now working, and what it does is it hears a word, and then outputs it via a MsgBox.

Local $RecoContext =ObjCreate("SAPI.SpSharedRecoContext")
If @Error Then
    Msgbox(0,"","Error Creating $RecoContext: "&@Error)
    Exit
EndIf

Local $SinkObject =ObjEvent($RecoContext,"MyEvent_")
Local $Grammar =$RecoContext.CreateGrammar(1)
$Grammar.DictationLoad
$Grammar.DictationSetState(1)  ;Start Listening
Sleep(5000)
$Grammar.DictationSetState(0)  ;Stop  Listening

Func MyEvent_Recognition($StreamNumber,$StreamPosition,$RecognitionType,$Result)
    MsgBox(0,"",$Result.PhraseInfo.GetText)
EndFunc

Note that it needs training, via ControlPanel, Speech tab.

This is the simplest implementation for Speech Recognition.

For anyone who's starting, and succeeded with this one, and wants to advance,

please see CyberZeroCool's article, for continuing:

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