Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i'm developing a speech to text software. I have two (2) buttons, Listen and stop, on my form. Under button Listen i have a thread, on form load i have an event and a method to invoke an action. I'm having problem with the invoke method and the event handler on the form load. This is the code...

VB
Public class DisabledChat
    Dim recog As SpeechRecognizedEventArgs
    Dim RecognizerState As Boolean
    Dim RecThread As Thread
    Dim recognizer As New SpeechRecognitionEngine

    Private sub btnListen_click(sender As Object, e As EventsArgs) Handles btnListen.Click
        RecognizerState = True
        RecThread = New Thread (Sub()
            while true
                 if RecognizerState = True
                     End
                 End if
                 Try
                     recognizer.Recognize()
             cth ex As Exception
                      'Handles error
                       MsgBox("There is an error recognizing your voice" & ex.Message)
                   End Try
                   End While
                   End Sub)
    Private Sub Chat_Load (sender As Object, e As EventArgs) Handles MyBase.Load
         'Grammer codes
         
          'Event handler
         AddHandler myobj.AnEvent, AddressOf rec_Speech
         myobj.CauseTheEvent()
         RemoveHandler myobj.AnEvent, AddressOf rec_Speech
         myobj.CauseHandler()

         End Sub

        Sub rec_Speech(sender As Object, recog As SpeechRecognisedEventArgs)
        'Recognizes the speech
         If Not RecognizerState Then
              Return
         End if
         Me.Invoke(Sub()
                           txtVisual.Text += (" " + recog.Result.Text.ToLower())
                            End Sub)
         End Sub

         Public Class Class1
             Public Event AnEvent (recog As SpeechRecognizedEventArgs)
             Sub CauseTheEvent()
                    ' Reaise an evetnt
                    RaiseEvent AnEvent()
             End Sub
    End Class

End Class)
The rec_Speech in the event has been underlined and when i start the code, the txtVisual.text += (" " + recog.Result.Text.ToLower() is highlighted yellow with the information that 'it does not have an object and its not able to recognize the speech neither to translate to text. Please counting on your support. Thanks in advance...
Posted
Updated 22-Apr-15 12:09pm
v2
Comments
Adepa Ampofo 22-Apr-15 18:04pm    
please the subject is invoke method not event method

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900