5

我有用 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
4

2 回答 2

5

RecognizeAsync() does a single recognition. RecognizeAsync(RecognizeMode.Multiple) will do multiple recognitions.

于 2013-07-01T21:55:50.427 回答
2
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

所有问题都解决了:)

于 2018-04-09T13:35:04.963 回答