AntecUser
Member
- Joined
- Feb 20, 2011
- Messages
- 5
- Programming Experience
- 3-5
Hi im a student Computer sciences and in my spare time i like to program using .NET
no im stuck on a part with voice recognition
i want to change the colour of my form using voice recognition
my program does detect speech but doenst respond to the commands (i think the problem is with the grammar)
i use Visual Studio 2010
Greetings Tim
no im stuck on a part with voice recognition
i want to change the colour of my form using voice recognition
my program does detect speech but doenst respond to the commands (i think the problem is with the grammar)
i use Visual Studio 2010
VB.NET:
Imports SpeechLib
Imports System.Speech
Imports System.Environment
Imports System.Speech.Recognition
Imports System.DateTime
Imports System.Speech.Recognition.SrgsGrammar
Public Class Form1
Dim WithEvents reco As New Recognition.SpeechRecognizer
Private Sub SetColor(ByVal color As System.Drawing.Color)
Dim synth As New Synthesis.SpeechSynthesizer
synth.SpeakAsync("setting the back color to " + color.ToString)
Me.BackColor = color
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim gram As New SrgsDocument
Dim colorRule As New SrgsRule("color")
Dim colorsList As New SrgsOneOf("red", "green")
colorRule.Add(colorsList)
gram.Rules.Add(colorRule)
gram.Root = colorRule
reco.LoadGrammar(New Recognition.Grammar(gram))
Catch s As Exception
MessageBox.Show(s.Message)
End Try
End Sub
Private Sub reco_SpeechDetected(ByVal sender As Object, ByVal e As System.Speech.Recognition.SpeechDetectedEventArgs) Handles reco.SpeechDetected
MessageBox.Show("Speech Detected")
End Sub
Private Sub reco_SpeechRecognized(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognitionEventArgs) Handles reco.SpeechRecognized
Select Case e.Result.Text
Case "red"
SetColor(Color.Red)
Case "green"
SetColor(Color.Green)
End Select
End Sub
End Class