Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,060 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,595 people online right now. Registration is fast and FREE... Join Now!




controlling the xp desktop with speech

 
Reply to this topicStart new topic

controlling the xp desktop with speech

narendra28
10 Apr, 2008 - 07:28 AM
Post #1

New D.I.C Head
*

Joined: 30 Mar, 2008
Posts: 4

hello sir,
i have acheived speech recognition in system.speech which but i am facing problem in implement the recognized command i.e i have speech recognition module i was not able to pass the recognized word to switch case.Can any one help me.
this is the code
//code
CODE

using System;
using System.Speech;
using System.Speech.Recognition;
using System.Threading;
using System.Diagnostics;
using System.Globalization;
namespace SpeechTest
{
    class Program
    {
        static void Main(string[] args)
        {
            EnumerateEngines();
            args = CheckArguments(args);

            CommandListener listener = new CommandListener();
            listener.SetCommands(args);
            listener.Run();
        }

        private static string[] CheckArguments(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Setting up default words. Enter your own words via command line arguments");
                args = new string[] { "notepad", "shutdown", "restart", "outlook" };
            }

            Console.Write("Now listening for...");
            foreach (string word in args)
            {
                Console.Write(String.Format("'{0}', ", word));
            }
            Console.WriteLine("\r\n(Press a key to stop listening)");
            return args;
        }

        private static void EnumerateEngines()
        {
            Console.WriteLine("The following engines are available");
            foreach (RecognizerInfo config in
SpeechRecognitionEngine.InstalledRecognizers())
            {
                Console.WriteLine(config.Name + " " +
config.Description);
            }
        }
    }

    class CommandListener
    {
        SpeechRecognitionEngine speechRecogniser;

        public CommandListener()
        {
            speechRecogniser = new SpeechRecognitionEngine();
            speechRecogniser.SetInputToDefaultAudioDevice();

            speechRecogniser.SpeechDetected += new
EventHandler<SpeechDetectedEventArgs>(speechRecogniser_SpeechDetected);
            speechRecogniser.SpeechHypothesized += new
EventHandler<SpeechHypothesizedEventArgs>(speechRecogniser_SpeechHypothesized);
            speechRecogniser.SpeechRecognitionRejected += new
EventHandler<SpeechRecognitionRejectedEventArgs>(speechRecogniser_SpeechRecognitionRejected);
            speechRecogniser.SpeechRecognized += new
EventHandler<SpeechRecognizedEventArgs>(speechRecogniser_SpeechRecognized);
            speechRecogniser.AudioStateChanged += new
EventHandler<AudioStateChangedEventArgs>(speechRecogniser_AudioStateChanged);
            speechRecogniser.AudioSignalProblemOccurred += new
EventHandler<AudioSignalProblemOccurredEventArgs>(speechRecogniser_AudioSignalProblemOccurred);

            
        }

        #region Event Handlers
        void speechRecogniser_AudioSignalProblemOccurred(object
sender, AudioSignalProblemOccurredEventArgs e)
        {
            NotifyEvent("Audio problem {0}",
e.AudioSignalProblem.ToString("G"));
        }

        void speechRecogniser_AudioStateChanged(object sender,
AudioStateChangedEventArgs e)
        {
            NotifyEvent("Audio state now {0}",
e.AudioState.ToString("G"));
        }

        void speechRecogniser_SpeechRecognized(object sender,
SpeechRecognizedEventArgs e)
        {
            NotifyEvent("Recognized '{0}' at {1} seconds",
e.Result.Text, e.Result.Audio.AudioPosition);
        }

        void speechRecogniser_SpeechRecognitionRejected(object sender,
SpeechRecognitionRejectedEventArgs e)
        {
            NotifyEvent("RecognitionRejected '{0}' at {1} seconds",
e.Result.Text, e.Result.Audio.AudioPosition);
        }

        void speechRecogniser_SpeechHypothesized(object sender,
SpeechHypothesizedEventArgs e)
        {

            NotifyEvent("Hypothesized '{0}' at seconds",
e.Result.Text);
        }

        void speechRecogniser_SpeechDetected(object sender,
SpeechDetectedEventArgs e)
        {
            NotifyEvent("Detected speech at {0} seconds",
e.AudioPosition.TotalSeconds);
        }
        #endregion

        public void SetCommands(string[] commands)
        {
            GrammarBuilder grammarBuilder = new GrammarBuilder();

            grammarBuilder.Culture =
speechRecogniser.RecognizerInfo.Culture;
            grammarBuilder.Append(new Choices(commands));
            Grammar grammar = new Grammar(grammarBuilder);

            speechRecogniser.UnloadAllGrammars();
            speechRecogniser.LoadGrammar(grammar);

            speechRecogniser.RecognizeAsync(RecognizeMode.Multiple);
        }

        public void Run()
        {
            while (!Console.KeyAvailable)
            {
                Thread.Sleep(100);
            }

            speechRecogniser.Dispose();
        }

        private static void NotifyEvent(string format, params object[] args)
        {
            Console.WriteLine(string.Format(format, args));
        }
    }
}


//code

this is efficiently working code for [font=Comic Sans Ms] speech recognition
but i had tough time passing the recognized word to switch case
can anyone help..
thanq
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 06:27PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month