如何使用.NET speech名称空间类将WAV文件中的音频转换为可以在屏幕上显示或保存到文件中的文本形式?
我正在寻找一些教程样本。
更新
找到代码示例here。但当我尝试它时,它给出了不正确的结果。下面是我采用的vb代码示例。(实际上,我不介意lang,只要它是vb/c#...)。它没有给我适当的结果。我假设如果我们放入正确的语法--即我们在录音中期望的单词--我们应该得到它的文本输出。首先,我尝试使用调用中的示例单词。它有时只打印那个(一个)单词,而不打印其他单词。然后,我尝试了一些我们完全不希望在recording...Unfortunately中打印出来的单词……:(
Imports System
Imports System.Speech.Recognition
Public Class Form1
Dim WithEvents sre As SpeechRecognitionEngine
Private Sub btnLiterate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLiterate.Click
If TextBox1.Text.Trim.Length = 0 Then Exit Sub
sre.SetInputToWaveFile(TextBox1.Text)
Dim r As RecognitionResult
r = sre.Recognize()
If r Is Nothing Then
TextBox2.Text = "Could not fetch result"
Return
End If
TextBox2.Text = r.Text
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = String.Empty
Dim dr As DialogResult
dr = OpenFileDialog1.ShowDialog()
If dr = Windows.Forms.DialogResult.OK Then
If Not OpenFileDialog1.FileName.Contains("wav") Then
MessageBox.Show("Incorrect file")
Else
TextBox1.Text = OpenFileDialog1.FileName
End If
End If
End Sub
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
sre = New SpeechRecognitionEngine()
End Sub
Private Sub sre_LoadGrammarCompleted(ByVal sender As Object, ByVal e As System.Speech.Recognition.LoadGrammarCompletedEventArgs) Handles sre.LoadGrammarCompleted
End Sub
Private Sub sre_SpeechHypothesized(ByVal sender As Object, ByVal e As System.Speech.Recognition.SpeechHypothesizedEventArgs) Handles sre.SpeechHypothesized
System.Diagnostics.Debug.Print(e.Result.Text)
End Sub
Private Sub sre_SpeechRecognitionRejected(ByVal sender As Object, ByVal e As System.Speech.Recognition.SpeechRecognitionRejectedEventArgs) Handles sre.SpeechRecognitionRejected
System.Diagnostics.Debug.Print("Rejected: " & e.Result.Text)
End Sub
Private Sub sre_SpeechRecognized(ByVal sender As Object, ByVal e As System.Speech.Recognition.SpeechRecognizedEventArgs) Handles sre.SpeechRecognized
System.Diagnostics.Debug.Print(e.Result.Text)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim words As String() = New String() {"triskaidekaphobia"}
Dim c As New Choices(words)
Dim grmb As New GrammarBuilder(c)
Dim grm As Grammar = New Grammar(grmb)
sre.LoadGrammar(grm)
End Sub
End Class更新(11月28日之后)
找到了加载默认语法的方法。它是这样的:
sre.LoadGrammar(New DictationGrammar)这里仍然存在问题。这种认识并不准确。输出结果是垃圾。对于一个6分钟的文件,它可能会给出5-6个与语音文件完全无关的文本。
发布于 2009-11-20 15:31:56
System.Speech中的类用于文本到语音转换(主要是一种可访问性特性)。
您正在寻找语音识别功能。从.Net 3.0开始就有可用的System.Speech.Recognition名称空间。它使用Windows桌面语音引擎。这可能会让你开始,但我想有更好的引擎在那里。
语音识别非常复杂,很难做好,也有一些商业产品可用。
发布于 2011-03-22 23:03:52
我知道这是一个古老的问题,但在后面的问题和答案中有更好的信息。例如,请参阅What is the best option for transcribing speech-to-text in a asp.net web app?
您可以调用SetInputToWaveFile()来读取音频文件,而不是调用SetInputToDefaultAudioDevice()。
Windows Vista和Windows 7中附带的桌面识别引擎包括如参考答案中所示的听写语法。
发布于 2009-11-20 15:39:24
你实际上需要自然语言工具包。在python中,我使用了NTLK http://www.nltk.org/
另请参阅文章http://en.wikipedia.org/wiki/Speech_recognition
https://stackoverflow.com/questions/1768679
复制相似问题