namespace mypro { public partial class MainWindow : Window { SpeechRecognitionEngine en = new SpeechRecognitionEngine(); public MainWindow() { InitializeComponent(); en.SetInputToDefaultAudioDevice(); Choices ch = new Choices("Hello","hey"); Grammar h = new Grammar(ch.ToGrammarBuilder()); h.Name = "ha"; en.LoadGrammarAsync(h); en.RecognizeAsync(RecognizeMode.Multiple); en.SpeechRecognized += new EventHandler<Speech Recognized EventArgs>(en_SpeechRecognized) } public void en_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { if (e.Result.Grammar.Name == "ha") { switch (e.Result.Text) { case "Hello": Say("hi, may i know your name?"); break; case "hey": Say("hi, may i know your name?"); break; } } } public void Say(string input) { var s = new SpeechSynthesizer(); var sa = new Prompt(input); s.Speak(sa); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)