Exemplo n.º 1
0
        private void button2_Click(object sender, RibbonControlEventArgs e)
        {
            talking = !talking;
            string          text;
            TextSynthesizer speaker  = new TextSynthesizer();
            SpeechCommand   listener = new SpeechCommand();

            if (talking)
            {
                button2.Label = "Talking";
            }
            else
            {
                button2.Label = "Silence";
            }
            button2.PerformDynamicLayout();
            if (talking)
            {
                int rec = listener.StartRecognition();
                if (rec > 0)
                {
                    switch (rec)
                    {
                    case 2:
                        counter++;
                        text = Globals.ThisAddIn.GetNextNumber(counter);
                        speaker.SpeakWord(text);

                        break;

                    case 8:
                        counter--;
                        text = Globals.ThisAddIn.GetNextNumber(counter);
                        speaker.SpeakWord(text);

                        break;

                    case 5:
                        text = Globals.ThisAddIn.GetCurrentCell();
                        speaker.SpeakWord(text);

                        break;

                    default:
                        break;
                    }
                    rec = 0;
                }
            }
            else
            {
                listener.CancelRecognition();
            }
        }
Exemplo n.º 2
0
 public SpeechCommand()
 {
     listener = this;
     recognizer.SpeechRecognized          += new EventHandler <SpeechRecognizedEventArgs>(SpeechRecognizedHandler);
     recognizer.EmulateRecognizeCompleted += new EventHandler <EmulateRecognizeCompletedEventArgs>(EmulateRecognizeCompletedHandler);
     recognizer.SpeechDetected            += new EventHandler <SpeechDetectedEventArgs>(SpeechDetectedHandler);
     completed = false;
     recognizer.InitialSilenceTimeout      = TimeSpan.FromSeconds(3);
     recognizer.BabbleTimeout              = TimeSpan.FromSeconds(2);
     recognizer.EndSilenceTimeout          = TimeSpan.FromSeconds(1);
     recognizer.EndSilenceTimeoutAmbiguous = TimeSpan.FromSeconds(1.5);
     LoadGrammarRecognizer();
 }