deo*_*oll 8 c# namespaces speech-to-text
你如何使用.NET语音命名空间类将WAV文件中的音频转换为文本形式,我可以在屏幕上显示或保存到文件?
我正在寻找一些教程样本.
在这里找到了代码示例.但是当我尝试它时它给出了不正确的结果.下面是我采用的vb代码示例.(其实我不介意lang,只要它的vb/c#...).它没有给我正确的结果.我假设如果我们把正确的语法 - 即我们在录音中所期望的单词 - 我们应该得到它的文本输出.首先,我尝试了调用中的示例单词.它有时只打印那个(一个)字而不是其他字.然后我尝试了一些我们在录音中完全没有想到的词......不幸的是它也打印出来...... :(
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
Run Code Online (Sandbox Code Playgroud)
找到了一种加载默认语法的方法.它是这样的:
sre.LoadGrammar(New DictationGrammar)
Run Code Online (Sandbox Code Playgroud)
这里还有问题.认可并不准确.输出是垃圾.对于6分钟的文件,它可能提供5-6个字的文本,与语音文件完全无关.
System.Speech中的类用于文本到语音(主要是可访问性功能).
您正在寻找语音识别.自.Net 3.0以来,可以使用System.Speech.Recognition命名空间.它使用Windows桌面语音引擎.这可能会让你开始,但我想有更好的引擎.
语音识别非常复杂,很难做到,也有一些商业产品可用.
| 归档时间: |
|
| 查看次数: |
13605 次 |
| 最近记录: |