我在玩这个 SAPI v5.1 库。所以我正在测试我拥有的示例 WAV 文件。(从这里下载)。无论如何,该文件中的声音清晰易懂。它只包含一个单词,即第三个单词。现在,当我运行以下代码时,我得到数字 8 或“八”。如果我删除它,我会得到 7。如果我尝试随机化列表,我会得到不同的结果,依此类推。我真的很困惑,并开始认为 SAPI 库中的 SpeachRecognition 根本不起作用......
无论如何,这就是我正在做的,
private void button1_Click(object sender, EventArgs e)
{
//Add choices to grammar.
Choices mychoices = new Choices();
mychoices.Add("one");
mychoices.Add("two");
mychoices.Add("three");
mychoices.Add("four");
mychoices.Add("five");
mychoices.Add("six");
mychoices.Add("seven");
mychoices.Add("eight");
mychoices.Add("nine");
mychoices.Add("zero");
mychoices.Add("1");
mychoices.Add("2");
mychoices.Add("3");
mychoices.Add("4");
mychoices.Add("5");
mychoices.Add("6");
mychoices.Add("7");
mychoices.Add("8");
mychoices.Add("9");
mychoices.Add("0");
Grammar myGrammar = new Grammar(new GrammarBuilder(mychoices));
//Create the engine.
SpeechRecognitionEngine reco = new SpeechRecognitionEngine();
//Read audio stream from wav file.
reco.SetInputToWaveFile("3.wav");
reco.LoadGrammar(myGrammar);
//Get the recognized value.
reco.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(reco_SpeechRecognized);
reco.RecognizeAsync(RecognizeMode.Multiple);
}
void reco_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
MessageBox.Show(e.Result.Text);
}