Wednesday, July 15, 2015

Speech Recognization

  Hi in this blog I am going to explain Microsoft Speech Recognization with Simple Demo Application.To  use Microsoft speech recognization first you must add reference to System.speech assembly(.dll) in to you Project


Lets See how to do that 

Step 1: Create a windows  form Application and design form as shown in the fig.
Step 2: Add the System.Speech Reference(Right Click References->Add References and the select System.speech)

Add the following code to the Form_load Event

       private void Form1_Load(object sender, EventArgs e)
        {
            IntializeRecognizationEngine();

        }

        private void IntializeRecognizationEngine()
        {
            try
            {
                recognizer = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("EN-US"));
                recognizer.SetInputToDefaultAudioDevice();
                recognizer.LoadGrammar(createGrammer());
                recognizer.RecognizeAsync(RecognizeMode.Multiple);
                recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_speechRecognized);
            }
            catch(Exception ex)
            {
                MessageBox.Show("Exception"+ex.ToString());
            }
        }

        private Grammar createGrammer()
        {
            Choices option = new Choices();
            option.Add(new string[]{"Notepad","Wordpad","Calculator","Presentation"});
            GrammarBuilder gb = new GrammarBuilder();
            gb.Append(option);
            Grammar g = new Grammar(gb);
            return g;
        }

 void sre_speechRecognized(Object sender, SpeechRecognizedEventArgs e)
        {
            textBox1.Text = string.Empty;
            textBox1.Text = e.Result.Text;

        }

Output:
   


Download the source code from here

Click here for my previous blog

Happy Coding.




No comments:

Post a Comment