SpeechRecognitionEngine RecognizeCompleted事件不会触发

时间:2014-05-13 14:49:54

标签: c# event-handling speech-recognition text-to-speech

我一直在寻找这个问题,但我找不到任何有用的东西。 我想从wav文件中执行连续语音识别using System.Speech.Recognition;但是,我希望在识别引擎完成其工作时返回结果。 我找到了solution来使用RecognizeCompleted事件处理程序,但它根本不会触发。 识别码:

        SpeechRecognitionEngine speechRecognitionEngine = null;
        bool completed = false;
        // create the engine
        speechRecognitionEngine = createSpeechEngine("en-GB");

        // hook to events
        speechRecognitionEngine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(engine_SpeechRecognized);
        speechRecognitionEngine.RecognizeCompleted += new EventHandler<RecognizeCompletedEventArgs>(recognizer_RecognizeCompleted);

        // load dictionary
        speechRecognitionEngine.LoadGrammar(new DictationGrammar());
        speechRecognitionEngine.SetInputToWaveFile("C:\\Converted Audio\\BBC1 cut sport.wav");

        // start listening for continuous speech recognition 
        speechRecognitionEngine.RecognizeAsync(RecognizeMode.Multiple);

        while (!completed)
        {
            Thread.Sleep(333);
        }

事件处理程序代码:

void recognizer_RecognizeCompleted(object sender, RecognizeCompletedEventArgs e)
    {
        completed = true;
    }

0 个答案:

没有答案