Speech Recognition using Interop.SpeechLib.dll wit..

Unknown | 7:56 PM |




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.Drawing.Drawing2D;
using System.Runtime.InteropServices;
using System.Threading;
using SpeechLib;
using MediaPlayer;
using WMPLib;
using System.Diagnostics;



 private SpeechLib.SpSharedRecoContext objRecoContext;
        private SpeechLib.ISpeechRecoGrammar grammar = null;
        private SpeechLib.ISpeechGrammarRule menuRule = null;
        SpVoice spo = new SpVoice();
        bool saved = false;
        bool enable_speach = false;
        bool speach_diabletime_out = false;



     private void Form1_Load(object sender, EventArgs e)
        {
         
            try
            {
                objRecoContext = new SpSharedRecoContext();
           
                spo.Speak("Welcome", SpeechVoiceSpeakFlags.SVSFlagsAsync);
                spo.WaitUntilDone(1000);
           
                enable_speach = false;
                objRecoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(Reco_Event);
           
            }
            catch (Exception exp)
            {

                MessageBox.Show("Install speech Before Statring Akku", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                Application.Exit();
            }

       
           
   
        }




 string result = "";

        private void Reco_Event(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result)
        {


            result = Result.PhraseInfo.GetText(0, -1, true);
       
            if (result == Properties.Settings.Default.start)
            {
             
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                //p.StartInfo.FileName = @"C:\Program Files\Mozilla Firefox\firefox.exe";
                p.StartInfo.FileName = @"C:\Program Files\Internet Explorer\IEXPLORE.EXE";
                p.Start();
                p.StartInfo.FileName = @"C:\\Windows";
                p.Start();
                //System.Diagnostics.Process("C:\\Windows");

            }
            if (result == Properties.Settings.Default.explorer)
            {
             
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = @"C:\Program Files\Internet Explorer\IEXPLORE.EXE";
                p.Start();

             
            }
            if (result == Properties.Settings.Default.player)
            {
                result = "";
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = @"C:\Program Files\Windows Media Player\wmplayer.exe" ;
                p.Start();
                System.Diagnostics.Process.Start(@"D:\virtulamouse\virtulamouse\01 - Kya Mujhe Pyaar Hai (Kay Kay).mp3");

            }
            if (result == Properties.Settings.Default.notepad)
            {
                result = "";
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = @"notepad.exe";
                p.Start();
                //System.Diagnostics.Process.Start(@"%SystemRoot%\system32\notepad.exe");

            }
            if (result == Properties.Settings.Default.keyboard)
            {
                result = "";
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = @"osk.exe";
                p.Start();
                //System.Diagnostics.Process.Start(@"%SystemRoot%\system32\notepad.exe");

            }
            serialPort1.Close();

            //System.Windows.Forms.SendKeys.SendWait("This text was entered ");
            //Thread.Sleep(1000);
            //System.Windows.Forms.SendKeys.SendWait("{TAB}");
            //Thread.Sleep(1000);
            //System.Windows.Forms.SendKeys.SendWait("using the System.Windows.");
            //Thread.Sleep(1000);

        }

        private void btnenablespeech_Click(object sender, EventArgs e)
        {
            try
            {
                grammar = objRecoContext.CreateGrammar(0);
                menuRule = grammar.Rules.Add("MenuCommands", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1);
                object PropValue = "";

            menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.start, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.start, 2, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.explorer, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.explorer, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.player, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.player, 4, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.notepad, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.notepad, 5, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.keyboard, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.keyboard, 5, ref PropValue, 1.0F);
         
            //menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.start, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.start, 2, ref PropValue, 1.0F);
            //menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.explorer, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.explorer, 3, ref PropValue, 1.0F);
            //menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.player, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.player, 4, ref PropValue, 1.0F);
            //menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.notepad, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.notepad, 5, ref PropValue, 1.0F);
            //menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.keyboard, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.keyboard, 5, ref PropValue, 1.0F);
                grammar.Rules.Commit();
                grammar.CmdSetRuleState("MenuCommands", SpeechRuleState.SGDSActive);
            }
            catch (Exception exp)
            {

                MessageBox.Show(exp.Message);
                if (serialPort1.IsOpen == true)
                {
                    serialPort1.Close();
                }
                return;
            }

            spo.Speak("start", SpeechVoiceSpeakFlags.SVSFlagsAsync);
            spo.WaitUntilDone(1000);
            if (button2.Text == "Enable Speech")
            {
                button2.Text = "Disable Speech";
            }
            else if (button2.Text == "Disable Speech")
            {
                objRecoContext.EndStream += new _ISpeechRecoContextEvents_EndStreamEventHandler(wavRecoContext_EndStream);
                button2.Text = "Enable Speech";
            }
        }

Category:

About http://dotnetvisual.blogspot.in/:
DOT NET TO ASP.NET is a web application framework marketed by Microsoft that programmers can use to build dynamic web sites, web applications and web services. It is part of Microsoft's .NET platform and is the successor to Microsoft's Active Server Pages (ASP) technology. ASP.NET is built on the Common Language Runtime, allowing programmers to write ASP.NET code using any Microsoft .NET language. create an application very easily ....