1
我正在制作一个具有语音命令的简单程序。我不完全知道vb.net中的代码,所以我试图复制C#中的代码,然后把它放在VB中,当我运行它时,它说“空规则是不允许的”Visual Basic .Net语音命令
这是我的代码:
Private Sub loginCommandFom_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Dim commandChoices As New Recognition.Choices
Dim grammarBuilder As New Recognition.GrammarBuilder
Dim gr As New Recognition.Grammar(grammarBuilder)
commandChoices.Add(New String("Hey", "Wazzup"))
grammarBuilder.Append(commandChoices)
commandRecognition.LoadGrammarAsync(gr)
commandRecognition.SetInputToDefaultAudioDevice()
commandRecognition.RecognizeAsync()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Private Sub speechCompleted(sender As Object, e As System.Speech.Recognition.RecognizeCompletedEventArgs) Handles commandRecognition.RecognizeCompleted
commandRecognition.RecognizeAsync()
End Sub
Private Sub speechRecognize(sender As Object, e As System.Speech.Recognition.SpeechRecognizedEventArgs) Handles commandRecognition.SpeechRecognized
Select Case e.Result.Text
Case "Hey"
MsgBox("Yeah")
Case "Wazzup"
MsgBox("Yah")
End Select
End Sub