Click to See Complete Forum and Search --> : Speech Recognition Event Problem


ccubed
October 14th, 2008, 06:53 PM
So I'm trying out SAPI 5.3 in Vista and I was trying to write something simple to start out with. I get the synthesizer working to where it speaks, but now i'm trying to get the recognizer working so I can get what people say. I'd like to get the text result of their speech, meaning the 1st and most likely recognized candidate. Now I'm having problem getting the sub event handler to work.


Imports System.Speech

Public Class Form1

Public synth As New Speech.Synthesis.SpeechSynthesizer
Public recognizer As New Speech.Recognition.SpeechRecognitionEngine

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

synth.Speak("This is a test.")

End Sub

Public Sub GotSpeech(ByVal phrase As System.Speech.Recognition.SpeechRecognizedEventArgs) Handles recognizer.SpeechRecognized

words.Text += phrase.Result.Text & "\n"

End Sub
End Class


It keeps saying this for Public Sub GotSpeech.

Error 1 Handles clause requires a WithEvents variable defined in the containing type or one of its base types.


I'm not really sure what it wants from me with the "WithEvents" variable.

ccubed
October 14th, 2008, 07:08 PM
Okay, So I got the WithEvents down, but now it won't recognize anything I say. It just stops and never triggers the gotspeech sub. Can anyone help?


Imports System.Speech

Public Class Form1

Public synth As New Speech.Synthesis.SpeechSynthesizer
Public WithEvents recognizer As New Speech.Recognition.SpeechRecognitionEngine

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

synth.Speak("This is a test.")

End Sub

Public Sub GotSpeech(ByVal sender As Object, ByVal phrase As System.Speech.Recognition.SpeechRecognizedEventArgs) Handles recognizer.SpeechRecognized

words.Text += phrase.Result.Text & "\n"

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

recognizer.SetInputToDefaultAudioDevice()
recognizer.Recognize()

End Sub
End Class

ccubed
October 14th, 2008, 09:47 PM
I'm thinking maybe it needs grammar. I figure that since it was a built in class it might automatically load a base grammar set but now i'm not so sure. So I guess my question changes to how I could import a base grammar set, like the one vista uses for its speech recognition.