使用微软语音识别,我可以获得识别一半语法的时间吗?

时间:2014-07-29 00:25:13

标签: c# speech-recognition system.speech.recognition

我想使用这样的语法:这是+名称

代码是:

GrammarBuilder grammar = new GrammarBuilder();
grammar.Append("This is");
gammar.Append(new Choices("Bangalore", "Sanjay", "Cindy",...));
_recognizer.LoadGrammar(new Grammar(grammar));

我的问题是,我可以在引擎识别这是时发送事件,并在引擎识别名称时发送另一个事件吗?

怎么做?

1 个答案:

答案 0 :(得分:0)

我认为您可以通过使用短语

来做到这一点
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

我还没有能够测试它。

更新:选项词组似乎无效。

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);