【问题标题】:Convert Audio File to text using System.Speech使用 System.Speech 将音频文件转换为文本
【发布时间】:2011-05-10 07:27:23
【问题描述】:

我正在寻找使用 C# 将通过 android 手机录制的 .wav 文件转换为文本,以 16000;即 System.Speech 命名空间。我的代码在下面提到;

recognizer.SetInputToWaveFile(Server.MapPath("~/spoken.wav"));
recognizer.LoadGrammar(new DictationGrammar());
RecognitionResult result = recognizer.Recognize();
label1.Text = result.Text;

与示例 .wav "Hello world" 文件完美配合。但是,当我在手机上录制内容并尝试在电脑上转换时,转换后的文本与我录制的内容相差甚远。有什么方法可以确保音频文件被准确转录吗?

【问题讨论】:

    标签: c# speech-recognition speech-to-text system.speech.recognition


    【解决方案1】:

    手机的音频文件是用什么格式录制的?文件是否编码? Microsoft 识别器支持 PCM、ALaw 和 ULaw。确保以受支持的格式录制。您可以查看 RecognizerInfo.SupportedAudioFormats 属性 - http://msdn.microsoft.com/en-us/library/system.speech.recognition.recognizerinfo.supportedaudioformats(v=VS.90).aspx 并检查您的识别器版本支持的格式。

    你听过你在手机上录制的文件吗?吵吗?听起来清楚吗?确保为识别器提供最佳音效。

    由于您使用的是听写语法,我假设您使用的是 Windows 7。您是否尝试过训练识别器?我的理解是听写语法的表现可以通过训练来提高,标准的Windows 7语音识别训练将有助于它的表现-http://windows.microsoft.com/en-US/windows7/Set-up-Speech-Recognition

    有关 StackOverflow 的其他一些问题也可能会给您一些见解。请参阅good Speech recognition API 开始。

    【讨论】:

      【解决方案2】:

      您可以在此处找到您想要的完整实施细节:

      Converting WAV audio to text using System.Speech

      【讨论】:

      • -1 链接页面中的示例与OP发布的示例基本相同
      【解决方案3】:
      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 
      

      或试试这个链接 Audio to text software free

      【讨论】:

      • -1 您的代码几乎与 OP 的代码重复,您没有回答问题。另外,链接的服务并不像它所说的那样免费
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-18
      • 1970-01-01
      • 2018-12-19
      • 2011-03-16
      • 2015-09-18
      • 1970-01-01
      相关资源
      最近更新 更多