示例#1
0
        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);
        }
示例#2
0
        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);
        }