Instructables

Step 4:

Picture of
Capture6.PNG
Capture3.PNG
Capture2.PNG
As we open a Visual C# IDE, i.e. Visual Studio 2010, we create an new project in Visual C#, using windows form.

Using the properties panel and the toolbox we make the form as we like it, and we just put a button that will enable monitoring and some labels guiding the user to control the program.

To make the communication PC-Arduino possible we must drag&drop from the toolbox, a serialPort object and set the correct port from its properties.

Also we must add the reference of speech recognition to our project:
Project > Add Reference. Add there "System.Speech".

Ending with the UI designing, it's time to get things working!
Double click the button we made and put the following code in the event:

private void button1_Click(object sender, EventArgs e)
        {
            rec = new SpeechRecognitionEngine();
            rec.SetInputToDefaultAudioDevice();
            // Specify the exact words that the engine will try to recognize.
            Choices choices = new Choices("help", "abort");
            // Create and load a Grammar using the Choices above.
            GrammarBuilder grBuilder = new GrammarBuilder(choices);
            Grammar grammar = new Grammar(grBuilder);
            rec.LoadGrammar(grammar);
          
            // Create the event handler
          
            if (button1.Text == "Disable" )
            {
                button1.Text = "Enable";
                label5.Text = "Unsecured";
            }
            else
            {
                rec.SpeechRecognized += newEventHandler<SpeechRecognizedEventArgs>(rec_SpeechRecognized);
                rec.RecognizeAsync(RecognizeMode.Multiple);
                button1.Text = "Disable";
                label5.Text = "Secured";
            }


void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {       
            foreach (RecognizedWordUnit word in e.Result.Words)
            {
                switch (word.Text)
                {
                    case "help":
                        if (button1.Text == "Disable")
                        {
                            label6.Text = "help";
                            USB.Write("1");
                        }
                        break;
                    case "abort":
                        if (button1.Text == "Disable")
                        {
                            label6.Text = "abort";
                            USB.Write("0");
                        }
                        break;
                    default:
                        USB.Write("1");
                        break;
                }
            }
        }