CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2007
    Location
    .NET 3.5 Beta SP1, Visual Basic 2008 Express
    Posts
    225

    Speech Recognition Event Problem

    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.

    Code:
    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.
    Code:
    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.
    Microsoft Visual Basic 2008 Express Edition
    .NET Framwork 3.5 Beta SP1

  2. #2
    Join Date
    Jun 2007
    Location
    .NET 3.5 Beta SP1, Visual Basic 2008 Express
    Posts
    225

    Re: Speech Recognition Event Problem

    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?

    Code:
    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
    Microsoft Visual Basic 2008 Express Edition
    .NET Framwork 3.5 Beta SP1

  3. #3
    Join Date
    Jun 2007
    Location
    .NET 3.5 Beta SP1, Visual Basic 2008 Express
    Posts
    225

    Re: Speech Recognition Event Problem

    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.
    Microsoft Visual Basic 2008 Express Edition
    .NET Framwork 3.5 Beta SP1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured