void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { Console.WriteLine("Speech recognized: " + e.Result.Text); var response = Cleverbot.getChatResponse(session, e.Result.Text); Console.WriteLine("Cleverbot: " + response); synth.Speak(response); }
public SpeechHandler() { session = Cleverbot.createSession(); recognizer = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")); synth = new SpeechSynthesizer(); recognizer.SetInputToDefaultAudioDevice(); synth.SetOutputToDefaultAudioDevice(); DictationGrammar defaultDictationGrammar = new DictationGrammar(); defaultDictationGrammar.Name = "default dictation"; defaultDictationGrammar.Enabled = true; recognizer.LoadGrammar(defaultDictationGrammar); recognizer.SpeechRecognized += new EventHandler <SpeechRecognizedEventArgs>(sre_SpeechRecognized); }
static void Main(string[] args) { SpeechHandler speech = new SpeechHandler(); Thread oThread = new Thread(new ThreadStart(speech.Begin_Listening)); oThread.Start(); while (!oThread.IsAlive) { ; } var session = Cleverbot.createSession(); string message; Console.WriteLine("Welcome to CleverBot.Net."); do { Console.WriteLine("Try saying something to Cleverbot. Type \"exit\" to quit the program"); message = Console.ReadLine(); } while (message.ToLower().Trim() != "exit"); //exit the test thread oThread.Abort(); Environment.Exit(0); }