C#调用 WINDOWS语音识别将WAV音频转文字
作者:张赐荣
本例使用Windows本地语音识别功能实现语音到文本的转换(支持WAV音频文件)。文章来源:https://www.toymoban.com/news/detail-418097.html
public static string SpeechRecognition (string wavPath)
{
try
{
System.Speech.Recognition.SpeechRecognitionEngine sre = new System.Speech.Recognition.SpeechRecognitionEngine();
sre.LoadGrammar(new System.Speech.Recognition.DictationGrammar());
sre.SetInputToWaveFile(wavPath);
string res = null;
StringBuilder sb = new StringBuilder();
do
{
try
{
res = sre.Recognize().Text;
}
catch (Exception)
{
res = null;
}
sb.Append(res);
} while (res != null);
sre.Dispose();
return (sb.ToString());
}
catch (Exception e)
{
return (e.Message);
}
}
文章来源地址https://www.toymoban.com/news/detail-418097.html
到了这里,关于张赐荣 | C#调用 WINDOWS语音识别将WAV音频转文字的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!