我有用Visual Basic编写的语音文本代码,但它只识别第一个单词或句子,然后停止识别。我希望它继续听。我怎样才能做到这一点?问题是什么? 这是我现在的代码:
Imports System.Speech
Public Class Form1
Public synth As New Speech.Synthesis.SpeechSynthesizer
Public WithEvents recognizer As New Speech.Recognition.SpeechRecognitionEngine
Dim gram As New System.Speech.Recognition.DictationGrammar()
Public Sub GotSpeech(ByVal sender As Object, ByVal phrase As System.Speech.Recognition.SpeechRecognizedEventArgs) Handles recognizer.SpeechRecognized
words.Text += phrase.Result.Text & vbNewLine
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
recognizer.LoadGrammar(gram)
recognizer.SetInputToDefaultAudioDevice()
recognizer.RecognizeAsync()
End Sub
End Class
答案 0 :(得分:3)
RecognizeAsync()进行单一表彰。 RecognizeAsync(RecognizeMode.Multiple)会做多次认可。
答案 1 :(得分:1)
Imports System.Speech
Public Class Form1
Public synth As New Speech.Synthesis.SpeechSynthesizer
Public WithEvents recognizer As New Speech.Recognition.SpeechRecognitionEngine
Dim gram As New System.Speech.Recognition.DictationGrammar()
Public Sub GotSpeech(ByVal sender As Object, ByVal phrase As System.Speech.Recognition.SpeechRecognizedEventArgs) Handles recognizer.SpeechRecognized
word.Text += phrase.Result.Text + ""
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
recognizer.LoadGrammar(gram)
recognizer.SetInputToDefaultAudioDevice()
recognizer.RecognizeAsync(Recognition.RecognizeMode.Multiple)
End Sub
End Class
清除所有问题 :)