有没有人知道如何使用 Microsoft 的语音识别 API for Windows Form Application 进行 STT?

最佳答案

.NET 包含用于语音识别的程序集。
您需要将引用添加到



并添加命名空间

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/

10-13 21:38