C#语音识别多个单词? (承认一句)

我正在构建一个识别用户多个单词的应用程序; 因此用一个被认可的词组成一个句子。

这就是我现在所拥有的:

namespace SentenceRecognitionFramework__v1_ { public partial class Form1 : Form { SpeechRecognitionEngine recog = new SpeechRecognitionEngine(); SpeechSynthesizer sp = new SpeechSynthesizer(); public Form1() { InitializeComponent(); } private void btnListen_Click(object sender, EventArgs e) { Choices sList = new Choices(); sList.Add(new String[] { "what","is", "a", "car" }); Grammar gr = new Grammar(new GrammarBuilder(sList)); recog.RequestRecognizerUpdate(); recog.LoadGrammar(gr); recog.SpeechRecognized += sRecognize_SpeechRecognized; recog.SetInputToDefaultAudioDevice(); recog.RecognizeAsync(RecognizeMode.Multiple); recog.SpeechRecognitionRejected += sRecognize_SpeechRecognitionRejected; } private void sRecognize_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e) { sentenceBox.Text = "Sorry, I couldn't recognize"; } private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { sentenceBox.Text = e.Result.Text.ToString(); } } } 

但是,此代码一次只能识别一个单词。 即使我编辑我的代码来执行此操作:

 private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { sentenceBox.Text = sentenceBox.Text + " " + e.Result.Text.ToString(); } 

当我说出“什么是汽车”时,应用程序无法持续识别单词, 而不会在我说出来时没有rest。

为了让程序能够识别使用这些单词构建的整个句子而不必在说出句子时有语音中断 ,我可以做些什么改变?

需要输出:

我说完这句话: 什么是汽车

应用程序显示: 什么是汽车

完美示例: Google语音识别 Google使用其文字库中提供的字词开发了一个句子

非常感谢你 :)

它识别一个单词,因为你错误地构造了语法。 由于你构造的语法包括选择一个单词 “what”,“is”,“a”,“car”,它确切地识别出其中一个单词。

您可能希望阅读语法和相关文档的介绍。

http://msdn.microsoft.com/en-us/library/hh378438(v=office.14).aspx

如果你想构造描述短语的语法,你可以像这样使用GrammarBuilder:

  Grammar gr = new Grammar(new GrammarBuilder("what is a car")); 

这个语法会识别一个短语。

要了解Choices如何工作,您可以阅读有关Choices的文档:

http://msdn.microsoft.com/en-us/library/microsoft.speech.recognition.choices(v=office.14).aspx

这个答案可能有点晚了,但我还没有找到任何其他地方对此问题的实际答案。 所以为了节省其他人的时间和挫折,我就是这样做的。

 using System; using System.Threading; using System.Speech; using System.Speech.Synthesis; using System.Speech.Recognition; namespace SpeachTest { public class GrammerTest { static void Main() { Choices choiceList = new Choices(); choiceList.Add(new string[]{"what", "is", "a", "car", "are", "you", "robot"} ); GrammarBuilder builder = new GrammarBuilder(); builder.Append(choiceList); Grammar grammar = new Grammar(new GrammarBuilder(builder, 0, 4) ); //Will recognize a minimum of 0 choices, and a maximum of 4 choices SpeechRecognizer speechReco = new SpeechRecognizer(); speechReco.LoadGrammar(grammar); } } } 

这里的关键是这条线

新的GrammarBuilder(建设者,0,4)

这告诉语音识别器识别, builder最多可重复4次元素,最小值为零。

所以它现在会认出来

 "what is a car" 

如果你想要超过4次重复,只需更换new GrammarBuilder(builder, 0, 4)

 new GrammarBuilder(builder, 0 "the number of repetitions you want") 

有关详细信息,请参阅此内容GrammarBuilder(builder,minRepeat,maxRepeat)