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("computer")); builder.AppendWildcard(); builder.Append(new Choices("blue", "green", "red")); Recognizer.LoadGrammar(new Grammar(builder)); GrammarBuilder builder2 = new GrammarBuilder(); builder2.Append("activate"); builder2.Append(new Choices("viewscreen", "emergency medical hologram")); Recognizer.LoadGrammar(new Grammar(builder2)); //Recognizer.LoadGrammar(new DictationGrammar()); } } }