Example #1
0
        static void Main(string[] args)
        {
            var keyphrasesFile = "keyphrases.txt";

            if (args.Length != 0)
            {
                keyphrasesFile = args[0];
            }

            RecognizerInfo info = null;

            foreach (var ri in SpeechRecognitionEngine.InstalledRecognizers())
            {
                if (ri.Culture.TwoLetterISOLanguageName.Equals("en"))
                {
                    info = ri;
                    break;
                }
            }
            if (info == null)
            {
                return;
            }

            using (_recognizer = new SpeechRecognitionEngine(info))
            {
                var keyphrases = new Choices(getChoices(keyphrasesFile));


                var gb = new GrammarBuilder(keyphrases)
                {
                    Culture = info.Culture
                };

                // Create the Grammar instance.
                var g = new Grammar(gb)
                {
                    Name = "Keyphrases"
                };

                _recognizer.RequestRecognizerUpdate();
                _recognizer.LoadGrammar(g);
                _recognizer.SpeechRecognized          += recognizer_SpeechRecognized;
                _recognizer.SpeechRecognitionRejected += recognizer_SpeechNotRecognized;
                _recognizer.SetInputToDefaultAudioDevice();
                _recognizer.RecognizeAsync(RecognizeMode.Multiple);
                while (true)
                {
                    Console.ReadLine();
                }
            }
        }
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();
            
        }