请看下面的代码
private void button2_Click(object sender, EventArgs e)
{
SpeechRecognizer sr = new SpeechRecognizer();
Choices colors = new Choices();
colors.Add(new string[] { "red arrow", "green", "blue" });
GrammarBuilder gb = new GrammarBuilder();
gb.Append(colors);
Grammar g = new Grammar(gb);
sr.LoadGrammar(g);
// SpeechSynthesizer s = new SpeechSynthesizer();
// s.SpeakAsync("start speaking");
sr.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sr_SpeechRecognized);
}
void sr_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
MessageBox.Show(e.Result.Text);
}
这是使用 MS 语音引擎的普通语音识别代码。你可以在这里看到我已经加载了一些语法。但是,也有一个问题。也就是说,这不仅响应给定的语法,还响应 MS 内置的语音命令!就像语音命令最小化窗口、打开开始菜单等!
我真的不需要那个。我的应用程序应该只响应我的语法而不是 MS 内置命令。有没有办法我可以做到这一点?