gpt4 book ai didi

c# - 使用 SAPI 将语音转换为文本

转载 作者:行者123 更新时间:2023-11-30 14:58:17 25 4
gpt4 key购买 nike

有没有人知道如何使用 Microsoft 的 Windows 窗体应用程序语音识别 API 进行 STT?

最佳答案

.NET 包含一个用于语音识别的程序集。您需要添加对

的引用

System.Speech

并添加命名空间

using System.Speech.Recognition;

以下代码将分析您的语音并将文本添加到文本框:

private void startRecognition()
{
SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine(); //default culture
//SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine(new CultureInfo("de-DE"));
//With specified culture | Could cause an CultureNotFoundException
Grammar dictationGrammar = new DictationGrammar();
recognizer.LoadGrammar(dictationGrammar);
try
{
recognizer.SetInputToDefaultAudioDevice();
RecognitionResult result = recognizer.Recognize();
if(result != null)
result_textBox.Text += result.Text + "\r\n";
}
catch (InvalidOperationException exception)
{
MessageBox.Show(exception.Message,exception.Source);
}
finally
{
recognizer.UnloadAllGrammars();
}
}

要更改识别超时的时间,请更改以下属性:

    recognizer.InitialSilenceTimeout = TimeSpan.FromSeconds(3);
recognizer.BabbleTimeout = TimeSpan.FromSeconds(2);
recognizer.EndSilenceTimeout = TimeSpan.FromSeconds(1);
recognizer.EndSilenceTimeoutAmbiguous = TimeSpan.FromSeconds(1.5);

来源:

http://msdn.microsoft.com/en-us/magazine/cc163663.aspx | http://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognitionengine.aspx

关于c# - 使用 SAPI 将语音转换为文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19345460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com