You are on page 1of 2

First of all sorry guys if the code that I gave you didn't work. This one I used in my program.

using System.Speech.Recognition; using System.Speech.Synthesis; using System.IO; SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine(); SpeechSynthesizer ALEXAI = new SpeechSynthesizer(); InitializeComponent(); Choices searching = new Choices(System.IO.File.ReadAllLines(@"C:\Alex SR program\Alex.txt")); // here goes the location of your file GrammarBuilder lookingService = new GrammarBuilder(); lookingService.Append(searching); // Create a Grammar object from the GrammarBuilder and load it to the recognizer. Grammar googleGrammar = new Grammar(lookingService); ; _recognizer.RequestRecognizerUpdate(); _recognizer.LoadGrammar(googleGrammar); // Add a handler for the speech recognized event. _recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_recognizer_Speech Recognized); // Configure the input to the speech recognizer. _recognizer.SetInputToDefaultAudioDevice(); // Start asynchronous, continuous speech recognition.

_recognizer.RecognizeAsync(RecognizeMode.Multiple);

void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { string speech = e.Result.Text; if (speech == "Hello") { ALEXAI.Speak("Hello sir!"); } else if (speech == "Goodbye") { ALEXAI.Speak("Until next time"); Application.Exit(); } }

You know where what goes where. Like I said I used this code in my program. Hope it works for you guys. Stay awesome :D and everything is awesome! everything is awesome!

You might also like