日期:2014-05-16  浏览次数:21125 次

WPF 语音识别 关于自定义语法问题
做了个简单的语音控制.
代码:
public SpeechRecognitionEngine recognizer = null;


string[] order = {  "暂停", "播放", "停止", "静音", "退出", "下一首", "上一首" };
GrammarBuilder grammarBuilder = new GrammarBuilder();
grammarBuilder.Append(new Choices(order));
Grammar customGrammar = new Grammar(grammarBuilder);
recognizer.UnloadAllGrammars();
recognizer.LoadGrammar(customGrammar);
   recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);


  private void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            //识别结果
            this.txt.Text = e.Result.Text;
        }


之后无论我说什么指令,都会在数组order里选择.我说暂停,识别结果就是暂停,说播放,结果就是播放.
但一旦我说到数组里没有的指令,程序依旧会从数组里选出一个.
比如我说天气真好,程序发现数组里没有,并不会得出天气真好,而是从数组里挑出一个接近的,比如静音,暂停什么的.

有没有办法解决?
------解决方案--------------------
问题解决了总是好事