C# Speech Recognition Program tutorial

This is a tutorial on how to make a speech recognition program in C#.
here is the code of the speech recognition program.

Create a new project is Visual Studio (select Windows Form Application).
First Add the references of System.Speech to your project.
Then properly understand this code and then copy it in your project or if you have understood it try to type it yourself.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;  // Adding the reference of Speech Recognition.
using System.Speech.Synthesis;      // Adding the reference of Speech Synthesizer.

namespace peech          //The word after 'namespace' means the name of your program.
{
    public partial class Form1 : Form
    {
       SpeechRecognitionEngine _reconize = new SpeechRecognitionEngine(); //Creating recognizer
       SpeechSynthesizer speaker = new SpeechSynthesizer(); //Creating synthesizer

        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            _reconize.SetInputToDefaultAudioDevice();
            _reconize.LoadGrammar(new Grammar(new GrammarBuilder(new Choices("hello", "goodbye))));
            _reconize.RecognizeAsync(RecognizeMode.Multiple);
            _reconize.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_reconize_SpeechRecognized);
        }

        void _reconize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            string speech = e.Result.Text;
            switch (speech)
            {
                case"hello":
                    speaker.Speak("hello");

                    break;

                case"goodbye":
                    speaker.Speak("Will meet you later!");
                    Application.Exit();
                    break;
    }
  }

}


Important notes: Speech Synthesizer is a built-in function in Visual Studio 2010. It converts text to speech. That means the program will speak out whatever in typed.

If there are any error in your program or it is not working then please contact me on my email. I will solve the problem.

If you have not watched a video on how to make a speech recoginition program then click here to watch