Hi guys,
A little background first... I've dabbled in loads of programming languages on a recreational basis.. But not much more than than! My work is based entirely around the SAS programming language, so I'm fully able to understand that!!! But, although the general concept is the same, visual basic is quite different! I want to learn visual basic, so I decided to try to learn some of the more 'basic' concepts before pushing too far! I've always 'learned by doing'.. so I plan on looking at small sections of other codes, and learning by toying with them. It turns out that the little bit that I'm trying to learn isn't going well!!
Anyway, my brief question!
I grabbed some code that was supposed to be an example of speech recognition in VB2008. I'm using 2010 on the same version of Windows (7). The code was designed to simply allow you to say one of three colours, and the form background would change colour... But alas, I'm getting an error that I fail to understand. As an extra (if it helps) I needed to include the references system.speech' (NET) and 'Microsoft Speech Object Library' (COM)... The two errors are:
'Backcolor' is not a member of windowsapp1.form1
Event 'load' cannot be found.
The code is here... I have underlined the bits linked to the errors! Please feel free to tell me to go back to the complete basics and run through early tutorials (this is probably a good idea!) as I understand that you guys must get this sort of silly question lots!!! But any help or advice would be more than appreciated. Please remember this isn't my code, so I'm not trying to take any sort of prop for it, just trying to understand it!
Thanks, guys.
Imports System.Speech
Public Class Form1
Dim WithEvents reco As New Recognition.SpeechRecognitionEngine
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
reco.SetInputToDefaultAudioDevice()
Dim gram As New Recognition.SrgsGrammar.SrgsDocument
Dim colorRule As New Recognition.SrgsGrammar.SrgsRule("color")
Dim colorsList As New Recognition.SrgsGrammar.SrgsOneOf("red", "green", "blue")
colorRule.Add(colorsList)
gram.Rules.Add(colorRule)
gram.Root = colorRule
reco.LoadGrammar(New Recognition.Grammar(gram))
reco.RecognizeAsync()
End Sub
Private Sub reco_RecognizeCompleted(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognizeCompletedEventArgs) Handles reco.RecognizeCompleted
reco.RecognizeAsync()
End Sub
Private Sub reco_SpeechRecognized(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognitionEventArgs) Handles reco.SpeechRecognized
Select e.Result.Text
Case "red"
SetColor(Color.Red)
Case ("green")
SetColor(Color.Green)
Case ("blue")
SetColor(Color.Blue)
End Select
End Sub
End Class
A little background first... I've dabbled in loads of programming languages on a recreational basis.. But not much more than than! My work is based entirely around the SAS programming language, so I'm fully able to understand that!!! But, although the general concept is the same, visual basic is quite different! I want to learn visual basic, so I decided to try to learn some of the more 'basic' concepts before pushing too far! I've always 'learned by doing'.. so I plan on looking at small sections of other codes, and learning by toying with them. It turns out that the little bit that I'm trying to learn isn't going well!!
Anyway, my brief question!
I grabbed some code that was supposed to be an example of speech recognition in VB2008. I'm using 2010 on the same version of Windows (7). The code was designed to simply allow you to say one of three colours, and the form background would change colour... But alas, I'm getting an error that I fail to understand. As an extra (if it helps) I needed to include the references system.speech' (NET) and 'Microsoft Speech Object Library' (COM)... The two errors are:
'Backcolor' is not a member of windowsapp1.form1
Event 'load' cannot be found.
The code is here... I have underlined the bits linked to the errors! Please feel free to tell me to go back to the complete basics and run through early tutorials (this is probably a good idea!) as I understand that you guys must get this sort of silly question lots!!! But any help or advice would be more than appreciated. Please remember this isn't my code, so I'm not trying to take any sort of prop for it, just trying to understand it!
Thanks, guys.
Imports System.Speech
Public Class Form1
Dim WithEvents reco As New Recognition.SpeechRecognitionEngine
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
reco.SetInputToDefaultAudioDevice()
Dim gram As New Recognition.SrgsGrammar.SrgsDocument
Dim colorRule As New Recognition.SrgsGrammar.SrgsRule("color")
Dim colorsList As New Recognition.SrgsGrammar.SrgsOneOf("red", "green", "blue")
colorRule.Add(colorsList)
gram.Rules.Add(colorRule)
gram.Root = colorRule
reco.LoadGrammar(New Recognition.Grammar(gram))
reco.RecognizeAsync()
End Sub
Private Sub reco_RecognizeCompleted(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognizeCompletedEventArgs) Handles reco.RecognizeCompleted
reco.RecognizeAsync()
End Sub
Private Sub reco_SpeechRecognized(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognitionEventArgs) Handles reco.SpeechRecognized
Select e.Result.Text
Case "red"
SetColor(Color.Red)
Case ("green")
SetColor(Color.Green)
Case ("blue")
SetColor(Color.Blue)
End Select
End Sub
End Class