如果我用語法來識別用Choice的對象構建的英文句子,我正在使用中文Windows 7語音識別工作正常。但是, SpeechRecognitionEngine只能出現SpeechDetectedEventArgs,而不會出現LoadGrammarCompletedEventArgs或RecognizeCompletedEventArgs,這時語法對象是用SrgsDocement的對象構造的。這是我對該項目的分心。如何用中文Windows7上的SAPI5.4識別英文句子
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文件構建SrgsDocement命名srgsdoc的對象。(對不起,添加.grxml文件,而不是.grxml文件的純文本的圖像)
![enter image description here][1]