Example #1
0
        public static void Run()
        {
            // Initialize an instance of the shared recognizer.
            using (SpeechRecognizer recognizer = new SpeechRecognizer())
            {

                // Create and load a sample grammar.
                Grammar testGrammar =
                  new Grammar(new GrammarBuilder("testing testing"));
                testGrammar.Name = "Test Grammar";
                recognizer.LoadGrammar(testGrammar);

                // Attach event handlers for recognition events.
                recognizer.SpeechRecognized +=
                  new EventHandler<SpeechRecognizedEventArgs>(
                    SpeechRecognizedHandler);
                recognizer.EmulateRecognizeCompleted +=
                  new EventHandler<EmulateRecognizeCompletedEventArgs>(
                    EmulateRecognizeCompletedHandler);

                completed = false;

                // Start asynchronous emulated recognition.
                // This matches the grammar and generates a SpeechRecognized event.
                recognizer.EmulateRecognizeAsync("testing testing");

                // Wait for the asynchronous operation to complete.
                while (!completed)
                {
                    Thread.Sleep(333);
                }

                completed = false;

                // Start asynchronous emulated recognition.
                // This does not match the grammar or generate a SpeechRecognized event.
                recognizer.EmulateRecognizeAsync("testing one two three");

                // Wait for the asynchronous operation to complete.
                while (!completed)
                {
                    Thread.Sleep(333);
                }
            }

            Console.WriteLine();
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Example #2
0
        static void Main(string[] args)
        {
            // Initialize an instance of the shared recognizer.
            using (SpeechRecognizer recognizer = new SpeechRecognizer())
            {
                // Create and load a sample grammar.

                /*Grammar testGrammar =  new Grammar(new GrammarBuilder("testing testing"), );
                 * testGrammar.Name = "Test Grammar";
                 * recognizer.LoadGrammar(testGrammar);*/

                // Attach event handlers for recognition events.
                recognizer.SpeechRecognized +=
                    new EventHandler <SpeechRecognizedEventArgs>(
                        SpeechRecognizedHandler);
                recognizer.EmulateRecognizeCompleted +=
                    new EventHandler <EmulateRecognizeCompletedEventArgs>(
                        EmulateRecognizeCompletedHandler);

                completed = false;

                // Start asynchronous emulated recognition.
                // This matches the grammar and generates a SpeechRecognized event.
                recognizer.EmulateRecognizeAsync("testing testing");

                // Wait for the asynchronous operation to complete.
                while (!completed)
                {
                    Thread.Sleep(333);
                }

                completed = false;

                // Start asynchronous emulated recognition.
                // This does not match the grammar or generate a SpeechRecognized event.
                recognizer.EmulateRecognizeAsync("testing one two three");

                // Wait for the asynchronous operation to complete.
                while (!completed)
                {
                    Thread.Sleep(333);
                }
            }

            Console.WriteLine();
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }