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