我正在尝试使用c#中的语音识别功能。我正在尝试这个代码,它的例外是
找不到请求的数据项,例如数据键或值
这是我正在使用的代码
public partial class Form1 : Form
{
SpeechRecognizer rec = new SpeechRecognizer();
public Form1()
{
InitializeComponent();
rec.SpeechRecognized += rec_SpeechRecognized;
}
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show(SpeechRecognitionEngine.InstalledRecognizers().Count.ToString());
var c = new Choices();
// Doens't work must use English words to add to Choices and
// populate grammar.
//
//for (var i = 0; i <= 100; i++)
// c.Add(i.ToString());
c.Add("one");
c.Add("two");
c.Add("three");
c.Add("four");
c.Add("hi");
c.Add("hello");
c.Add("I");
c.Add("A");
c.Add("B");
c.Add("C");
c.Add("D");
c.Add("amer");
// etc...
var gb = new GrammarBuilder(c);
var g = new Grammar(gb);
rec.LoadGrammar(g);
rec.Enabled = true;
}
void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
label1.Text = e.Result.Text;
}
}
请告诉我为什么会出现此异常