我在C#中创建了一个简单的语法,之后我使用了SpeechRecognizer.SpeechRecognized Event。但我不知道为什么它与Microsoft Speech Recognizer(英语 - 美国)一起使用,但它不适用于Microsoft Speech Recognizer(英语 - 英语)。
这是代码:
private void button1_Click(object sender, EventArgs e)
{
System.Speech.Recognition.SpeechRecognizer sr = new SpeechRecognizer();
Choices Slist = new Choices();
Slist.Add(new string[] { "Brazil", "Germany", "Argentina", "Netherlands" });
Grammar gr = new Grammar(new GrammarBuilder(Slist));
sr.RequestRecognizerUpdate();
sr.LoadGrammarAsync(gr);
sr.SpeechRecognized += sr_SpeechRecognized;
}
void sr_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text.ToString()== "Brazil")
{
MessageBox.Show("Fourth");
}
if (e.Result.Text.ToString() == "Germany")
{
MessageBox.Show("First");
}
if (e.Result.Text.ToString() == "Argentina")
{
MessageBox.Show("Second");
}
if (e.Result.Text.ToString() == "Netherlands")
{
MessageBox.Show("third");
}
}
任何帮助都将不胜感激。