private void StartSpeechRecognition()
        {
            if (_isActive && !_isRecognizing)
            {
                _isRecognizing = true;
                _waitForLoadGrammarCompleted.WaitOne();
                _speechRecognitionConnector.AttachFlow(_audioVideoFlow);
                _speechRecognitionStream = _speechRecognitionConnector.Start();
                _speechRecognitionEngine.SetInputToAudioStream(_speechRecognitionStream, speechAudioFormatInfo);
                _speechRecognitionEngine.RecognizeAsync(RecognizeMode.Multiple);

                #if EMULATE_SPEECH
                _speechRecognitionEngine.EmulateRecognizeAsync("one");
                _speechRecognitionEngine.EmulateRecognizeAsync("two");
                _speechRecognitionEngine.EmulateRecognizeAsync("three");
                _speechRecognitionEngine.EmulateRecognizeAsync("four");
                #endif // EMULATE_SPEECH
            }
        }
Example #2
0
        public Jarvis()
        {
            modules = new LinkedList<IJModule>();
            /*************** IJModule Instatiation Stuff ****************/
            modules.AddLast(new MusicControl(preferences.mediaplayerprocess, preferences.initialvolume, preferences.volumeincrements));
            if (preferences.usegooglevoice)
                modules.AddLast(new GoogleVoice(preferences.googleemail, preferences.googlepassword, preferences.googleaddressbook));
            if (preferences.facebookrssfeed != null)
                modules.AddLast(new Facebook(preferences.facebookrssfeed));
            if (preferences.usegooglecalendar)
                modules.AddLast(new GoogleCalendar(preferences.googleemail, preferences.googlepassword, preferences.googlecalendaralerttime));
            alertThread = new Thread(new ThreadStart(alertFunction));
            alertThread.Name = "Alert Thread";
            alertThread.Start();

            /****************Get Grammar From Modules*********************/
            var grammars = new LinkedList<Microsoft.Speech.Recognition.Grammar>();
            foreach (IJModule module in modules)
            {
                if(module.getGrammarFile() != null)
                {
                    var gb = new Microsoft.Speech.Recognition.GrammarBuilder();
                    gb.AppendRuleReference("file://" + System.Environment.CurrentDirectory + "\\" + module.getGrammarFile());
                    Console.WriteLine("file://"+System.Environment.CurrentDirectory+"\\" + module.getGrammarFile());
                    grammars.AddLast(new Microsoft.Speech.Recognition.Grammar(gb));
                }
            }
            
            /************ Speech Recognition Stuff **********************/
            
            dictation = new System.Speech.Recognition.SpeechRecognitionEngine();
            dictation.SetInputToDefaultAudioDevice();
            dictation.LoadGrammar(new DictationGrammar());
            dictation.SpeechRecognized += SreSpeechRecognized;
            
            sensor = (from sensorToCheck in KinectSensor.KinectSensors where sensorToCheck.Status == KinectStatus.Connected select sensorToCheck).FirstOrDefault();

            if (sensor == null)
            {
                Console.WriteLine(
                        "No Kinect sensors are attached to this computer or none of the ones that are\n" +
                        "attached are \"Connected\".\n" +
                        "Press any key to continue.\n");

                Console.ReadKey(true);
                return;
            }

            sensor.Start();

            KinectAudioSource source = sensor.AudioSource;

            source.EchoCancellationMode = EchoCancellationMode.CancellationOnly; 
            source.AutomaticGainControlEnabled = false; 

            Microsoft.Speech.Recognition.RecognizerInfo ri = GetKinectRecognizer();
            Debug.WriteLine(ri.Id);
            if (ri == null)
            {
                Console.WriteLine("Could not find Kinect speech recognizer. Please refer to the sample requirements.");
                return;
            }

            int wait = 4;
            while (wait > 0)
            {
                Console.Write("Device will be ready for speech recognition in {0} second(s).\r", wait--);
                Thread.Sleep(1000);
            }
            //sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
            sre = new Microsoft.Speech.Recognition.SpeechRecognitionEngine(ri.Id);
            
                foreach(Microsoft.Speech.Recognition.Grammar g in grammars){
                    sre.LoadGrammar(g);
                }
                sre.SpeechRecognized += SreSpeechRecognized;

                using (Stream s = source.Start())
                {
                    sre.SetInputToAudioStream(
                        s, new Microsoft.Speech.AudioFormat.SpeechAudioFormatInfo(Microsoft.Speech.AudioFormat.EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                    Console.WriteLine("Recognizing speech. Say: 'red', 'green' or 'blue'. Press ENTER to stop");
                    sre.RecognizeAsync(Microsoft.Speech.Recognition.RecognizeMode.Multiple);




                Console.ReadLine();
                Console.WriteLine("Stopping recognizer ...");
                sre.RecognizeAsyncStop();

                }


                source.Stop();
                alertThread.Abort();
            
        }