如何在中文Windows7上使用SAPI5.4识别英语句子

时间:2013-03-08 19:11:12

标签: c#-4.0 windows-7 speech-recognition sapi

如果我使用语法来识别用Choice对象构造的英语句子,我使用中文Windows 7语音识别工作正常。但SpeechRecognitionEngine的对象只能出现SpeechDetectedEventArgs并且不会出现LoadGrammarCompletedEventArgs或RecognizeCompletedEventArgs当语法的对象是用SrgsDocement的对象构建的时候。我对这个项目有所了解。

    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);
        }
    }

还有一个名为commongreetingGrammar.grxml的文件构造了名为srgsdoc的SrgsDocement对象。(抱歉添加.grxml文件的图像而不是.grxml文件的纯文本)

![enter image description here][1]

1 个答案:

答案 0 :(得分:0)

我担心我没有清楚地表达我的问题。 我尝试使用SpeechRecognitionEngine类来识别英语句子,该类是SAPI5.4的一部分,在中文Windows7上安装了Microsoft语音识别器8.0 for Windows(简体中文 - PRC)。使用由对象构造的语法类对象对于Choice类,SpeechRecognitionEngine类的对象加载语法可以识别一些简单的英语句子,例如“你好吗”,“是”,“退出”。 但是,使用由.grxml文件构造的SrgsDocement对象构造的语法类对象,加载语法的SpeechRecognitionEngine对象无法识别一些简单的英语句子,只能检测到音频输入。代码片段如下所示。 / p>

Luckliy,我今天找到了问题的解决方案。 问题是我没有安装英语语言包并且错误地构造了语法对象,这导致SpeechRecognitionEngine对象无法识别英语句子。我在CodeProject中发布的解决方案的详细信息。