我做了很多研究并想出了下面的代码。它使用麦克风成功地将语音转换为文本。
我的网络服务器上有一个文件,通过 mp3 流式传输音频。它只是一个 mp3 文件的链接。我需要把它翻译成文本。
我试图找出最好的方法来做到这一点。那么,您可以选择音频输入作为计算机音频(即在网络浏览器中播放音频)吗?或者您可以将音频直接传输给翻译人员吗?我想我需要使用SetInputToWaveStream方法,但不明白如何使用它。
Private Sub InitializeRecognizerSynthesizer()
Dim selectedRecognizer = ( _
Where e.Culture.Equals(Thread.CurrentThread.CurrentCulture)).FirstOrDefault()
recognizer = New SpeechRecognitionEngine(selectedRecognizer)
recognizer.AudioStateChanged += New EventHandler(Of AudioStateChangedEventArgs)(recognizer_AudioStateChanged)
recognizer.SpeechHypothesized += New EventHandler(Of SpeechHypothesizedEventArgs)(recognizer_SpeechHypothesized)
recognizer.SpeechRecognized += New EventHandler(Of SpeechRecognizedEventArgs)(recognizer_SpeechRecognized)
synthesizer = New SpeechSynthesizer()
End Sub
Private Function SelectInputDevice() As Boolean
Dim proceedLoading As Boolean = True
If IsOscompatible() Then
Try
recognizer.SetInputToDefaultAudioDevice()
Catch
'no audio input device
proceedLoading = False
End Try
Else
ThreadPool.QueueUserWorkItem(InitSpeechRecogniser)
End If
Return proceedLoading
End Function