我想使用这样的语法:This is + name。
代码是:
GrammarBuilder grammar = new GrammarBuilder();
grammar.Append("This is");
gammar.Append(new Choices("Bangalore", "Sanjay", "Cindy",...));
_recognizer.LoadGrammar(new Grammar(grammar));
我的问题是,我能否在引擎识别出 This is 时发送事件,并在引擎识别出名称时发送另一个事件?
如何做到这一点?
最佳答案
我想你可以通过使用短语来做到这一点
GrammarBuilder thisIsPhrase = new GrammarBuilder("This is");
Choices choices = new Choices("Dog, Cat");
GrammarBuilder endPhrase = new GrammarBuilder(choices);
Choices both = new Choices(new GrammarBuilder[] { thisIsPhrase, endPhrase });
Grammar dictationGrammar = new Grammar((GrammarBuilder)both);
参见 MSDN .
虽然我还没有能够测试它。
更新:choices 短语似乎不起作用。
GrammarBuilder thisIsPhrase = new GrammarBuilder("This is");
GrammarBuilder endPhrase = new GrammarBuilder("Dog"); //repeat creating phrases
Choices both = new Choices(new GrammarBuilder[] { thisIsPhrase, endPhrase });//also need to add phrases here
Grammar dictationGrammar = new Grammar((GrammarBuilder)both);
关于c# - 使用microsoft speech recognition,我能得到语法识别到一半的时间吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25006441/