I am messing around with speech recognition, for no real reason other than trying to get it to work. I have read countless tutorials on this all over the web. I can get it to compile without errors, but nothing ever happens. I have even rather lamely completed all the speech recognition training on my windows 7, just in case.
I am pretty sure I'm importing and referencing everything I am meant to. If anyone could either point to a really idiots guide or tell me whats wrong with the code below / post some really simple working code, it would be great!
I am pretty sure I'm importing and referencing everything I am meant to. If anyone could either point to a really idiots guide or tell me whats wrong with the code below / post some really simple working code, it would be great!
Code:
Imports System.Speech
Imports System.Speech.Recognition
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Using recognizer As New SpeechRecognitionEngine()
Dim words As New Choices(New String() {"hello", "goodbye"})
Dim builder As New GrammarBuilder()
builder.Append(words)
Dim g As New Grammar(builder)
g.Name = ("labeltext")
recognizer.LoadGrammarAsync(g)
AddHandler recognizer.LoadGrammarCompleted, AddressOf recognizer_LoadGrammarCompleted
AddHandler recognizer.SpeechDetected, AddressOf recognizer_speechdetected
AddHandler recognizer.SpeechRecognized, AddressOf recognizer_SpeechRecognized
recognizer.SetInputToDefaultAudioDevice()
recognizer.RecognizeAsync()
End Using
End Sub
Private Sub recognizer_LoadGrammarCompleted(sender As Object, e As LoadGrammarCompletedEventArgs)
Label1.Text = "Loaded"
End Sub
Private Sub recognizer_speechdetected(sender As Object, e As SpeechDetectedEventArgs)
Label1.Text = "Your speaking"
End Sub
Private Sub recognizer_SpeechRecognized(sender As Object, e As SpeechRecognizedEventArgs)
Label2.Text = "You said " & e.Result.Text
End Sub
End Class