Speech Recognition

b3jsd73jfx

Active member
Joined
Mar 6, 2006
Messages
28
Programming Experience
1-3
Below is the codethat I currently have to try and do some basic speech recognition, but it just won't seem to work. Does anyone have any ideas?
VB.NET:
    Dim WithEvents RecoContext As SpSharedRecoContext
    Dim Grammar As ISpeechRecoGrammar

    Private Sub RecoContext_Recognition(ByVal StreamNumber As Long, ByVal StreamPosition As Object, ByVal RecognitionType As SpeechRecognitionType, ByVal Result As ISpeechRecoResult)
        Dim strText As String
        strText = Result.PhraseInfo.GetText
        MsgBox(strText)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RecoContext = New SpSharedRecoContext
        Grammar = RecoContext.CreateGrammar(1)
        Grammar.DictationLoad()
        Grammar.DictationSetState(SpeechRuleState.SGDSActive)
    End Sub
 
You forgot to add the Handles statement to the event handler method, also the method signature is wrong (probably due to conversion from older VB language). When you got objects declared WithEvents, you can simply select the object in top combobox in codeview then select the event in the events combobox, and IDE will generate the event handler code correctly. Microsoft Speech SDK 5.1 have to be installed if it wasn't already (http://www.microsoft.com/downloads/details.aspx?FamilyId=5E86EC97-40A7-453F-B0EE-6583171B4530&displaylang=en).
VB.NET:
Private Sub RecoContext_Recognition(ByVal [COLOR=red]StreamNumber As Integer[/COLOR], _
ByVal StreamPosition As Object, _
ByVal RecognitionType As SpeechLib.SpeechRecognitionType, _
ByVal Result As SpeechLib.ISpeechRecoResult) _
[COLOR=red]Handles RecoContext.Recognition[/COLOR]
  MessageBox.Show(Result.PhraseInfo.GetText)
End Sub
 
Back
Top