0

I have need to write an application which uses a speech recognition engine, the purpose off app is to control PC(keyboard and mouse), when user say "open mycomputer" to open my computer, or say any thing to perform that action, i have tried a lots of time but stuck in between,
my code is

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

need helP!!! what to do or any mistakes in my code???

Sumit
  • 1,022
  • 13
  • 19
  • What exactly does not work?? – bash.d Aug 15 '13 at 10:51
  • 2
    Place a breakpoint, and debug. Does the debugger reach to the gramer_SpeechRecognized function? What is e.Tesult.Text value? – sara Aug 15 '13 at 10:54
  • 1
    Also - convert the e.Result.Text to lower case before the compare. – sara Aug 15 '13 at 11:00
  • i have also tried that, my program did not compare if else condition – Sumit Aug 15 '13 at 19:18
  • @sara e.result.text have the string value, which we spoken, like i say my computer then e.result.text="my computer", and i want that if it compare the word/phrase then open my computer but didnt work – Sumit Aug 15 '13 at 19:22
  • So you're saying that e.result.text contains exactly "my computer"? Do you even get inside the if statement? It is not clear to me what the exact problem is. – Bob Claerhout Aug 16 '13 at 16:29

1 Answers1

0

yes I have done this now work prefect

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

but if you still find answer better than this so plz comment here thanx guys

AK856
  • 33
  • 5
Sumit
  • 1,022
  • 13
  • 19