Ejemplo n.º 1
0
 //fala nenhum mal
 public static void WhatTimeIS()
 {
     _retorno = DateTime.Now.ToShortTimeString();
     SPEAKER.Speak(_retorno);
 }
 private void Form1_Load(object sender, EventArgs e)
 {
     LoadSpeech();
     SPEAKER.Speak("Estou pronta");
 }
 private void button1_Click(object sender, EventArgs e)
 {
     SPEAKER.SetVoice(comboBox1.SelectedItem.ToString());
     SPEAKER.Speak("a voz foi alterada", "feito", "como quizer");
 }
        private void LoadSpeech()
        {
            try
            {
                engine = new SpeechRecognitionEngine(); // instancia
                engine.SetInputToDefaultAudioDevice();  // microfone
                                                        // string[] words = { "olá", "boa noite" };
                                                        // Operações
                Choices c_numero = new Choices();
                for (int i = 0; i <= 100; i++)
                {
                    c_numero.Add(i.ToString());
                }


                // video 03
                Choices c_commandsOfSystem = new Choices();
                c_commandsOfSystem.Add(GrammarRules.WhatTimeIS.ToArray());
                c_commandsOfSystem.Add(GrammarRules.WhatDateIS.ToArray());
                // comando pare de ouvir e o comando pra voltar a ouvir ->> shmyt
                c_commandsOfSystem.Add(GrammarRules.ShmytStopListening.ToArray());
                c_commandsOfSystem.Add(GrammarRules.ShmytStartListening.ToArray());
                c_commandsOfSystem.Add(GrammarRules.MinimizeWindow.ToArray());
                c_commandsOfSystem.Add(GrammarRules.MaximizaWindow.ToArray());
                c_commandsOfSystem.Add(GrammarRules.NormalizaWindow.ToArray());
                c_commandsOfSystem.Add(GrammarRules.ChangeVoice.ToArray());
                c_commandsOfSystem.Add(GrammarRules.OpenProgram.ToArray());
                c_commandsOfSystem.Add(GrammarRules.MediaPlayComands.ToArray());

                GrammarBuilder gb_comandOfSystem = new GrammarBuilder();// 4:22
                gb_comandOfSystem.Append(c_commandsOfSystem);

                Grammar g_comandsOfSystem = new Grammar(gb_comandOfSystem);
                g_comandsOfSystem.Name = "sys";

                engine.LoadGrammar(g_comandsOfSystem);//carrega gramatica na memoria

                // gramabuilder numeros
                GrammarBuilder gb_number = new GrammarBuilder();
                gb_number.Append(c_numero);
                gb_number.Append(new Choices("mais", "menos", "vezes", "por"));
                gb_number.Append(c_numero);

                Grammar g_numero = new Grammar(gb_number);
                g_numero.Name = "calc";
                engine.LoadGrammar(g_numero);
                // carregar gramatica substituido por choise
                // engine.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(words))));
                // Chamar o evento do reconhecimento comentado pelo video 03

                #region SpeechRecognition Events
                engine.SpeechRecognized += new EventHandler <SpeechRecognizedEventArgs>(rec);
                //barra de progresso
                engine.AudioLevelUpdated         += new EventHandler <AudioLevelUpdatedEventArgs>(audioLevel);
                engine.SpeechRecognitionRejected += new EventHandler <SpeechRecognitionRejectedEventArgs>(rej);
                //engine.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(rej);
                #endregion

                #region SpeechRecognition Events
                synthesizer.SpeakStarted  += new EventHandler <SpeakStartedEventArgs>(speakStarted);
                synthesizer.SpeakProgress += new EventHandler <SpeakProgressEventArgs>(speakProgress);
                #endregion

                // inicia o reconhecimento
                engine.RecognizeAsync(RecognizeMode.Multiple);

                SPEAKER.Speak("estou carregando as configurações");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ocorreu erro no LoadSpeech() " + ex.Message);
            }
        }