3

无论如何或有人知道如何使用 Microsoft 的 Speech Recognition API for Windows Form Application 进行 STT?

4

1 回答 1

5

.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

于 2013-10-13T13:18:33.777 回答