我需要编写一个使用语音识别引擎的应用程序,应用程序的目的是控制 PC(键盘和鼠标),当用户说“打开我的电脑”来打开我的电脑,或者说任何话来执行那个动作时,我已经尝试了很多时间但停留在两者之间,
我的代码是
{
SpeechRecognizer recognizer = new SpeechRecognizer();
recognizer.Enabled = true;
Choices folderPath= new Choices();
folderPath.Add(new string[] { "My Computer", "My Documents", "my docs", "Sumeet", "gehi"});
GrammarBuilder gb = new GrammarBuilder(folderPath);
Grammar gramer = new Grammar(gb);
recognizer.LoadGrammar(gramer);
gramerSpeechRecognized+=new EventHandler<SpeechRecognizedEventArgs (gramer_SpeechRecognized);
}
void gramer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text == "computer" || e.Result.Text=="my computer")
{
string myComputerPath = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
System.Diagnostics.Process.Start("explorer", myComputerPath);
//OR
//System.Diagnostics.Process.Start("explorer", "::{20d04fe0-3aea-1069-a2d8-08002b30309d}");
}
else
{
// give output what user have said
textBox1.Text = e.Result.Text;
}
}
需要帮忙!!!怎么办或我的代码中有任何错误???