Jump to content

[Solved] The Simplest Example for Speech Recognition


Zohar
 Share

Recommended Posts

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
Link to comment
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

Link to comment
Share on other sites

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
Link to comment
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.

Link to comment
Share on other sites

  • 1 month later...

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:

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