0

我需要编写一个使用语音识别引擎的应用程序,应用程序的目的是控制 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;
         }
    }

需要帮忙!!!怎么办或我的代码中有任何错误???

4

1 回答 1

0

是的,我已经做到了,现在可以工作了

  string resultText = e.Result.Text.ToLower();
      if (resultText == "computer")
        {
          string myComputerPath = 
            Environment.GetFolderPath(Environment.SpecialFolder.MyComputer); 
          System.Diagnostics.Process.Start("explorer", myComputerPath);
        //System.Diagnostics.Process.Start("explorer", "::{20d04fe0-3aea-1069-a2d8-08002b30309d}");
       }

但是,如果您仍然找到比这更好的答案,请在此处发表评论,谢谢

于 2013-08-16T20:01:20.477 回答