使用System.Speech将mp3文件转换为文本
我正在尝试使用.net中的语音识别来识别mp3文件中播客的语音,并将结果作为字符串。 我见过的所有例子都与使用麦克风有关但我不想使用麦克风并提供一个示例mp3文件作为我的音频源。 任何人都可以指向任何资源或发布示例。
编辑 –
我将音频文件转换为wav
文件并在其上尝试此代码。 但它只提取前68个单词。
public class MyRecognizer { public string ReadAudio() { SpeechRecognitionEngine sre = new SpeechRecognitionEngine(); Grammar gr = new DictationGrammar(); sre.LoadGrammar(gr); sre.SetInputToWaveFile("C:\\Users\\Soham Dasgupta\\Downloads\\Podcasts\\Engadget_Podcast_353.wav"); sre.BabbleTimeout = new TimeSpan(Int32.MaxValue); sre.InitialSilenceTimeout = new TimeSpan(Int32.MaxValue); sre.EndSilenceTimeout = new TimeSpan(100000000); sre.EndSilenceTimeoutAmbiguous = new TimeSpan(100000000); RecognitionResult result = sre.Recognize(new TimeSpan(Int32.MaxValue)); return result.Text; } }
尝试循环阅读。
SpeechRecognitionEngine sre = new SpeechRecognitionEngine(); Grammar gr = new DictationGrammar(); sre.LoadGrammar(gr); sre.SetInputToWaveFile("C:\\Users\\Soham Dasgupta\\Downloads\\Podcasts\\Engadget_Podcast_353.wav"); sre.BabbleTimeout = new TimeSpan(Int32.MaxValue); sre.InitialSilenceTimeout = new TimeSpan(Int32.MaxValue); sre.EndSilenceTimeout = new TimeSpan(100000000); sre.EndSilenceTimeoutAmbiguous = new TimeSpan(100000000); StringBuilder sb = new StringBuilder(); while (true) { try { var recText = sre.Recognize(); if (recText == null) { break; } sb.Append(recText.Text); } catch (Exception ex) { //handle exception //... break; } } return sb.ToString();
如果您有Windows窗体或WPF应用程序,请在单独的线程中运行此代码,否则它会阻止UI线程。
我首先看一下这里记录的方法: http : //msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognitionengine.setinputtowavefile.aspx
你应该能够在这里解决这个问题。
- 在.NET Speech中添加另一个语音
- 加密C#中web.config文件中的连接字符串
- FileStream.BeginWrite优于FileStream.Write?
- Scaffold-DbContext在.net核心中抛出错误“找不到程序集”
- 为什么我可以通过索引访问KeyCollection / ValueCollection中的项目,即使它没有实现IList(Of Key)?
- 使用C#/ .NET替换文件中文本的最佳方法是什么?
- 如何在.NET / C#中以编程方式为我的应用程序创建快捷方式(.lnk)添加快捷方式(.lnk)
- 双变量保持错误的值
- 为什么我不能安装我的服务(运行时比加载的运行时更新)?