0

I am using an Chinese Windows 7 with speech recognition working fine if I use the grammar to recognize English sentences which is constructed with the object of Choice.But the object of SpeechRecognitionEngine only can arise SpeechDetectedEventArgs and doesn't arise LoadGrammarCompletedEventArgs or RecognizeCompletedEventArgs when the the object of Grammar is constructed with the object of SrgsDocement.There is my fragement of the project.

    SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine ( System.Globalization.CultureInfo.CreateSpecificCulture("zh-CN"));
            SrgsDocument srgsdoc = new SrgsDocument(./commongreetingGrammar.grxml");
            recognizer.MaxAlternates = 5;
            recognizer.LoadGrammarCompleted += new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);
            recognizer.SpeechDetected += new EventHandler<SpeechDetectedEventArgs>(recognizer_SpeechDetected);
            recognizer.RecognizeCompleted += new EventHandler<RecognizeCompletedEventArgs>(recognizer_RecognizeCompleted);
            recognizer.LoadGrammar(new Grammar(srgsdoc));

            recognizer.SetInputToDefaultAudioDevice();
            recognizer.RecognizeAsync (RecognizeMode .Multiple);
        }
        catch (Exception ex)
        { Console.WriteLine(ex.Message); }
        Console.ReadKey();
    }

    static void recognizer_SpeechDetected(object sender, SpeechDetectedEventArgs e)
    {
        Console.WriteLine("Detect that someone is speeching");
    }

    static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)
    {
        if (e.Error == null)
            Console.WriteLine("complete to load grammar ");
        else
            Console.WriteLine("Fail to load grammar");
    }

    static void recognizer_RecognizeCompleted(object sender, RecognizeCompletedEventArgs e)
    {
        if (e.Result.Semantics["step"].Value.ToString() == "A1")
        {
            Console.WriteLine("A start to speak:{0}", e.Result.Text);
        }
    }

And there is the file named commongreetingGrammar.grxml that constructs the object of SrgsDocement named srgsdoc .(Sorry to add the image of the .grxml file instead of the plain text of the .grxml file)

![enter image description here][1]
4

1 回答 1

0

恐怕我没有清楚地提出我的问题。我尝试使用 SpeechRecognitionEngine 类(它是 SAPI5.4 的一部分)在安装了 Microsoft Speech Recognizer 8.0 for Windows(简体中文 - 中国)的中文 Windows7 上识别英文句子。使用用该对象构造的 Grammar 类的对象Choice类的SpeechRecognitionEngine类的对象加载了语法可以识别一些简单的英语句子,例如,“你好吗”,“是”,“退出”。但是,使用由.grxml文件构造的SrgsDocement对象构造的Grammar类对象,加载语法的SpeechRecognitionEngine对象不能识别一些简单的英文句子,只能检测音频输入。代码片段如下。

幸运的是,我今天找到了解决问题的方法。问题是我没有安装英语语言包,错误地构造了Grammar对象,导致SpeechRecognitionEngine对象无法识别英语句子。解决方法的细节我已经在CodeProject中发布。

于 2013-03-10T04:08:02.457 回答