Example #1
0
        private void Stop_Click(object sender, RoutedEventArgs e)
        {
            //using (SpeechSynthesizer synth = new SpeechSynthesizer())
            //{

            //    // Configure the audio output.
            //    synth.SetOutputToDefaultAudioDevice();

            //    // Create a PromptBuilder object and define the data types for some of the added strings.
            //    PromptBuilder sayAs = new PromptBuilder();
            //    sayAs.AppendText("Your");
            //    sayAs.AppendTextWithHint("1st", SayAs.NumberOrdinal);
            //    sayAs.AppendText("request was for");
            //    sayAs.AppendTextWithHint("1", SayAs.NumberCardinal);
            //    sayAs.AppendText("room, on");
            //    sayAs.AppendTextWithHint("10/19/2012,", SayAs.MonthDayYear);
            //    sayAs.AppendText("with early arrival at");
            //    sayAs.AppendTextWithHint("12:35pm", SayAs.Time12);

            //    // Speak the contents of the SSML prompt.
            //    synth.Speak(sayAs);
            //}

            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);

                RecognitionResult result;

                // This EmulateRecognize call matches the grammar and returns a
                // recognition result.
                result = recognizer.EmulateRecognize("testing testing");
                if (result != null)
                {
                    TextInFile.Text = result.Text;
                }

                // This EmulateRecognize call does not match the grammar and
                // returns null.
                result = recognizer.EmulateRecognize("testing one two three");
                if (result != null)
                {
                    TextInFile.Text += result.Text;
                }
            }
        }
Example #2
0
        private void PerformSerenadeCommand(SpeechRecognizer speechRecogniser)
        {
            Process.Start(@"C:\Users\MPhil\AppData\Local\Programs\Serenade\Serenade.exe");
            speechRecogniser.EmulateRecognize("minimise speech recognition");
            ToggleSpeechRecognitionListeningMode(inputSimulator);
            List <string> keys = new List <string>()
            {
                "^% "
            };

            SendKeysCustom(null, null, keys, currentProcess.ProcessName);
        }
Example #3
0
 private void RunVisualStudioCommand(SpeechRecognizer speechRecogniser)
 {
     if (currentProcess.ProcessName == "devenv")
     {
         List <string> keys = new List <string>()
         {
             "%v"
         };
         SendKeysCustom(null, null, keys, currentProcess.ProcessName);
         ToggleSpeechRecognitionListeningMode(inputSimulator);
         Thread.Sleep(2000);
         ToggleSpeechRecognitionListeningMode(inputSimulator);
     }
     else
     {
         speechRecogniser.EmulateRecognize("Switch to Visual Studio");
     }
 }
        [OuterLoop] // Pops UI
        public static void SpeechRecognizer()
        {
            if (Thread.CurrentThread.CurrentCulture.ToString() != "en-US")
            {
                return;
            }

            // Sometimes this lingers, causing subsequent tests to fail
            foreach (Process p in Process.GetProcessesByName("sapisvr.exe"))
            {
                p.Kill();
            }

            using (SpeechRecognizer recognizer = new SpeechRecognizer()) // Pops Windows UI that can be ignored but isn't dismissed by the test
            {
                Grammar testGrammar = new Grammar(new GrammarBuilder("test"));
                testGrammar.Name = "Test Grammar";
                recognizer.LoadGrammar(testGrammar);

                var list = new List <string>();

                recognizer.SpeechRecognized          += (object sender, SpeechRecognizedEventArgs e) => list.Add("SpeechRecognized");
                recognizer.SpeechDetected            += (object sender, SpeechDetectedEventArgs e) => list.Add("SpeechDetected");
                recognizer.SpeechHypothesized        += (object sender, SpeechHypothesizedEventArgs e) => list.Add("SpeechHypothesized");
                recognizer.SpeechRecognitionRejected += (object sender, SpeechRecognitionRejectedEventArgs e) => list.Add("SpeechRecognitionRejected");

                recognizer.EmulateRecognizeCompleted += (object sender, EmulateRecognizeCompletedEventArgs e) =>
                {
                    Assert.Equal(EncodingFormat.Pcm, recognizer.AudioFormat.EncodingFormat);
                    Assert.Equal(new TimeSpan(0, 0, 0), recognizer.AudioPosition);
                    Assert.Equal(AudioState.Stopped, recognizer.AudioState);
                    Assert.Equal(RecognizerState.Stopped, recognizer.State);
                    list.Add("EmulateRecognizeCompleted");
                    Assert.Equal(2, list.Count);
                };

                RecognitionResult result = recognizer.EmulateRecognize("test");
                Assert.NotNull(result);
            }
        }
Example #5
0
 /// <summary>
 /// Emulates input of a phrase to the shared speech recognizer, using text instead
 /// of audio for synchronous speech recognition.
 /// </summary>
 /// <param name="inputText">The input for the recognition operation.</param>
 /// <returns>The recognition result for the recognition operation, or null, if the operation
 /// is not successful or Windows Speech Recognition is in the Sleeping state.</returns>
 public RecognitionResult Recognize(string inputText)
 {
     return(_recon.EmulateRecognize(inputText));
 }