如何通过语音识别打开我的电脑

本文关键字:我的 电脑 何通过 语音识别 | 更新日期: 2023-09-27 18:27:42

我需要编写一个使用语音识别引擎的应用程序,应用程序的目的是控制PC(键盘和鼠标),当用户说"打开mycomputer"来打开我的计算机,或者说任何话来执行该操作时,我试了很多时间,但一直处于中间,
我的代码是

       {         
        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;
         }
    }

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

如何通过语音识别打开我的电脑

是的,我现在已经完成了这项工作,完美的

  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}");
       }

但如果你仍然能找到比这更好的答案,请在这里发表评论thanx家伙