Voice Recognition Code with C#

one day you may wake up i should make an application that can listen to me well here is one of simple sample of  Voice Recognition .
By saying the names , face book , youtube , badoo it will open them in browser :
feel free to comment




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Diagnostics;

namespace Voice_Recognition
{
    public partial class Form1 : Form
    {
        SpeechRecognitionEngine srEngine = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));
        object fb ="facebok";
        public Form1()
        {
            InitializeComponent();
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            srEngine.RecognizeAsync(RecognizeMode.Multiple);
            btnStop.Enabled = true;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Choices ch = new Choices();
            ch.Add(new string[] {"hello","face book","you tube","badoo"});
            GrammarBuilder gb = new GrammarBuilder();
            gb.Append(ch);
            Grammar g = new Grammar(gb);
            srEngine.LoadGrammar(g);
            srEngine.SetInputToDefaultAudioDevice();
            srEngine.SpeechRecognized+=srEngine_SpeechRecognized;
            srEngine.Recognize();
        }

        private void srEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
          switch(e.Result.Text)
          {
              case "hello":
                  richTextBox1.Text = "hello";
                  break;

              case "face book":
                  Process.Start("https://www.facebook.com");
                  break;

              case "you tube":
                  Process.Start("https://www.youtube.com/?gl=AE");
                  break;


              case "badoo":
                  Process.Start("https://www.badoo.com");
                  break;

         
         
          }



           
         
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            srEngine.RecognizeAsyncStop();
            btnStop.Enabled = false;
        }
    }
}

Comments

Popular posts from this blog

Adding navigation to your web pages with one line of php code