设为首页收藏本站

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 270|回复: 1

convert wave file to Text format

[复制链接]
发表于 2014-1-27 20:22:33 | 显示全部楼层 |阅读模式
  1. SpeechRecognitionEngine RecognitionEngine;
  2. using (RecognitionEngine = new SpeechRecognitionEngine(new CultureInfo("en-US")))
  3. {
  4. RecognitionEngine.SetInputToWaveFile"D:/wav/test.wav");

  5. //RecognitionEngine.RecognizeCompleted += new EventHandler<RecognizeCompletedEventArgs>(RecognitionEngine_RecognizeCompleted);
  6. RecognitionEngine.LoadGrammar(new DictationGrammar());
  7. RecognitionResult Result = RecognitionEngine.Recognize();
  8. RecognitionEngine.RecognizeAsync(RecognizeMode.Single);

  9. StringBuilder Output = new StringBuilder();
  10. foreach (RecognizedWordUnit Word in Result.Words)
  11. {
  12. Output.Append(Word.Text + " ");
  13. }

  14. // RecognitionEngine.RecognizeAsyncStop();

  15. lbl_result.Text = Output.ToString();

  16. RecognitionEngine.Dispose();
  17. //Dispose();
复制代码
i tried using Dispose method also but no use.
how to solve this pbm. And the output should be as it is on the given wave file,because it shows wrong output some words are correct and some incorrect. is there anyway to get the exact output .                                                                                               
 楼主| 发表于 2014-1-27 20:31:13 | 显示全部楼层

Converting or Transcribing audio to text using C# and .NET System.Speech

Recently, I had a project where I needed to convert some audio to text. It took a bit more googling than I was used to in order to find the code, so I went ahead and whipped up a project that demonstrates its usage, so people can more easily find it.
This code uses the .NET System.Speech namespace and demonstrates how to transcribe audio using either a microphone or a previously created .wav file using C#.
The code can be divided into 2 main parts:
Step 1: Configuring the SpeechRecognitionEngine


  1. _speechRecognitionEngine = new SpeechRecognitionEngine();
  2. _speechRecognitionEngine.SetInputToDefaultAudioDevice();
  3. _dictationGrammar = new DictationGrammar();
  4. _speechRecognitionEngine.LoadGrammar(_dictationGrammar);
  5. _speechRecognitionEngine.RecognizeAsync(RecognizeMode.Multiple);
复制代码


At this point your object is ready to start transcribing audio from the microphone. You need to handle some events though, in order to actually get access to the results.
Step 2: Handling the SpeechRecognitionEngine Events
  1. _speechRecognitionEngine.SpeechRecognized -= new EventHandler(SpeechRecognized);
  2. _speechRecognitionEngine.SpeechHypothesized -= new EventHandler(SpeechHypothesizing);

  3. _speechRecognitionEngine.SpeechRecognized += new EventHandler(SpeechRecognized);
  4. _speechRecognitionEngine.SpeechHypothesized += new EventHandler(SpeechHypothesizing);

  5. private void SpeechHypothesizing(object sender, SpeechHypothesizedEventArgs e)
  6. {
  7. ///real-time results from the engine
  8. string realTimeResults = e.Result.Text;
  9. }

  10. private void SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
  11. {
  12. ///final answer from the engine
  13. string finalAnswer = e.Result.Text;
  14. }
复制代码

That’s it.  If you want to use a pre-recorded .wav file instead of a microphone, you would use
  1. _speechRecognitionEngine.SetInputToWaveFile(pathToTargetWavFile);
复制代码

instead of
  1. _speechRecognitionEngine.SetInputToDefaultAudioDevice();
复制代码

There are a bunch of different options in these classes and they are worth exploring in more detail.  This covers the bare essentials for a prototype.  I have attached a full example and encapsulation here. or


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|BC Morning Website ( Best Deal Inc. 001 )  

GMT-8, 2025-12-12 11:07 , Processed in 0.016686 second(s), 17 queries .

Supported by Best Deal Online X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表