Click here to Skip to main content
15,798,200 members
Please Sign up or sign in to vote.
3.50/5 (3 votes)
See more: , +
I'm working on a uni project to control your PC through voice, means when i say open my computer, then my-computer open, or control other functions,i have tried a lots of time but stuck in between code, my code gets voice input from user but doesn't compare
here is code:
      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);

      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);
      //System.Diagnostics.Process.Start("explorer", "::{20d04fe0-3aea-1069-a2d8-08002b30309d}");
         // give output what user have said
        textBox1.Text = e.Result.Text;

need your help developers...
is there any mistakes in my code or how to compare with speech
Updated 15-Aug-13 10:40am
Sergey Alexandrovich Kryukov 15-Aug-13 15:45pm    
There is no much code here? More is involved in the full solution. Anyway, do you have any problems with it?
Sumeet Kumar G 16-Aug-13 11:18am    
Yes, it doesn't compare
[no name] 15-Aug-13 15:46pm    
What exactly does "doesn't compare" mean? Does your event handler run? What are you getting in e.Result?
Sumeet Kumar G 16-Aug-13 10:15am    
the work of this code is when i say something through mic it will display in text-box & when i say computer or my computer it will open my computer, when i say my computer textbox display that i have said but cant open my computer folder, it did not compare with e.result.text

<pre lang="c#"> if (e.Result.Text == "computer" || e.Result.Text=="my computer")
System.Diagnostics.Process.Start("explorer", "::{20d04fe0-3aea-1069-a2d8-08002b30309d}");
} </pre>
this not work or i havent knowledge about it or how to compare sting input
[no name] 16-Aug-13 11:43am    
How would you expect someone to help you when you do not answer their questions?


Probably, "My Computer" is capitalized, so the input is "My Computer", which is NOT equal to "my computer"!
Try this:
void gramer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        string resultText = e.Result.Text.ToLower();
        if (resultText == "computer" || resultText =="my computer")

Hope this helps.
Share this answer
Sumeet Kumar G 16-Aug-13 16:11pm    
Thanx programFox it's works
Thomas Daniels 17-Aug-13 3:36am    
You're welcome!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900