Random header image... Refresh for more!

And a better example…

Here’s an example of using System.Speech.Recognition to recognize the words “red”, “blue”, and “green”.

using System;
using System.Speech.Recognition;

namespace MathPirate.AlternativeInputDevices.SpeechCommandProcessor
{
    public class SpeechProcessor
    {
        protected SpeechRecognizer Recognizer { get; set; }

        public SpeechProcessor()
        {
            Recognizer = new SpeechRecognizer();

            Recognizer.SpeechRecognized += (sender, e) => Console.WriteLine(e.Result.Text);
            Recognizer.SpeechDetected += (sender, e) => Console.WriteLine("Detected: {0}", e.AudioPosition);
            Recognizer.SpeechHypothesized += (sender, e) => Console.WriteLine("Hypothesis: {0}", e.Result.Text);
            Recognizer.SpeechRecognitionRejected += (sender, e) => Console.WriteLine("Rejected: {0}", e.Result.Text);

            GrammarBuilder builder = new GrammarBuilder();
            builder.Append(new Choices("blue", "green", "red"));
            Recognizer.LoadGrammar(new Grammar(builder));          
        }
    }
}

No, seriously. That’s it. And most of it’s debug writelines that you don’t even need.

0 comments

There are no comments yet...

Kick things off by filling out the form below.

Leave a Comment