public SoundDataProcessor(KeyboardInputProcessor keyboard)
        {
            ConfigureLogManager();
            keyboardProcessor = keyboard;
            kinectAudioResourse = new KinectAudioSource();
            kinectAudioResourse.FeatureMode = true;
            kinectAudioResourse.AutomaticGainControl = false; //Important to turn this off for speech recognition
            kinectAudioResourse.SystemMode = SystemMode.OptibeamArrayOnly; //No AEC for this sample

            ri = SpeechRecognitionEngine.InstalledRecognizers().Where(r => r.Id == recognizerId).FirstOrDefault();

            if (ri == null)
            {
                Trace.WriteLine("Could not find speech recognizer: {0}. Please refer to the sample requirements.", recognizerId);
                throw new System.InvalidOperationException("Could not find speech recognizer: {0}. Please refer to the sample requirements." + recognizerId);
            }

            sre = new SpeechRecognitionEngine(ri.Id);
            speechCommands = new Choices();

            speechCommands.Add("jump");
            speechCommands.Add("reload");
            speechCommands.Add("aim");
            speechCommands.Add("knife");
            speechCommands.Add("grenade");

            speechCommands.Add("menu");
            speechCommands.Add("pause");
            speechCommands.Add("select");
            speechCommands.Add("okay");
            speechCommands.Add("enter");
            speechCommands.Add("up");
            speechCommands.Add("down");
            speechCommands.Add("left");
            speechCommands.Add("right");

            gb = new GrammarBuilder();
            gb.Culture = ri.Culture;
            gb.Append(speechCommands);

            grammar = new Grammar(gb);
            sre.LoadGrammar(grammar);

            audioSourceStream = kinectAudioResourse.Start();
            sre.SetInputToAudioStream(audioSourceStream,
                                                  new SpeechAudioFormatInfo(
                                                      EncodingFormat.Pcm, 16000, 16, 1,
                                                      32000, 2, null));
            sre.RecognizeAsync(RecognizeMode.Multiple);
            handleRequests = new Semaphore(0, (int)SemaphoreConstants.MAX_CONCURRENT_REQUESTS);
            requestSoundData = new Semaphore((int)SemaphoreConstants.MAX_CONCURRENT_REQUESTS, (int)SemaphoreConstants.MAX_CONCURRENT_REQUESTS);

            dataQueue = new Queue<SoundData>();
            threadExit = false;

            soundProcessorThread = new Thread(SoundProcessorModule);
            soundProcessorThread.Name = "SoundProcessorThread";
            soundProcessorThread.SetApartmentState(ApartmentState.MTA);
            soundProcessorThread.Start();
        }
void BuildSpeechEngine(RecognizerInfo rec)
{
    _speechEngine = new SpeechRecognitionEngine(rec.Id);

    var choices = new Choices();
    choices.Add("venus");
    choices.Add("mars");
    choices.Add("earth");
    choices.Add("jupiter");
    choices.Add("sun");

    var gb = new GrammarBuilder { Culture = rec.Culture };
    gb.Append(choices);

    var g = new Grammar(gb);

    _speechEngine.LoadGrammar(g);
    //recognized a word or words that may be a component of multiple complete phrases in a grammar.
    _speechEngine.SpeechHypothesized += new EventHandler<SpeechHypothesizedEventArgs>(SpeechEngineSpeechHypothesized);
    //receives input that matches any of its loaded and enabled Grammar objects.
    _speechEngine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_speechEngineSpeechRecognized);
    //receives input that does not match any of its loaded and enabled Grammar objects.
    _speechEngine.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(_speechEngineSpeechRecognitionRejected);


    //C# threads are MTA by default and calling RecognizeAsync in the same thread will cause an COM exception.
    var t = new Thread(StartAudioStream);
    t.Start();
}
Example #3
0
        public ComponentControl()
        {
            this.AudioSource = new KinectAudioSource();

            this.AudioSource.FeatureMode = true;
            this.AudioSource.AutomaticGainControl = false;
            this.AudioSource.SystemMode = SystemMode.OptibeamArrayOnly;
            this.AudioSource.BeamChanged += new EventHandler<BeamChangedEventArgs>(AudioSource_BeamChanged);

            this.Recognizer = SpeechRecognitionEngine.InstalledRecognizers().Where(r => r.Id == RecognizerId).FirstOrDefault();

            if(this.Recognizer == null) {
                throw new Exception("Could not find Kinect speech recognizer");
            }

            this.Engine = new SpeechRecognitionEngine(Recognizer.Id);
            this.Engine.UnloadAllGrammars();

            this.LoadGrammer();

            this.AudioStream = this.AudioSource.Start();
            this.Engine.SetInputToAudioStream(this.AudioStream, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1,
                                                      32000, 2, null));

            this.Engine.SpeechHypothesized += new EventHandler<SpeechHypothesizedEventArgs>(Engine_SpeechHypothesized);

            this.Engine.RecognizeAsync(RecognizeMode.Multiple);
            Console.WriteLine("Speech recognition initialized");
        }
 public SpeechRecognizer()
 {
     this.recognizerInfo = GetKinectRecognizer();
     if (this.recognizerInfo != null)
     {
         this.speechRecognitionEngine = new SpeechRecognitionEngine(this.recognizerInfo.Id);
         this.speechRecognitionEngine.SpeechRecognized += this.SpeechRecognitionEngine_SpeechRecognized;
         this.speechRecognitionEngine.SpeechDetected += this.SpeechRecognitionEngine_SpeechDetected;
     }
 }
Example #5
0
        public KinectSpeechService(ISensorService<KinectSensor> sensorService)
        {
            _sensorService = sensorService;

            IReadOnlyList<AudioBeam> audioBeamList = _sensorService.Sensor.AudioSource.AudioBeams;
            System.IO.Stream audioStream = audioBeamList[0].OpenInputStream();

            // create the convert stream
            _convertStream = new KinectAudioStream(audioStream);

            _ri = TryGetKinectRecognizer();
        }
        public void InitializeSpeechRecognition(RecognizerInfo recognizer, ISpeechGrammar grammar)
        {
            RecognizerInfo ri = recognizer;
            if (ri == null)
            {
                MessageBox.Show(
                    @"There was a problem initializing Speech Recognition.
Ensure you have the Microsoft Speech SDK installed.",
                    "Failed to load Speech SDK",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
                return;
            }

            try
            {
                speechRecognizer = new SpeechRecognitionEngine(ri.Id);
            }
            catch
            {
                MessageBox.Show(
                    @"There was a problem initializing Speech Recognition.
Ensure you have the Microsoft Speech SDK installed and configured.",
                    "Failed to load Speech SDK",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
            }

            var phrases = new Choices();

            foreach(String word in grammar.GrammarWords())
            {
                phrases.Add(word);
            }

            var gb = new GrammarBuilder();
            //Specify the culture to match the recognizer in case we are running in a different culture.                                 
            gb.Culture = ri.Culture;
            gb.Append(phrases);

            // Create the actual Grammar instance, and then load it into the speech recognizer.
            var g = new Grammar(gb);

            speechRecognizer.LoadGrammar(g);
            speechRecognizer.SpeechRecognized += SreSpeechRecognized;
            speechRecognizer.SpeechHypothesized += SreSpeechHypothesized;
            speechRecognizer.SpeechRecognitionRejected += SreSpeechRecognitionRejected;

            this.readyTimer = new DispatcherTimer();
            this.readyTimer.Tick += this.ReadyTimerTick;
            this.readyTimer.Interval = new TimeSpan(0, 0, 4);
            this.readyTimer.Start();
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="kinectSensor"></param>
        public KinectSpeechRecognition(KinectSensor kinectSensor)
        {
            this.KinectSensor = kinectSensor;
            this.RecognizerInfo = this.FindRecognizerInfo();
            this.SpeechRecognitionEngine = new SpeechRecognitionEngine(this.RecognizerInfo); // this.RecognizerInfo.Id ?

            // Build and load grammar.
            this.Dictionary = this.BuildDictionary();
            this.SpeechRecognitionEngine.LoadGrammar(this.BuildGrammar(this.Dictionary));

            this.RecognizedChoice = "";
            this.RecognizableChoices = new List<String>();
        }
Example #8
0
        public CommandListener(RecognizerInfo recognizer)
        {
            Compose();

            Recognizer = recognizer;
            engine = new SpeechRecognitionEngine(recognizer);
            engine.SetInputToDefaultAudioDevice();

            engine.SpeechRecognized += sre_SpeechRecognized;
            engine.SpeechDetected += engine_SpeechDetected;
            engine.SpeechHypothesized += engine_SpeechHypothesized;
            engine.SpeechRecognitionRejected += engine_SpeechRecognitionRejected;
        }
Example #9
0
        public Grammar BuildGrammar(RecognizerInfo recInfo, string anchor)
        {
            Choices choices = new Choices();
            this.anchor = anchor;

            // Build General Command Grammar
            choices.Add(string.Format("{0} What time is it?", anchor));

            var gb = new GrammarBuilder();
            gb.Culture = recInfo.Culture;
            gb.Append(choices);

            return new Grammar(gb);
        }
Example #10
0
        public Recognizer( string name, Choices alternateChoices )
        {
            info = GetRecognizer( name );
            engine = new SpeechRecognitionEngine( info.Id );

            builder = new GrammarBuilder();
            builder.Culture = info.Culture;
            builder.Append( alternateChoices );

            grammar = new Grammar( builder );
            engine.LoadGrammar( grammar );
            engine.SpeechRecognized += Recognizer_SpeechRecognized;
            engine.SpeechHypothesized += Recognizer_SpeechHypothesized;
            engine.SpeechRecognitionRejected += Recognizer_SpeechRecognitionRejected;
        }
Example #11
0
        public SpeechRecognizer()
        {
            this.commandDelegates = new SpeechCommandReceived[SharedContent.CommandStrings.Length];
            for (int i = 0; i < commandDelegates.Length; i++)
            {
                commandDelegates[i] = null;
            }

            ri = SpeechRecognitionEngine.InstalledRecognizers().Where(r => r.Id == SharedContent.RecognizerId).FirstOrDefault();
            if (ri == null)
            {
                MessageBox.Show(
                    "Could not find speech recognizer: {0}. Please refer to the application requirements.", SharedContent.RecognizerId);
                Environment.Exit(-1);
            }
        }
Example #12
0
        public Grammar BuildGrammar(RecognizerInfo recInfo, string anchor)
        {
            Choices choices = new Choices();
            this.anchor = anchor;

            // Build General Command Grammar
            choices.Add(string.Format("{0} What's the weather right now?", anchor));
            choices.Add(string.Format("{0} What's the weather for tomorrow?", anchor));
            choices.Add(string.Format("{0} What was that?", anchor));

            var gb = new GrammarBuilder();
            gb.Culture = recInfo.Culture;
            gb.Append(choices);

            return new Grammar(gb);
        }
        public void Initialize()
        {
            if(initialized)
            {
                return;
            }

            KinectAudioSource audioSource = new KinectAudioSource(); // test Kinect

            ri = SpeechRecognitionEngine.InstalledRecognizers().Where(r => r.Id == RECOGNIZER_ID).FirstOrDefault();

            if (ri == null)
            {
                throw new Exception("Could not find speech recognizer " + RECOGNIZER_ID + ".");
            }

            initialized = true;
        }
        /// <summary>
        /// Method name reflects where it is supposed to be called. Loads/initializes all the resources
        /// of our speech recognizer.
        /// </summary>
        public void LoadContent()
        {
            foreach (var potentialSensor in KinectSensor.KinectSensors)
            {
                if (potentialSensor.Status == KinectStatus.Connected)
                {
                    this.Sensor = potentialSensor;
                    break;
                }
            }
            if (this.Sensor != null)
            {
                try
                {
                    // Start the sensor!
                    this.Sensor.Start();
                }
                catch (IOException)
                {
                    // Some other application is streaming from the same Kinect sensor
                    this.Sensor = null;
                }
            }

            if (this.Sensor == null)
            {
                return;
            }

            RecognizerInfo = GetKinectRecognizer();
            if (RecognizerInfo != null)
            {

                this.SpeechEngine = new SpeechRecognitionEngine(RecognizerInfo.Id);

                SetupGrammar();

                SpeechEngine.SetInputToAudioStream(
                    Sensor.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                SpeechEngine.RecognizeAsync(RecognizeMode.Multiple);
            }
        }
Example #15
0
        public Grammar BuildGrammar(RecognizerInfo recInfo, string anchor)
        {
            Choices choices = new Choices();
            this.anchor = anchor;

            // Build General Command Grammar
            choices.Add(string.Format("{0} What's your name?", anchor));
            choices.Add(string.Format("{0} Wake up", anchor));
            choices.Add(string.Format("{0} You suck", anchor));
            choices.Add(string.Format("{0} Shut Up", anchor));
            choices.Add(string.Format("{0} What was that?", anchor));
            choices.Add(string.Format("{0} What did you say?", anchor));
            choices.Add(string.Format("{0} Move upwards", anchor));
            choices.Add(string.Format("{0} Give me your status", anchor));

            var gb = new GrammarBuilder();
            gb.Culture = recInfo.Culture;
            gb.Append(choices);

            return new Grammar(gb);
        }
Example #16
0
        public Grammar BuildGrammar(RecognizerInfo recInfo, string anchor)
        {
            Choices choices = new Choices();
            List<ITunesTrack> trackList = itc.GetLibrary();
            this.anchor = anchor;

            // Build Artist Grammar
            List<string> artistList = trackList.Select(song => song.Artist).Distinct().ToList();
            foreach (var artist in artistList)
            {
                if (artist != null)
                {
                    choices.Add(string.Format("{0} play artist {1}", anchor, artist));
                }
            }

            // Build Song Grammar
            List<string> songList = trackList.Select(song => song.Name).Distinct().ToList();
            foreach (var song in songList)
            {
                if (song != null)
                {
                    var treatedSongName = song.Replace("\"", "");
                    choices.Add(string.Format("{0} play song {1}", anchor, treatedSongName));
                }
            }

            // Build General Command Grammar
            choices.Add(string.Format("{0} play", anchor));
            choices.Add(string.Format("{0} next", anchor));
            choices.Add(string.Format("{0} previous", anchor));
            choices.Add(string.Format("{0} pause", anchor));
            choices.Add(string.Format("{0} stop", anchor));

            var gb = new GrammarBuilder();
            gb.Culture = recInfo.Culture;
            gb.Append(choices);

            return new Grammar(gb);
        }
        void estableceReconocimiento()
        {
            ri = obtenerLP();
            if (ri != null)
            {
                speechengine = new SpeechRecognitionEngine(ri.Id);
                opciones = new Choices();

                opciones.Add(new SemanticResultValue("Angulo Kinect menos veinticinco", "KINECT25NEGATIVO"));
                opciones.Add(new SemanticResultValue("Angulo Kinect menos veinte", "KINECT20NEGATIVO"));
                opciones.Add(new SemanticResultValue("Angulo Kinect menos quince", "KINECT15NEGATIVO"));
                opciones.Add(new SemanticResultValue("Angulo Kinect menos diez", "KINECT10NEGATIVO"));
                opciones.Add(new SemanticResultValue("Angulo Kinect menos cinco", "KINECT5NEGATIVO"));
                opciones.Add(new SemanticResultValue("Angulo Kinect cero", "KINECT0"));
                opciones.Add(new SemanticResultValue("Angulo Kinect cinco", "KINECT5"));
                opciones.Add(new SemanticResultValue("Angulo Kinect diez", "KINECT10"));
                opciones.Add(new SemanticResultValue("Angulo Kinect quince", "KINECT15"));
                opciones.Add(new SemanticResultValue("Angulo Kinect veinte", "KINECT20"));
                opciones.Add(new SemanticResultValue("Angulo Kinect veinticinco", "KINECT25"));

                opciones.Add(new SemanticResultValue("Angulo Kinect restablecer", "KINECT0"));

                //Esta variable creará todo el conjunto de frases y palabras en base a nuestro lenguaje elegido en la variable ri
                grammarb = new GrammarBuilder { Culture = ri.Culture };
                //Agregamos las opciones de palabras y frases a grammarb
                grammarb.Append(opciones);

                grammar = new Grammar(grammarb);
                speechengine.LoadGrammar(grammar);

                speechengine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(speechengine_SpeechRecognized);

                //speechengine inicia la entrada de datos de audio
                speechengine.SetInputToAudioStream(miKinect.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                speechengine.RecognizeAsync(RecognizeMode.Multiple);
            }
        }
        public SpeechManager()
        {
            // No microphones have been initialized yet
            sensorActive = false;

            // If there's a Kinect available, set the recognizerInfo to the one it provides
            this.recognizerInfo = GetKinectRecognizer();
            if (this.recognizerInfo != null)
            {
                this.speechRecognitionEngine = new SpeechRecognitionEngine(this.recognizerInfo.Id);
                Console.WriteLine("Speech Recognition Engine set to Kinect Recognizer");
            }

            // Otherwise, use a new recognition engine for use with a default microhpone
            else
            {
                this.recognizerInfo = SpeechRecognitionEngine.InstalledRecognizers().FirstOrDefault();
                this.speechRecognitionEngine = new SpeechRecognitionEngine();
                Console.WriteLine("Speech Recognition Engine set to default microphone");
            }

            this.speechRecognitionEngine.SpeechRecognized += this.speechRecognized;
            this.speechRecognitionEngine.SpeechDetected += this.speechDetected;
        }
Example #19
0
        /// <summary>
        /// Default constructor. Sets up the voice recognizer with default settings.
        ///
        /// Namely, default options are: en-US, default input device, listen always, confidence level at .90
        /// </summary>
        public VoiceRecognizer()
        {
            if (SpeechRecognitionEngine.InstalledRecognizers().Count == 0)
            {
                SetupError = "You don't appear to have any Microsoft Speech Recognizer packs installed on your system.";
                State      = VoiceRecognizerState.Error;
                return;
            }

            try
            {
                var            installedRecognizers = SpeechRecognitionEngine.InstalledRecognizers();
                RecognizerInfo speechRecognizer     = null;

                switch (CultureInfo.InstalledUICulture.Name)
                {
                case "en-GB":
                    speechRecognizer = (installedRecognizers.FirstOrDefault(x => x.Culture.Name == "en-GB") ?? installedRecognizers.FirstOrDefault(x => x.Culture.TwoLetterISOLanguageName == "en"));
                    break;

                case "en-US":
                default:
                    speechRecognizer = installedRecognizers.FirstOrDefault(x => x.Culture.TwoLetterISOLanguageName == "en");
                    break;
                }


                if (speechRecognizer == null)
                {
                    SetupError = String.Format("You don't appear to have the {0} Speech Recognizer installed. Articulate requires this recognizer to be present in order to function correctly.", "English");
                    State      = VoiceRecognizerState.Error;
                    return;
                }

                // Setup members
                ConfidenceLock     = new Object();
                EngineShuttingDown = new AutoResetEvent(false);
                State = VoiceRecognizerState.Paused;

                // Create a new SpeechRecognitionEngine instance.
                Engine = new SpeechRecognitionEngine(speechRecognizer);

                try
                {
                    // Setup the audio device
                    Engine.SetInputToDefaultAudioDevice();
                }
                catch (InvalidOperationException ex)
                {
                    // No default input device
                    Trace.WriteLine(ex.Message);
                    SetupError = "Check input device.\n\n";
                    State      = VoiceRecognizerState.Error;
                    return;
                }

                // Set the confidence setting
                ConfidenceMargin = 90;

                // Create the Grammar instance and load it into the speech recognition engine.
                Grammar g = new Grammar(CommandPool.BuildSrgsGrammar(speechRecognizer.Culture));
                Engine.LoadGrammar(g);

                // Register a handlers for the SpeechRecognized and SpeechRecognitionRejected event
                Engine.SpeechRecognized          += sre_SpeechRecognized;
                Engine.SpeechRecognitionRejected += sre_SpeechRecognitionRejected;
                Engine.RecognizeCompleted        += sre_RecognizeCompleted;

                StartListening();
            }
            catch (Exception ex)
            {
                // Something went wrong setting up the voiceEngine.
                Trace.WriteLine(ex.Message);
                SetupError = String.Format("{0}\nCurrent Culture: {1}\nAvailable Recognizers: {2}\nStack Trace:\n{3}", ex.Message, CultureInfo.InstalledUICulture.Name, SpeechRecognitionEngine.InstalledRecognizers().Select(x => x.Culture.Name).Aggregate((x, y) => x + ", " + y), ex.StackTrace);
                State      = VoiceRecognizerState.Error;
            }
        }
Example #20
0
        private void InitializeSpeechRecognition()
        {
            RecognizerInfo ri = GetKinectRecognizer();

            if (ri == null)
            {
                MessageBox.Show(
                    @"There was a problem initializing Speech Recognition.
Ensure you have the Microsoft Speech SDK installed.",
                    "Failed to load Speech SDK",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
                return;
            }

            try
            {
                speechRecognizer = new SpeechRecognitionEngine(ri.Id);
            }
            catch
            {
                MessageBox.Show(
                    @"There was a problem initializing Speech Recognition.
Ensure you have the Microsoft Speech SDK installed and configured.",
                    "Failed to load Speech SDK",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
            }

            var firstword = new Choices();

            foreach (string value in firstWord.Keys)
            {
                firstword.Add(value);
            }

            GrammarBuilder firstword1 = new Choices(new string[] { "seir" });

            firstword1.Append("surita");
            firstword1.Append("fimm");
            firstword1.Append("groenn");
            firstword1.Append("vindr");

            GrammarBuilder firstword2 = new Choices(new string[] { "oss" });

            firstword2.Append("naeo");
            firstword2.Append("fyor");
            firstword2.Append("regin");
            firstword2.Append("tinada");
            firstword2.Append("varindo");
            firstword2.Append("yotsun");

            GrammarBuilder exit = new Choices(new string[] { "nox" });

            exit.Append("eterna");

            Choices first = new Choices();

            first.Add(new Choices(new GrammarBuilder[] { firstword1, firstword2, exit }));

            var gb = new GrammarBuilder();

            gb.Culture = ri.Culture;
            gb.Append(first);

            var g = new Grammar(gb);

            speechRecognizer.LoadGrammar(g);
            speechRecognizer.SpeechRecognized          += speechRecognizer_SpeechRecognized;
            speechRecognizer.SpeechHypothesized        += speechRecognizer_SpeechHypothesized;
            speechRecognizer.SpeechRecognitionRejected += speechRecognizer_SpeechRecognitionRejected;

            if (Kinect == null || speechRecognizer == null)
            {
                return;
            }

            var audioSource = this.Kinect.AudioSource;

            audioSource.BeamAngleMode = BeamAngleMode.Adaptive;
            var kinectStream = audioSource.Start();

            speechRecognizer.SetInputToAudioStream(
                kinectStream, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
            speechRecognizer.RecognizeAsync(RecognizeMode.Multiple);
        }
Example #21
0
        /// <summary>
        /// Kinect enabled apps should customize which Kinect services it initializes here.
        /// </summary>
        /// <param name="kinectSensorManager"></param>
        /// <param name="sensor"></param>
        private void InitializeKinectServices(KinectSensorManager kinectSensorManager, KinectSensor sensor)
        {
            // Application should enable all streams first.

            // configure the color stream
            kinectSensorManager.ColorFormat        = ColorImageFormat.RgbResolution640x480Fps30;
            kinectSensorManager.ColorStreamEnabled = true;

            // configure the depth stream
            kinectSensorManager.DepthStreamEnabled = true;

            kinectSensorManager.TransformSmoothParameters =
                new TransformSmoothParameters
            {
                Smoothing          = 0.5f,
                Correction         = 0.5f,
                Prediction         = 0.5f,
                JitterRadius       = 0.05f,
                MaxDeviationRadius = 0.04f
            };

            // configure the skeleton stream
            sensor.SkeletonFrameReady += OnSkeletonFrameReady;
            kinectSensorManager.SkeletonStreamEnabled = true;

            // initialize the gesture recognizer
            gestureController = new GestureController();
            gestureController.GestureRecognized += OnGestureRecognized;

            kinectSensorManager.KinectSensorEnabled = true;

            RecognizerInfo ri = GetKinectRecognizer();

            if (null != ri)
            {
                // recognitionSpans = new List<Span> { forwardSpan, backSpan, rightSpan, leftSpan };

                this.speechEngine = new SpeechRecognitionEngine(ri.Id);

                var directions = new Choices();
                //directions.Add(new SemanticResultValue("forward", "FORWARD"));
                //directions.Add(new SemanticResultValue("forwards", "FORWARD"));
                //directions.Add(new SemanticResultValue("straight", "FORWARD"));
                //directions.Add(new SemanticResultValue("backward", "BACKWARD"));
                //directions.Add(new SemanticResultValue("backwards", "BACKWARD"));
                //directions.Add(new SemanticResultValue("back", "BACKWARD"));
                //directions.Add(new SemanticResultValue("turn left", "LEFT"));
                //directions.Add(new SemanticResultValue("turn right", "RIGHT"));
                directions.Add(new SemanticResultValue("lights on", "LIGHTS_ON"));
                directions.Add(new SemanticResultValue("lights off", "LIGHTS_OFF"));
                directions.Add(new SemanticResultValue("screen up", "SCREEN_UP"));
                directions.Add(new SemanticResultValue("screen down", "SCREEN_DOWN"));
                directions.Add(new SemanticResultValue("projector on", "PROJECTOR_ON"));
                directions.Add(new SemanticResultValue("projector off", "PROJECTOR_OFF"));
                directions.Add(new SemanticResultValue("presentation mode", "PRESENTATION_MODE"));
                directions.Add(new SemanticResultValue("blackboard mode", "BLACKBOARD_MODE"));

                var gb = new GrammarBuilder {
                    Culture = ri.Culture
                };
                gb.Append(directions);

                var g = new Grammar(gb);

                // Create a grammar from grammar definition XML file.
                //using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(Properties.Resources.SpeechGrammar)))
                //{
                //    var g = new Grammar(memoryStream);
                //    speechEngine.LoadGrammar(g);
                //}

                speechEngine.LoadGrammar(g);
                speechEngine.SpeechRecognized          += SpeechRecognized;
                speechEngine.SpeechRecognitionRejected += SpeechRejected;

                speechEngine.SetInputToAudioStream(sensor.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                speechEngine.RecognizeAsync(RecognizeMode.Multiple);
            }
            else
            {
                //this.statusBarText.Text = Properties.Resources.NoSpeechRecognizer;
            }
            if (!kinectSensorManager.KinectSensorAppConflict)
            {
                // addition configuration, as needed
            }
        }
Example #22
0
        public void setup(string[] args /*, StreamWriter writer*/)
        {
            kinectSensor = KinectSensor.KinectSensors[0];

            //output = writer;
            source = kinectSensor.AudioSource;

            //source.FeatureMode = true;
            source.AutomaticGainControlEnabled = false;                     //Important to turn this off for speech recognition
            source.EchoCancellationMode        = EchoCancellationMode.None; //SystemMode.OptibeamArrayOnly; //No AEC for this sample

            //RecognizerInfo ri = SpeechRecognitionEngine.InstalledRecognizers().Where(r => r.Id == RecognizerId).FirstOrDefault();
            RecognizerInfo ri = getKinectRecognizer();

            if (ri == null)
            {
                //Console.WriteLine("Could not find speech recognizer: {0}. Please refer to the sample requirements.", RecognizerId);
                Console.WriteLine("Could not find speech recognizer. Please refer to the sample requirements.");
                return;
            }

            Console.WriteLine("Using: {0}", ri.Name);

            //using (var sre = new SpeechRecognitionEngine(ri.Id))
            sre = new SpeechRecognitionEngine(ri.Id);
            var words = new Choices();

            foreach (string w in args)
            {
                words.Add(w);
            }

            gb = new GrammarBuilder();
            //Specify the culture to match the recognizer in case we are running in a different culture.
            gb.Culture = ri.Culture;
            gb.Append(words);


            // Create the actual Grammar instance, and then load it into the speech recognizer.
            g = new Grammar(gb);

            sre.LoadGrammar(g);
            sre.SpeechRecognized          += SreSpeechRecognized;
            sre.SpeechHypothesized        += SreSpeechHypothesized;
            sre.SpeechRecognitionRejected += SreSpeechRecognitionRejected;

            s = source.Start();

            sre.SetInputToAudioStream(s,
                                      new SpeechAudioFormatInfo(
                                          EncodingFormat.Pcm, 16000, 16, 1,
                                          32000, 2, null));

            Console.Write("Recognizing: ");
            foreach (string w in args)
            {
                Console.Write(w + " ");
            }
            Console.Write("\n");

            startRecog();
        }
Example #23
0
        public Recognizer()
        {
            RecognizerInfo ri = SpeechRecognitionEngine.InstalledRecognizers().Where(r => r.Id == RecognizerId).FirstOrDefault();

            if (ri == null)
            {
                return;
            }

            sre = new SpeechRecognitionEngine(ri.Id);

            // Build a simple grammar of shapes, colors, and some simple program control
            var single = new Choices();

            foreach (var phrase in SinglePhrases)
            {
                single.Add(phrase.Key);
            }

            var gameplay = new Choices();

            foreach (var phrase in GameplayPhrases)
            {
                gameplay.Add(phrase.Key);
            }

            var shapes = new Choices();

            foreach (var phrase in ShapePhrases)
            {
                shapes.Add(phrase.Key);
            }

            var colors = new Choices();

            foreach (var phrase in ColorPhrases)
            {
                colors.Add(phrase.Key);
            }

            var coloredShapeGrammar = new GrammarBuilder();

            coloredShapeGrammar.Append(colors);
            coloredShapeGrammar.Append(shapes);

            var objectChoices = new Choices();

            objectChoices.Add(gameplay);
            objectChoices.Add(shapes);
            objectChoices.Add(colors);
            objectChoices.Add(coloredShapeGrammar);

            var actionGrammar = new GrammarBuilder();

            actionGrammar.AppendWildcard();
            actionGrammar.Append(objectChoices);

            var allChoices = new Choices();

            allChoices.Add(actionGrammar);
            allChoices.Add(single);

            var gb = new GrammarBuilder();

            gb.Append(allChoices);

            var g = new Grammar(gb);

            sre.LoadGrammar(g);
            sre.SpeechRecognized          += sre_SpeechRecognized;
            sre.SpeechHypothesized        += sre_SpeechHypothesized;
            sre.SpeechRecognitionRejected += new EventHandler <SpeechRecognitionRejectedEventArgs>(sre_SpeechRecognitionRejected);

            var t = new Thread(StartDMO);

            t.Start();

            valid = true;
        }
Example #24
0
        private void LoadContent()
        {
            kinectDevice = new Runtime();
            kinectDevice.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseColor);

            kinectDevice.SkeletonEngine.TransformSmooth = true;
            kinectDevice.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color);
            kinectDevice.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex);

            kinectDevice.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(kinectDevice_SkeletonFrameReady);
            kinectDevice.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(kinectDevice_VideoFrameReady);            

            kinectAudio = new KinectAudioSource();

            kinectAudio.FeatureMode = true;
            kinectAudio.AutomaticGainControl = false;
            kinectAudio.SystemMode = SystemMode.OptibeamArrayOnly;

            ri = SpeechRecognitionEngine.InstalledRecognizers().Where(r => r.Id == RecognizerId).FirstOrDefault();
            sre = new SpeechRecognitionEngine(ri.Id);
            audioChoices = new Choices();
            audioChoices.Add("stop");
            audioChoices.Add("start");
            audioChoices.Add("kinect shutdown");
            audioChoices.Add("reset time");
            audioChoices.Add("spree");
            audioChoices.Add("reset hand");
            audioChoices.Add("faster");
            audioChoices.Add("slower");
            grammerBuilder = new GrammarBuilder();
            grammerBuilder.Culture = ri.Culture;
            grammerBuilder.Append(audioChoices);
            grammer = new Grammar(grammerBuilder);

            sre.LoadGrammar(grammer);

            sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);

            sre.SetInputToAudioStream(kinectAudio.Start(), new SpeechAudioFormatInfo( EncodingFormat.Pcm, 16000,16,1,32000,2, null));
            sre.RecognizeAsync(RecognizeMode.Multiple);

            player = new NinjaPlayer(this);

            backGround = Content.Load<Texture2D>("wood_paneling");
            font = Content.Load<SpriteFont>("font");

            sound = new SoundPlayer();
        }
        // Connect to the Kinect sensor and begin processing events.
        public void InitializeKinect()
        {
            this.sensor = null;

            // Look through all sensors and start the first connected one.
            // This requires that a Kinect is connected at the time of app startup.
            // To make your app robust against plug/unplug,
            // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit (See components in Toolkit Browser).
            foreach (var potentialSensor in KinectSensor.KinectSensors)
            {
                if (potentialSensor.Status == KinectStatus.Connected)
                {
                    this.sensor = potentialSensor;
                    break;  // Connect to first Kinect.
                }
            }

            if (null == this.sensor)
            {
                ErrorLogging.AddMessage(ErrorLogging.LoggingLevel.Error, "InitializeKinect() failed, not connected to Kinect sensor.");
                return;
            }
            else
            {
                // Turn on the skeleton stream to receive skeleton frames
                this.sensor.SkeletonStream.Enable();

                // Add an event handler to be called whenever there is new color frame data
                SkeletonFrameReady += SensorSkeletonFrameReady;

                // Start the sensor!
                try
                {
                    this.sensor.Start();
                }
                catch (IOException)
                {
                    ErrorLogging.AddMessage(ErrorLogging.LoggingLevel.Error, "InitializeKinect() failed, unable to Start Kinect sensor.");
                    this.sensor = null;
                    return;
                }
            }

            RecognizerInfo ri = GetKinectRecognizer();

            if (null != ri)
            {
                this.speechEngine = new SpeechRecognitionEngine(ri.Id);

                /****************************************************************
                *
                * Use this code to create grammar programmatically rather than from
                * a grammar file.
                *
                * var directions = new Choices();
                * directions.Add(new SemanticResultValue("forward", "FORWARD"));
                * directions.Add(new SemanticResultValue("forwards", "FORWARD"));
                * directions.Add(new SemanticResultValue("straight", "FORWARD"));
                * directions.Add(new SemanticResultValue("backward", "BACKWARD"));
                * directions.Add(new SemanticResultValue("backwards", "BACKWARD"));
                * directions.Add(new SemanticResultValue("back", "BACKWARD"));
                * directions.Add(new SemanticResultValue("turn left", "LEFT"));
                * directions.Add(new SemanticResultValue("turn right", "RIGHT"));
                *
                * var gb = new GrammarBuilder { Culture = ri.Culture };
                * gb.Append(directions);
                *
                * var g = new Grammar(gb);
                *
                ****************************************************************/

                // Create a grammar from grammar definition XML file.
                using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(Properties.Resources.SpeechGrammar)))
                {
                    var g = new Grammar(memoryStream);
                    speechEngine.LoadGrammar(g);
                }

                speechEngine.SpeechRecognized          += SpeechRecognized;
                speechEngine.SpeechRecognitionRejected += SpeechRejected;

                robotSpeech.SpeakStarted   += SpeakStarted;
                robotSpeech.SpeakCompleted += SpeakCompleted;

                // For long recognition sessions (a few hours or more), it may be beneficial to turn off adaptation of the acoustic model.
                // This will prevent recognition accuracy from degrading over time.
                ////speechEngine.UpdateRecognizerSetting("AdaptationOn", 0);

                speechEngine.SetInputToAudioStream(
                    sensor.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                speechEngine.RecognizeAsync(RecognizeMode.Multiple);
            }
            else
            {
                ErrorLogging.AddMessage(ErrorLogging.LoggingLevel.Error, "InitializeKinect() failed, no speech recognizer.");
            }

            ErrorLogging.AddMessage(ErrorLogging.LoggingLevel.Info, "InitializeKinect() succeeded, Kinect sensor is ready.");
        }
Example #26
0
        // Execute startup tasks
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            // Look through all sensors and start the first connected one.
            // This requires that a Kinect is connected at the time of app startup.
            // To make your app robust against plug/unplug,
            // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit (See components in Toolkit Browser).
            foreach (var potentialSensor in KinectSensor.KinectSensors)
            {
                if (potentialSensor.Status == KinectStatus.Connected)
                {
                    this.sensor = potentialSensor;
                    break;
                }
            }

            if (null != this.sensor)
            {
                // Skeleton
                // Create the drawing group we'll use for drawing
                this.drawingGroupSkeleton = new DrawingGroup();
                // Create an image source that we can use in our image control
                this.imageSourceSkeleton = new DrawingImage(this.drawingGroupSkeleton);
                // Display the drawing using our image control
                ImageSkeleton.Source = this.imageSourceSkeleton;
                // Turn on the skeleton stream to receive skeleton frames
                this.sensor.SkeletonStream.Enable();
                // Add an event handler to be called whenever there is new color frame data
                this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;

                // Ball
                // Create the drawing group we'll use for drawing
                this.drawingGroupBall = new DrawingGroup();
                // Create an image source that we can use in our image control
                this.imageSourceBall = new DrawingImage(this.drawingGroupBall);
                // Display the drawing using our image control
                ImageBall.Source = this.imageSourceBall;
                // Turn on the skeleton stream to receive skeleton frames
                ball.vel = new Vector(0, initialVel);
                ball.pos = new Point();

                // Racket
                racket1.posList   = new List <Point>();
                racket1.thetaList = new List <float>();
                racket2.posList   = new List <Point>();
                racket2.thetaList = new List <float>();

                // RGB
                // Turn on the color stream to receive color frames
                this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
                // Allocate space to put the pixels we'll receive
                this.colorPixels = new byte[this.sensor.ColorStream.FramePixelDataLength];
                // This is the bitmap we'll display on-screen
                this.colorBitmap = new WriteableBitmap(this.sensor.ColorStream.FrameWidth, this.sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);
                // Set the image we display to point to the bitmap where we'll put the image data
                this.ImageRGB.Source = this.colorBitmap;
                // Add an event handler to be called whenever there is new color frame data
                this.sensor.ColorFrameReady += this.SensorColorFrameReady;

                // Start the sensor!
                try
                {
                    this.sensor.Start();
                }
                catch (IOException)
                {
                    this.sensor = null;
                }
            }

            if (null == this.sensor)
            {
                this.statusBarText.Text = Properties.Resources.NoKinectReady;
            }

            // v----- Speech recognizer -----v //
            RecognizerInfo ri = GetKinectRecognizer();

            if (null != ri)
            {
                this.speechEngine = new SpeechRecognitionEngine(ri.Id);

                var directions = new Choices();
                directions.Add(new SemanticResultValue("pelota", "PELOTA"));   // Grammar, Command
                directions.Add(new SemanticResultValue("reset", "RESET"));

                var gb = new GrammarBuilder {
                    Culture = ri.Culture
                };
                gb.Append(directions);

                var g = new Grammar(gb);

                // Create a grammar not from grammar definition XML file.
                speechEngine.LoadGrammar(g);

                speechEngine.SpeechRecognized += SpeechRecognized;
                //speechEngine.SpeechRecognitionRejected += SpeechRejected;

                // For long recognition sessions (a few hours or more), it may be beneficial to turn off adaptation of the acoustic model.
                // This will prevent recognition accuracy from degrading over time.
                ////speechEngine.UpdateRecognizerSetting("AdaptationOn", 0);

                speechEngine.SetInputToAudioStream(
                    sensor.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                speechEngine.RecognizeAsync(RecognizeMode.Multiple);
            }
            // ^----- Speech recognizer -----^ //
        }
Example #27
0
        static bool CreateRecognizer()
        {
            // Was the SRE already defined ?
            if (recognizer != null)
            {
                // Yes
                recognizer = null;
            }

            try
            {

                recogInfo = null;
                Console.WriteLine("\nSpeech Processor: The following Speech Recognizers are available:");

                foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers())
                {
                    Console.Write("  "); Console.WriteLine(ri.Description);
                    if (ri.Culture.Name.Equals(strCulture))
                    {
                        recogInfo = ri;
                    }
                }

                if (recogInfo != null)
                {
                    recognizer = new SpeechRecognitionEngine(recogInfo);
                    Console.WriteLine("\nUsing recognizer " + recognizer.RecognizerInfo.Name + " for culture " + strCulture);

                    // Attach event handlers.
                    recognizer.SpeechDetected +=
                        new EventHandler<SpeechDetectedEventArgs>(
                        SpeechDetectedHandler);
                    /*    recognizer.SpeechHypothesized +=
                            new EventHandler<SpeechHypothesizedEventArgs>(SpeechHypothesizedHandler);
                          recognizer.SpeechRecognitionRejected +=
                            new EventHandler<SpeechRecognitionRejectedEventArgs>(SpeechRecognitionRejectedHandler);
                    */
                    recognizer.SpeechRecognized +=
                        new EventHandler<SpeechRecognizedEventArgs>(
                        SpeechRecognizedHandler);
                    recognizer.RecognizeCompleted +=
                        new EventHandler<RecognizeCompletedEventArgs>(
                        RecognizeCompletedHandler);
                    recognizer.RecognizerUpdateReached +=
                        new EventHandler<RecognizerUpdateReachedEventArgs>(RecognizerUpdateReachedHandler);

                    // Assign input to the recognizer and start asynchronous
                    // recognition.
                    recognizer.SetInputToDefaultAudioDevice();

                    return (true);
                }
                else
                {
                    Console.WriteLine("\nSpeech Processor: could not find a recognizer for culture ..." + strCulture);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nSpeech Processor: unable to create Speech Recognition Engine");
            }

            return (false);
        }
        void conectaActiva()
        {
            //Nos aseguramos que la cuenta de sensores conectados sea de al menos 1

            if (KinectSensor.KinectSensors.Count > 0)
            {
                //Checamos que la variable _sensor sea nula

                if (this._sensor == null)
                {
                    //Asignamos el primer sensor Kinect a nuestra variable
                    this._sensor = KinectSensor.KinectSensors[0];
                    if (this._sensor != null)
                    {
                        try
                        {
                            //Iniciamos el dispositivo Kinect
                            this._sensor.Start();
                            //Esto es opcional pero ayuda a colocar el dispositivo Kinect a un cierto angulo de inclinacion, desde -27 a 27
                            _sensor.ElevationAngle = 3;
                            //Informamos que se ha conectado e inicializado correctamente el dispositivo Kinect
                            //El source nuestro control imagen mandara llamar a la imagen 1.jpg , lo mismo se hace para las demas opciones
                        }
                        catch (Exception ex)
                        {
                            //Si hay algun error lo mandamos en el TextBlock statusK
                        }

                        //Creamos esta variable ri que tratara de encontrar un language pack valido haciendo uso del metodo obtenerLP
                        RecognizerInfo ri = obtenerLP();
                        //Si se encontro el language pack requerido lo asignaremos a nuestra variable speechengine
                        if (ri != null)
                        {
                            this.speechengine = new SpeechRecognitionEngine(ri.Id);

                            //Creamos esta variable opciones la cual almacenara las opciones de palabras o frases que podran ser reconocidas por el dispositivo

                            var opciones = new Choices();

                            //Comenzamos a agregar las opciones comenzando por el valor de opcion que tratamos reconocer y una llave que identificara a ese
                            //valor

                            //Por ejemplo en esta linea "uno" es el valor de opcion y "UNO" es la llave

                            opciones.Add("encendido", "ENCENDIDO");

                            //En esta linea "unidad" es el valor de opcion y "UNO" es la llave

                            opciones.Add("apagado", "APAGAR");

                            //En esta linea "dos" es el valor de opcion y "DOS" es la llave

                            opciones.Add("adelante", "ADELANTE");

                            //En esta linea "windows ocho" es el valor de opcion y "TRES" es la llave y asi sucesivamente

                            opciones.Add("atrás", "BACK");

                            opciones.Add("subir", "SUBIR");
                            opciones.Add("bajar", "BAJAR");
                            opciones.Add(new SemanticResultValue("prende", "ENCENDIDO"));
                            opciones.Add(new SemanticResultValue("apaga", "APAGADO"));
                            opciones.Add(new SemanticResultValue("sube", "SUBIR"));
                            opciones.Add(new SemanticResultValue("baja", "BAJAR"));

                            //Esta variable creará todo el conjunto de frases y palabras en base a nuestro lenguaje elegido en la variable ri

                            var grammarb = new GrammarBuilder {
                                Culture = ri.Culture
                            };

                            //Agregamos las opciones de palabras y frases a grammarb

                            grammarb.Append(opciones);

                            //Creamos una variable de tipo Grammar utilizando como parametro a grammarb

                            var grammar = new Grammar(grammarb);

                            //Le decimos a nuestra variable speechengine que cargue a grammar

                            this.speechengine.LoadGrammar(grammar);

                            //mandamos llamar al evento SpeechRecognized el cual se ejecutara cada vez que una palabra sea detectada

                            speechengine.SpeechRecognized += new EventHandler <SpeechRecognizedEventArgs>(speechengine_SpeechRecognized);

                            //speechengine inicia la entrada de datos de tipo audio

                            speechengine.SetInputToAudioStream(_sensor.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1,
                                                                                                                      32000, 2, null));

                            speechengine.RecognizeAsync(RecognizeMode.Multiple);
                        }
                    }
                    else
                    {
                        // statusK1.Content = "Conectado";
                    }
                }
            }
        }
Example #29
0
        static bool CreateRecognizer()
        {
            // Was the SRE already defined ?
            if (recognizer != null)
            {
                // Yes
                recognizer = null;
            }

            try
            {
                recogInfo = null;
                Console.WriteLine("\nSpeech Processor: The following Speech Recognizers are available:");

                foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers())
                {
                    Console.Write("  "); Console.WriteLine(ri.Description);
                    if (ri.Culture.Name.Equals(strCulture))
                    {
                        recogInfo = ri;
                    }
                }

                if (recogInfo != null)
                {
                    recognizer = new SpeechRecognitionEngine(recogInfo);
                    Console.WriteLine("\nUsing recognizer " + recognizer.RecognizerInfo.Name + " for culture " + strCulture);

                    // Attach event handlers.
                    recognizer.SpeechDetected +=
                        new EventHandler <SpeechDetectedEventArgs>(
                            SpeechDetectedHandler);

                    /*    recognizer.SpeechHypothesized +=
                     *      new EventHandler<SpeechHypothesizedEventArgs>(SpeechHypothesizedHandler);
                     *    recognizer.SpeechRecognitionRejected +=
                     *      new EventHandler<SpeechRecognitionRejectedEventArgs>(SpeechRecognitionRejectedHandler);
                     */
                    recognizer.SpeechRecognized +=
                        new EventHandler <SpeechRecognizedEventArgs>(
                            SpeechRecognizedHandler);
                    recognizer.RecognizeCompleted +=
                        new EventHandler <RecognizeCompletedEventArgs>(
                            RecognizeCompletedHandler);
                    recognizer.RecognizerUpdateReached +=
                        new EventHandler <RecognizerUpdateReachedEventArgs>(RecognizerUpdateReachedHandler);

                    // Assign input to the recognizer and start asynchronous
                    // recognition.
                    recognizer.SetInputToDefaultAudioDevice();

                    return(true);
                }
                else
                {
                    Console.WriteLine("\nSpeech Processor: could not find a recognizer for culture ..." + strCulture);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nSpeech Processor: unable to create Speech Recognition Engine");
            }

            return(false);
        }
        private KinectModel()
        {
            kinectSensor = KinectSensor.GetDefault();
            timerFoundBodies.Interval = TimeSpan.FromSeconds(1.5);
            timerNoBodies.Interval = TimeSpan.FromSeconds(10);
            timerFoundBodies.Tick += TimerFoundBodies_Tick;
            timerNoBodies.Tick += TimerNoBodies_Tick;

            if (kinectSensor != null)
            {
                this.kinectSensor.Open();

                IReadOnlyList<AudioBeam> audioBeamList = this.kinectSensor.AudioSource.AudioBeams;
                Stream audioStream = audioBeamList[0].OpenInputStream();

                this.convertStream = new KinectAudioStream(audioStream);
            }
            else
            {
                return;
            }

            ri = TryGetKinectRecognizer();
            //	Setup Gestures
            InitGestures();

            ActiveViews = new List<IReceptionistView>();
        }
Example #31
0
 private SpeechRecognizer()
 {
     RecognizerInfo ri = GetKinectRecognizer();
     this.sre = new SpeechRecognitionEngine(ri);
     this.LoadGrammar(this.sre);
 }
Example #32
0
        static void Main(string[] args)
        {
            try
            {
                using (var source = new KinectAudioSource())
                {
                    source.FeatureMode          = true;
                    source.AutomaticGainControl = false;                        //Important to turn this off for speech recognition
                    source.SystemMode           = SystemMode.OptibeamArrayOnly; //No AEC for this sample

                    RecognizerInfo ri = SpeechRecognitionEngine.InstalledRecognizers().Where(r => r.Id == RecognizerId).FirstOrDefault();

                    if (ri == null)
                    {
                        Console.WriteLine("Could not find speech recognizer: {0}. Please refer to the sample requirements.", RecognizerId);
                        return;
                    }

                    Console.WriteLine("Using: {0}", ri.Name);

                    using (var sre = new SpeechRecognitionEngine(ri.Id))
                    {
                        var colors = new Choices();
                        colors.Add("red");
                        colors.Add("green");
                        colors.Add("blue");

                        var gb = new GrammarBuilder();
                        //Specify the culture to match the recognizer in case we are running in a different culture.
                        gb.Culture = ri.Culture;
                        gb.Append(colors);


                        // Create the actual Grammar instance, and then load it into the speech recognizer.
                        var g = new Grammar(gb);

                        sre.LoadGrammar(g);
                        sre.SpeechRecognized          += SreSpeechRecognized;
                        sre.SpeechHypothesized        += SreSpeechHypothesized;
                        sre.SpeechRecognitionRejected += SreSpeechRecognitionRejected;

                        using (Stream s = source.Start())
                        {
                            sre.SetInputToAudioStream(s,
                                                      new SpeechAudioFormatInfo(
                                                          EncodingFormat.Pcm, 16000, 16, 1,
                                                          32000, 2, null));

                            Console.WriteLine("Recognizing. Say: 'red', 'green' or 'blue'. Press ENTER to stop");

                            sre.RecognizeAsync(RecognizeMode.Multiple);
                            Console.ReadLine();
                            Console.WriteLine("Stopping recognizer ...");
                            sre.RecognizeAsyncStop();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #33
0
        public Form1()
        {
            InitializeComponent();
            for (int i = 3; i < 255; i++)
            {
                this.cmbBoxIPID.Items.Add(string.Format("{0:X2}", i));
            }

            this.acnxConnection = new ActiveCNX();

            acnxConnection.onConnect    += new ActiveCNXConnectionEventHandler(acnxConnection_onConnect);
            acnxConnection.onDisconnect += new ActiveCNXConnectionEventHandler(acnxConnection_onDisconnect);
            acnxConnection.onError      += new ActiveCNXErrorEventHandler(acnxConnection_onError);
            acnxConnection.onDigital    += new ActiveCNXEventHandler(acnxConnection_onDigital);

            //I remembered that you can chain as many methods onto a delegate as you want, meaning we don't need a List of actions anymore.
            //Now instead of initializing several lists within the dictionary, we can just initialize it with a null delegate to start and
            //then add methods onto it as needed. Should be an easier syntax than dealing with the lists...
            Action del = null;

            audioSource.FeatureMode          = true;
            audioSource.AutomaticGainControl = false;
            audioSource.SystemMode           = SystemMode.OptibeamArrayOnly;

            RecognizerInfo ri = SpeechRecognitionEngine.InstalledRecognizers().Where(r => r.Id == RecognizerId).FirstOrDefault();

            if (ri == null)
            {
                MessageBox.Show("Could not find speech recognizer: {0}.", RecognizerId);
                return;
            }

            this.sre       = new SpeechRecognitionEngine(ri.Id);
            this.transport = new Choices(
                "play",
                "stop",
                "next channel",
                "previous channel",
                "cnn",
                "fox");

            var gb = new GrammarBuilder();

            gb.Culture = ri.Culture;
            gb.Append(transport);

            var g = new Grammar(gb);

            sre.LoadGrammar(g);

            this.actionMap = new Dictionary <string, Action>()
            {
                { "play", del },
                { "stop", del },
                { "pause", del },
            };

            actionMap["play"] += () =>
            {
                this.log.LogEvent("\nPlay command recognized");
                this.acnxConnection.SendDigital(0, 1, true);
                this.acnxConnection.SendDigital(0, 1, false);
            };

            actionMap["stop"] += () =>
            {
                this.log.LogEvent("\nStop command recognized");
                this.acnxConnection.SendDigital(0, 2, true);
                this.acnxConnection.SendDigital(0, 2, false);
            };

            actionMap["pause"] += () =>
            {
                this.log.LogEvent("\nPause command recognized");
                this.acnxConnection.SendDigital(0, 3, true);
                this.acnxConnection.SendDigital(0, 3, false);
            };

            //We could also do something like this, if we wanted a way to add actions at runtime; something like this
            //would let us add new actions to a given command while the form was running, which might be cool
            AddActionToMap("play", () => this.acnxConnection.SendDigital(1, 0, false));

            //To deal with the threading issue, I've moved the speech stuff into it's own class, which is how the ShapeGame
            //sample works. The Recognizer basically just takes an array of strings to set up a speech engine, and has it's
            //own SpeechRecognized event that we can hook onto - it basically just mirrors the standard SpeechRecognized event.
            //This means the Kinect stuff can have it's own little MTA threaded playground to fart around in, but the rest of
            //the code doesn't have to deal with any messy threading issues.
            recognizer = new Recognizer(this.actionMap.Keys.ToArray());
            this.recognizer.SaidSomething += sre_SpeechRecognized;
        }
 public VoiceControlEngine(KinectSensor sensor)
 {
     this.sensor = sensor;
     this.ri = GetKinectRecognizer();
     this.spotifyController = new SpotifyController();
 }
Example #35
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SpeechRecognizer"/> class.
        /// </summary>
        /// <param name="recognizerInfo">
        /// Metadata used to identify the recognizer acoustic model to be used.
        /// </param>
        /// <param name="grammars">
        /// Set of grammars to be loaded into speech recognition engine. May NOT be null.
        /// </param>
        private SpeechRecognizer(RecognizerInfo recognizerInfo, IEnumerable<Grammar> grammars)
        {
            this.ConfidenceThreshold = DefaultConfidenceThreshold;
            this.speechEngine = new SpeechRecognitionEngine(recognizerInfo);

            try
            {
                foreach (Grammar grammar in grammars)
                {
                    speechEngine.LoadGrammar(grammar);
                }
            }
            catch (InvalidOperationException)
            {
                // Grammar may not be in a valid state
                this.speechEngine.Dispose();
                this.speechEngine = null;
            }
        }
Example #36
0
        ///////////////////////////////////////////////////////////////////
        private void CreateGrammars(RecognizerInfo rInfo)
        {
            //定义操作类型
            var controls = new Choices();
            controls.Add("打开");
            controls.Add("关闭");
            controls.Add("调高");
            controls.Add("降低");

            //定义所操作的设备
            var devices = new Choices();
            devices.Add("电视");
            devices.Add("红色电灯");
            devices.Add("绿色电灯");
            devices.Add("空调");

            //定义操作参数
            var param = new Choices();
            param.Add("亮度");
            param.Add("温度");
            param.Add("频道");
            param.Add("电源");

            var gBulider = new GrammarBuilder();
            gBulider.Culture = rInfo.Culture;
            gBulider.Append(controls);
            gBulider.Append(devices);
            gBulider.Append(param);
            gBulider.AppendWildcard();

            var g = new Grammar(gBulider);
            _speechRecognitionEngine.LoadGrammar(g);

            var q = new GrammarBuilder { Culture = rInfo.Culture };
            q.Append("退出 程序");
            var quit = new Grammar(q);

            _speechRecognitionEngine.LoadGrammar(quit);
        }
Example #37
0
        /// <summary>
        /// Execute initialization tasks.
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            // Look through all sensors and start the first connected one.
            // This requires that a Kinect is connected at the time of app startup.
            // To make your app robust against plug/unplug,
            // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit (See components in Toolkit Browser).
            foreach (var potentialSensor in KinectSensor.KinectSensors)
            {
                if (potentialSensor.Status == KinectStatus.Connected)
                {
                    this.sensor = potentialSensor;
                    break;
                }
            }

            objec[0] = -1;
            objec[1] = -1;
            objec[2] = -1;
            bot[0]   = 0;
            bot[1]   = 0;
            bot[2]   = 0;

            if (null != this.sensor)
            {
                this.sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
                this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
                this.sensor.SkeletonStream.Enable();
                this.colorPixels = new byte[this.sensor.ColorStream.FramePixelDataLength];
                this.depthPixels = new DepthImagePixel[this.sensor.DepthStream.FramePixelDataLength];
                this.colorBitmap = new WriteableBitmap(this.sensor.ColorStream.FrameWidth, this.sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);
                this.depthBitmap = new WriteableBitmap(this.sensor.DepthStream.FrameWidth, this.sensor.DepthStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);

                this.img.Source             = this.colorBitmap;
                this.sensor.AllFramesReady += sensor_AllFramesReady;

                try
                {
                    // Start the sensor!
                    this.sensor.Start();
                }
                catch (IOException)
                {
                    // Some other application is streaming from the same Kinect sensor
                    this.sensor = null;
                }
            }

            if (null == this.sensor)
            {
                this.statusBarText.Text = Properties.Resources.NoKinectReady;
                return;
            }

            RecognizerInfo ri = GetKinectRecognizer();

            if (null != ri)
            {
                //recognitionSpans = new List<Span> { forwardSpan, backSpan, rightSpan, leftSpan };

                this.speechEngine = new SpeechRecognitionEngine(ri.Id);


                // Create a grammar from grammar definition XML file.
                using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(Properties.Resources.SpeechGrammar)))
                {
                    var g = new Grammar(memoryStream);
                    speechEngine.LoadGrammar(g);
                }

                speechEngine.SpeechRecognized          += SpeechRecognized;
                speechEngine.SpeechRecognitionRejected += SpeechRejected;


                speechEngine.SetInputToAudioStream(
                    sensor.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                speechEngine.RecognizeAsync(RecognizeMode.Multiple);
            }
            else
            {
                this.statusBarText.Text = Properties.Resources.NoSpeechRecognizer;
            }
        }
Example #38
0
        protected override SpeechRecognitionEngine CreateSpeechRecognitionEngine()
        {
            RecognizerInfo kinectRecognizer = KinectV1Utils.GetKinectRecognizer(CultureInfo.GetCultureInfoByIetfLanguageTag("en"));   //use Kinect-based recognition engine

            return((kinectRecognizer != null)? new SpeechRecognitionEngine(kinectRecognizer) : base.CreateSpeechRecognitionEngine()); //fallback to recognition using default audio source
        }
        /// <summary>
        /// Execute initialization tasks.
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            // Look through all sensors and start the first connected one.
            // This requires that a Kinect is connected at the time of app startup.
            // To make your app robust against plug/unplug,
            // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit
            foreach (var potentialSensor in KinectSensor.KinectSensors)
            {
                if (potentialSensor.Status == KinectStatus.Connected)
                {
                    this.sensor = potentialSensor;
                    break;
                }
            }

            if (null != this.sensor)
            {
                try
                {
                    // Start the sensor!
                    this.sensor.Start();
                }
                catch (IOException)
                {
                    // Some other application is streaming from the same Kinect sensor
                    this.sensor = null;
                }
            }

            if (null == this.sensor)
            {
                this.statusBarText.Text = Properties.Resources.NoKinectReady;
                return;
            }

            RecognizerInfo ri = GetKinectRecognizer();

            if (null != ri)
            {
                recognitionSpans = new List <Span> {
                    forwardSpan, backSpan, rightSpan, leftSpan
                };

                this.speechEngine = new SpeechRecognitionEngine(ri.Id);

                /****************************************************************
                *
                * Use this code to create grammar programmatically rather than from
                * a grammar file.
                *
                * var directions = new Choices();
                * directions.Add(new SemanticResultValue("forward", "FORWARD"));
                * directions.Add(new SemanticResultValue("forwards", "FORWARD"));
                * directions.Add(new SemanticResultValue("straight", "FORWARD"));
                * directions.Add(new SemanticResultValue("backward", "BACKWARD"));
                * directions.Add(new SemanticResultValue("backwards", "BACKWARD"));
                * directions.Add(new SemanticResultValue("back", "BACKWARD"));
                * directions.Add(new SemanticResultValue("turn left", "LEFT"));
                * directions.Add(new SemanticResultValue("turn right", "RIGHT"));
                *
                * var gb = new GrammarBuilder { Culture = ri.Culture };
                * gb.Append(directions);
                *
                * var g = new Grammar(gb);
                *
                ****************************************************************/

                // Create a grammar from grammar definition XML file.
                using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(Properties.Resources.SpeechGrammar)))
                {
                    var g = new Grammar(memoryStream);
                    speechEngine.LoadGrammar(g);
                }

                speechEngine.SpeechRecognized          += SpeechRecognized;
                speechEngine.SpeechRecognitionRejected += SpeechRejected;

                speechEngine.SetInputToAudioStream(
                    sensor.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                speechEngine.RecognizeAsync(RecognizeMode.Multiple);
            }
            else
            {
                this.statusBarText.Text = Properties.Resources.NoSpeechRecognizer;
            }
        }
Example #40
0
        private static SpeechRecognitionEngine CreateSpeechRecognizer()
        {
            RecognizerInfo ri = GetKinectRecognizer();

            if (ri == null)
            {
                Console.WriteLine("There was a problem initializing Speech Recognition." +
                                  "Ensure you have the Microsoft Speech SDK installed." +
                                  "Failed to load Speech SDK");
                return(null);
            }

            SpeechRecognitionEngine sre;

            try
            {
                sre = new SpeechRecognitionEngine(ri.Id);
            }
            catch
            {
                Console.WriteLine("There was a problem initializing Speech Recognition." +
                                  "Ensure you have the Microsoft Speech SDK installed and configured." +
                                  "Failed to load Speech SDK");
                return(null);
            }

            var grammar = new Choices();

            //grammar.Add("red");
            //grammar.Add("green");
            //grammar.Add("blue");
            //grammar.Add("eric");
            //grammar.Add("stop");
            //grammar.Add("hello world");
            grammar.Add("The");
            grammar.Add("quick");
            grammar.Add("brown");
            grammar.Add("fox");
            grammar.Add("jumps");
            grammar.Add("over");
            grammar.Add("the");
            grammar.Add("lazy");
            grammar.Add("dog");
            grammar.Add("super");


            var gb = new GrammarBuilder {
                Culture = ri.Culture
            };

            gb.Append(grammar);

            var g = new Grammar(gb);

            sre.LoadGrammar(g);
            sre.SpeechRecognized          += new EventHandler <SpeechRecognizedEventArgs>(sre_SpeechRecognized);
            sre.SpeechHypothesized        += new EventHandler <SpeechHypothesizedEventArgs>(sre_SpeechHypothesized);
            sre.SpeechRecognitionRejected += new EventHandler <SpeechRecognitionRejectedEventArgs>(sre_SpeechRecognitionRejected);

            return(sre);
        }
Example #41
0
        private SpeechRecognitionEngine CreateSpeechRecognizer()
        {

            RecognizerInfo ri = GetKinectRecognizer();

            if (ri == null)
            {
                System.Windows.MessageBox.Show(
                    @"There was a problem initializing Speech Recognition.
Ensure you have the Microsoft Speech SDK installed.",
                    "Failed to load Speech SDK",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
                this.Close();
                return null;
            }

            //SpeechRecognitionEngine sre;
            try
            {
                speechRecognizer = new SpeechRecognitionEngine(ri.Id);
                //speechRecognizer = SelectRecognizer("Kinect");
            }
            catch
            {
                System.Windows.MessageBox.Show(
                    @"There was a problem initializing Speech Recognition.
Ensure you have the Microsoft Speech SDK installed and configured.",
                    "Failed to load Speech SDK",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
                this.Close();
                return null;
            }

            var grammar = new Choices();
            grammar.Add("start");
            grammar.Add("pick");
            grammar.Add("select");
            grammar.Add("a");
            grammar.Add("navigate");
            grammar.Add("b");
            grammar.Add("move");
            grammar.Add("stop");
            grammar.Add("hold");
            grammar.Add("synchronize");

            var gb = new GrammarBuilder {};
            gb.Append(grammar);

            // Create the actual Grammar instance, and then load it into the speech recognizer.
            var g = new Grammar(gb);

            speechRecognizer.LoadGrammar(g);
            speechRecognizer.SpeechRecognized += this.SreSpeechRecognized;
            speechRecognizer.SpeechHypothesized += SreSpeechHypothesized;
            speechRecognizer.SpeechRecognitionRejected += SreSpeechRecognitionRejected;

            kinectSource = kinectSensorT.AudioSource;
            kinectSource.BeamAngleMode = BeamAngleMode.Adaptive;
            kinectSource.EchoCancellationMode = EchoCancellationMode.None; // No AEC for this sample
            kinectSource.AutomaticGainControlEnabled = false; // Important to turn this off for speech recognition

            st = kinectSource.Start();

            //System.Windows.MessageBox.Show("audio source started");

            speechRecognizer.SetInputToAudioStream(st,
                  new SpeechAudioFormatInfo(
                      EncodingFormat.Pcm, 16000, 16, 1,
                      32000, 2, null));
            speechRecognizer.RecognizeAsync(RecognizeMode.Multiple);

            return speechRecognizer;
        }
Example #42
0
        private void Setup(string ip, string language, string grammar)
        {
            if (this.client == null)
            {
                this.client = new MqttClient(ip);
                this.client.ProtocolVersion         = MqttProtocolVersion.Version_3_1;
                this.client.MqttMsgPublishReceived += this.TextToSpeech;
                this.client.Subscribe(new string[] { ttsTopic }, new byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
                this.client.Connect(Guid.NewGuid().ToString());
            }

            if (this.dictationSpeechEngine == null)
            {
                try {
                    this.dictationSpeechEngine = new SpeechRecognitionEngine(new System.Globalization.CultureInfo(language));
                    this.dictationSpeechEngine.SpeechRecognized += this.DicatationSpeechRecognition_SpeechRecognized;
                    this.dictationSpeechEngine.LoadGrammar(new DictationGrammar());
                    this.dictationSpeechEngine.SetInputToDefaultAudioDevice();
                    this.dictationSpeechEngine.RecognizeAsync(RecognizeMode.Multiple);
                } catch { this.LanguageStatus.Text = "failed load dictation engine"; }
            }

            if (this.templateSpeechEngine == null)
            {
                RecognizerInfo ri = null;
                try {
                    foreach (RecognizerInfo recognizer in SpeechRecognitionEngine.InstalledRecognizers())
                    {
                        if (language.Equals(recognizer.Culture.Name, StringComparison.OrdinalIgnoreCase))
                        {
                            ri = recognizer;
                            break;
                        }
                    }

                    this.templateSpeechEngine = new SpeechRecognitionEngine(ri.Id);
                    string exe = Assembly.GetExecutingAssembly().Location;
                    grammar = exe.Substring(0, exe.LastIndexOf('\\')) + @"\..\..\Grammar\" + grammar;

                    if (File.Exists(grammar))
                    {
                        try {
                            this.templateSpeechEngine.LoadGrammar(new Grammar(grammar));
                            this.templateSpeechEngine.SpeechRecognized          += this.TemplateSpeechRecognition_FrameArrived;
                            this.templateSpeechEngine.SpeechRecognitionRejected += this.TemplateSpeechRecognition_Rejected;
                            this.templateSpeechEngine.SetInputToDefaultAudioDevice();
                            this.templateSpeechEngine.RecognizeAsync(RecognizeMode.Multiple);
                        }
                        catch { this.GrammarStatus.Text = "failed load template engine"; }
                    }
                    else
                    {
                        this.GrammarStatus.Text = "failed load grammar file";
                    }
                } catch { this.GrammarStatus.Text = "recognizer is null"; }
            }

            if (this.speechSynthesizer == null)
            {
                this.speechSynthesizer = new SpeechSynthesizer();
                this.speechSynthesizer.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Teen);
                this.speechSynthesizer.SetOutputToDefaultAudioDevice();
                this.speechSynthesizer.SpeakCompleted += this.SpeechEnd_FrameArrived;
            }

            if (this.kinectSensor == null)
            {
                this.kinectSensor = KinectSensor.GetDefault();

                AudioSource audioSource = this.kinectSensor.AudioSource;
                this.audioReader = audioSource.OpenReader();
                this.audioReader.FrameArrived += this.Audio_FrameArrived;
                this.kinectSensor.Open();
            }

#if PRINT_STATUS_MESSAGE
            this.appClock.Start();
#endif
        }
Example #43
0
        private void StartSpeechRecognition(RecognizerInfo ri)
        {
            this.speechEngine = new SpeechRecognitionEngine(ri.Id);
            using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(File.ReadAllText("SpeechGrammar.xml"))))
            {
                var g = new Grammar(memoryStream);
                this.speechEngine.LoadGrammar(g);
            }

            this.speechEngine.SpeechRecognized += this.SpeechRecognized;
            this.speechEngine.SpeechRecognitionRejected += this.SpeechRejected;

            this.speechEngine.SetInputToAudioStream(
                 this.kinect.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
            this.speechEngine.RecognizeAsync(RecognizeMode.Multiple);
        }
        /// <summary>
        /// Execute initialization tasks.
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            // Only one sensor is supported
            this.kinectSensor = KinectSensor.GetDefault();

            if (this.kinectSensor != null)
            {
                // open the sensor
                this.kinectSensor.Open();

                // grab the audio stream
                IReadOnlyList <AudioBeam> audioBeamList = this.kinectSensor.AudioSource.AudioBeams;
                System.IO.Stream          audioStream   = audioBeamList[0].OpenInputStream();

                // create the convert stream
                this.convertStream = new KinectAudioStream(audioStream);
            }
            else
            {
                // on failure, set the status text
                this.statusBarText.Text = Properties.Resources.NoKinectReady;
                return;
            }

            RecognizerInfo ri = TryGetKinectRecognizer();

            if (null != ri)
            {
                this.recognitionSpans = new List <Span> {
                    forwardSpan, backSpan, rightSpan, leftSpan
                };

                this.speechEngine = new SpeechRecognitionEngine(ri.Id);

                /****************************************************************
                *
                * Use this code to create grammar programmatically rather than from
                * a grammar file.
                *
                * var directions = new Choices();
                * directions.Add(new SemanticResultValue("forward", "FORWARD"));
                * directions.Add(new SemanticResultValue("forwards", "FORWARD"));
                * directions.Add(new SemanticResultValue("straight", "FORWARD"));
                * directions.Add(new SemanticResultValue("backward", "BACKWARD"));
                * directions.Add(new SemanticResultValue("backwards", "BACKWARD"));
                * directions.Add(new SemanticResultValue("back", "BACKWARD"));
                * directions.Add(new SemanticResultValue("turn left", "LEFT"));
                * directions.Add(new SemanticResultValue("turn right", "RIGHT"));
                *
                * var gb = new GrammarBuilder { Culture = ri.Culture };
                * gb.Append(directions);
                *
                * var g = new Grammar(gb);
                *
                ****************************************************************/

                // Create a grammar from grammar definition XML file.
                using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(Properties.Resources.SpeechGrammar)))
                {
                    var g = new Grammar(memoryStream);
                    this.speechEngine.LoadGrammar(g);
                }

                this.speechEngine.SpeechRecognized          += this.SpeechRecognized;
                this.speechEngine.SpeechRecognitionRejected += this.SpeechRejected;

                // let the convertStream know speech is going active
                this.convertStream.SpeechActive = true;

                // For long recognition sessions (a few hours or more), it may be beneficial to turn off adaptation of the acoustic model.
                // This will prevent recognition accuracy from degrading over time.
                ////speechEngine.UpdateRecognizerSetting("AdaptationOn", 0);

                this.speechEngine.SetInputToAudioStream(
                    this.convertStream, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                this.speechEngine.RecognizeAsync(RecognizeMode.Multiple);
            }
            else
            {
                this.statusBarText.Text = Properties.Resources.NoSpeechRecognizer;
            }
        }
Example #45
0
        /// <summary>
        /// Execute startup tasks
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            // Create the drawing group we'll use for drawing
            this.drawingGroup = new DrawingGroup();
            // Create an image source that we can use in our image control
            this.imageSource = new DrawingImage(this.drawingGroup);
            // Display the drawing using our image control
            Image.Source = this.imageSource;

            // Look through all sensors and start the first connected one.
            // This requires that a Kinect is connected at the time of app startup.
            // To make your app robust against plug/unplug,
            // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit (See components in Toolkit Browser).
            foreach (var potentialSensor in KinectSensor.KinectSensors)
            {
                if (potentialSensor.Status == KinectStatus.Connected)
                {
                    this.sensor = potentialSensor;
                    break;
                }
            }

            if (null != this.sensor)
            {
                // Turn on the skeleton stream to receive skeleton frames
                this.sensor.SkeletonStream.Enable();

                // Add an event handler to be called whenever there is new color frame data
                this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;

                // Start the sensor!
                try
                {
                    this.sensor.Start();
                }
                catch (IOException)
                {
                    this.sensor = null;
                }
            }

            if (null == this.sensor)
            {
                this.statusBarText.Text = Properties.Resources.NoKinectReady;
            }
            RecognizerInfo ri = (from recognizer in SpeechRecognitionEngine.InstalledRecognizers()
                                 where "en-US".Equals(recognizer.Culture.Name, StringComparison.OrdinalIgnoreCase)
                                 select recognizer).FirstOrDefault();

            if (ri != null)
            {
                this.speechEngine = new SpeechRecognitionEngine(ri.Id);
                var color = new Choices();
                color.Add(new SemanticResultValue("RED", "Red"));
                color.Add(new SemanticResultValue("BLUE", "Blue"));
                color.Add(new SemanticResultValue("GREEN", "Green"));
                color.Add(new SemanticResultValue("YELLOW", "Yellow"));
                color.Add(new SemanticResultValue("QUIT", "Quit"));
                var gb = new GrammarBuilder();
                gb.Culture = ri.Culture;
                gb.Append(color);
                var g = new Grammar(gb);
                speechEngine.LoadGrammar(g);
                this.speechEngine.SpeechRecognized += new EventHandler <SpeechRecognizedEventArgs>(speechEngine_SpeechRecognized); speechEngine.SetInputToAudioStream(sensor.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000,
                                                                                                                                                                                                                            16, 1, 32000, 2, null));
                speechEngine.RecognizeAsync(RecognizeMode.Multiple);
            }
            //content.Text = "1. put your left hand over your shoulder, then use your right hand to draw a shape";
        }
Example #46
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            List <string>   words    = (List <string>)e.Argument;
            ProgessResponse response = new ProgessResponse()
            {
            };

            using (var source = new KinectAudioSource())
            {
                source.FeatureMode          = true;
                source.AutomaticGainControl = false;                        //Important to turn this off for speech recognition
                source.SystemMode           = SystemMode.OptibeamArrayOnly; //No AEC for this sample

                RecognizerInfo ri = SpeechRecognitionEngine.InstalledRecognizers().Where(r => r.Id == RecognizerId).FirstOrDefault();

                if (ri == null)
                {
                    response.Message = "Could not find speech recognizer: {0}. Please refer to the sample requirements." + RecognizerId;
                    backgroundWorker1.ReportProgress(0, response);
                    return;
                }

                response.Message = "Using: {0}" + ri.Name;
                backgroundWorker1.ReportProgress(0, response);

                using (var sre = new SpeechRecognitionEngine(ri.Id))
                {
                    var wordChoices = new Choices();

                    foreach (string word in words)
                    {
                        wordChoices.Add(word);
                        //backgroundWorker1.ReportProgress(0, "added: " + word);
                    }


                    response.Message = "speech listener started";
                    backgroundWorker1.ReportProgress(0, response);



                    var gb = new GrammarBuilder();
                    //Specify the culture to match the recognizer in case we are running in a different culture.
                    gb.Culture = ri.Culture;
                    gb.Append(wordChoices);

                    // Create the actual Grammar instance, and then load it into the speech recognizer.
                    var g = new Grammar(gb);

                    sre.LoadGrammar(g);
                    sre.SpeechRecognized          += SreSpeechRecognized;
                    sre.SpeechHypothesized        += SreSpeechHypothesized;
                    sre.SpeechRecognitionRejected += SreSpeechRecognitionRejected;

                    using (Stream s = source.Start())
                    {
                        sre.SetInputToAudioStream(s, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                        sre.RecognizeAsync(RecognizeMode.Multiple);

                        bool cancel = false;
                        while (cancel == false)
                        {
                            if (backgroundWorker1.CancellationPending)
                            {
                                // Set the e.Cancel flag so that the WorkerCompleted event
                                // knows that the process was cancelled.
                                e.Cancel = true;
                                cancel   = true;
                                break;
                            }

                            Thread.Sleep(10);
                        }
                        sre.RecognizeAsyncStop();
                    }
                }
            }
        }
Example #47
0
        ///
        /// VOZ
        ///
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            // Look through all sensors and start the first connected one.
            // This requires that a Kinect is connected at the time of app startup.
            // To make your app robust against plug/unplug,
            // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit (See components in Toolkit Browser).
            foreach (var potentialSensor in KinectSensor.KinectSensors)
            {
                if (potentialSensor.Status == KinectStatus.Connected)
                {
                    this.sensor = potentialSensor;
                    break;
                }
            }

            if (null != this.sensor)
            {
                // Turn on the skeleton stream to receive skeleton frames
                this.sensor.SkeletonStream.Enable();

                // Add an event handler to be called whenever there is new color frame data
                this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;

                myKinect = KinectSensor.KinectSensors[0];
                myKinect.ColorStream.Enable();
                myKinect.ColorFrameReady += myKinect_ColorFrameReady;
                // Start the sensor!
                try
                {
                    this.sensor.Start();
                }
                catch (IOException)
                {
                    this.sensor = null;
                }
            }
            //---------------------VOZ

            //Gramatica correspondiente a los comandos de voz
            RecognizerInfo ri = GetKinectRecognizer();

            if (null != ri)
            {
                this.speechEngine = new SpeechRecognitionEngine(ri.Id);

                // Use this code to create grammar programmatically rather than froma grammar file.
                var directions = new Choices();
                directions.Add(new SemanticResultValue("izquierdo", "CLICKIZQ"));
                directions.Add(new SemanticResultValue("derecho", "CLICKDER"));
                directions.Add(new SemanticResultValue("foto", "CAPTURA"));
                directions.Add(new SemanticResultValue("arriba", "ARRIBA"));
                directions.Add(new SemanticResultValue("abajo", "ABAJO"));
                directions.Add(new SemanticResultValue("cambio", "CAMBIO"));
                directions.Add(new SemanticResultValue("sube", "SUBE"));
                directions.Add(new SemanticResultValue("baja", "BAJA"));
                directions.Add(new SemanticResultValue("salir", "SALIR"));

                var gb = new GrammarBuilder {
                    Culture = ri.Culture
                };
                gb.Append(directions);

                var g = new Grammar(gb);

                /*
                 ****************************************************************/

                // Create a grammar from grammar definition XML file.
                //using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(Properties.Resources.SpeechGrammar)))
                //{
                //    var g = new Grammar(memoryStream);
                speechEngine.LoadGrammar(g);
                //}

                speechEngine.SpeechRecognized += SpeechRecognized;
                //speechEngine.SpeechRecognitionRejected += SpeechRejected;

                // For long recognition sessions (a few hours or more), it may be beneficial to turn off adaptation of the acoustic model.
                // This will prevent recognition accuracy from degrading over time.
                ////speechEngine.UpdateRecognizerSetting("AdaptationOn", 0);

                speechEngine.SetInputToAudioStream(
                    sensor.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                speechEngine.RecognizeAsync(RecognizeMode.Multiple);
            }
            //VOZ
        }
Example #48
0
        void conectaActiva()
        {
            //Nos aseguramos que la cuenta de sensores conectados sea de al menos 1
            if (KinectSensor.KinectSensors.Count > 0)
            {
                //Checamos que la variable _sensor sea nula
                if (this.sensor == null)
                {
                    //Asignamos el primer sensor Kinect a nuestra variable
                    this.sensor = KinectSensor.KinectSensors[0];
                    if (this.sensor != null)
                    {
                        try
                        {
                            //Iniciamos el dispositivo Kinect
                            this.sensor.Start();
                            //Esto es opcional pero ayuda a colocar el dispositivo Kinect a un cierto angulo de inclinacion, desde -27 a 27
                            //   sensor.ElevationAngle = 3;
                            //Informamos que se ha conectado e inicializado correctamente el dispositivo Kinect
                            //  Error err = new VME.Error(RecursosLocalizables.StringResources.KinectDetect, 3);
                            // err.Show();
                        }
                        catch (Exception ex)
                        {
                        }

                        //Creamos esta variable ri que tratara de encontrar un language pack valido haciendo uso del metodo obtenerLP
                        RecognizerInfo ri = obtenerLP();

                        //Si se encontro el language pack requerido lo asignaremos a nuestra variable speechengine
                        if (ri != null)
                        {
                            this.speechengine = new SpeechRecognitionEngine(ri.Id);
                            //Creamos esta variable opciones la cual almacenara las opciones de palabras o frases que podran ser reconocidas por el dispositivo
                            Choices opciones = new Choices();
                            //Comenzamos a agregar las opciones comenzando por el valor de opcion que tratamos reconocer y una llave que identificara a ese valor
                            //Por ejemplo en esta linea "uno" es el valor de opcion y "UNO" es la llave

                            opciones.Add(RecursosLocalizables.StringResources.cerrar, "UNO");
                            //En esta linea "dos" es el valor de opcion y "DOS" es la llave
                            opciones.Add(RecursosLocalizables.StringResources.Reflexes, "DOS");
                            opciones.Add(RecursosLocalizables.StringResources.configuracion, "TRES");
                            opciones.Add(RecursosLocalizables.StringResources.opciones, "TRES");
                            opciones.Add(RecursosLocalizables.StringResources.usuario, "TRES");
                            opciones.Add(RecursosLocalizables.StringResources.acercaDe1, "TRES");
                            opciones.Add(RecursosLocalizables.StringResources.tabInformacion, "TRES");
                            //En esta linea "windows ocho" es el valor de opcion y "TRES" es la llave y asi sucesivamente
                            opciones.Add(new SemanticResultValue("windows", "TRES"));
                            opciones.Add(new SemanticResultValue("new windows", "TRES"));

                            //Esta variable creará todo el conjunto de frases y palabras en base a nuestro lenguaje elegido en la variable ri
                            var grammarb = new GrammarBuilder {
                                Culture = ri.Culture
                            };
                            //Agregamos las opciones de palabras y frases a grammarb
                            grammarb.Append(opciones);
                            //Creamos una variable de tipo Grammar utilizando como parametro a grammarb
                            var grammar = new Grammar(grammarb);
                            //Le decimos a nuestra variable speechengine que cargue a grammar
                            this.speechengine.LoadGrammar(grammar);
                            //mandamos llamar al evento SpeechRecognized el cual se ejecutara cada vez que una palabra sea detectada
                            speechengine.SpeechRecognized += new EventHandler <SpeechRecognizedEventArgs>(speechengine_SpeechRecognized);
                            //speechengine inicia la entrada de datos de tipo audio
                            speechengine.SetInputToAudioStream(sensor.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                            speechengine.RecognizeAsync(RecognizeMode.Multiple);
                        }
                    }
                }
            }
        }
Example #49
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            //initialize Kinect SDK

            nui = Runtime.Kinects[0];

            nui.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking);

            nui.SkeletonEngine.TransformSmooth = true;

            TransformSmoothParameters param = new TransformSmoothParameters();

            param.Smoothing          = 0.2f;
            param.Correction         = 0.0f;
            param.Prediction         = 0.0f;
            param.JitterRadius       = 0.2f;
            param.MaxDeviationRadius = 0.3f;

            nui.SkeletonEngine.SmoothParameters = param;

            nui.SkeletonFrameReady += new EventHandler <SkeletonFrameReadyEventArgs>(nui_SkeletonFrameReady);

            //setup audio


            RecognizerInfo ri = GetKinectRecognizer();

            if (ri == null)
            {
                Console.WriteLine("Could not find Kinect speech recognizer. Please refer to the sample requirements.");
                return;
            }

            Console.WriteLine("Using: {0}", ri.Name);

            sre = new SpeechRecognitionEngine();

            var models = new Choices();

            models.Add("lander");
            models.Add("flowers");
            models.Add("car");

            var gb = new GrammarBuilder();

            //Specify the culture to match the recognizer in case we are running in a different culture.
            gb.Culture = ri.Culture;
            gb.Append(models);


            // Create the actual Grammar instance, and then load it into the speech recognizer.
            var g = new Grammar(gb);

            sre.LoadGrammar(g);
            sre.SpeechRecognized          += SreSpeechRecognized;
            sre.SpeechHypothesized        += SreSpeechHypothesized;
            sre.SpeechRecognitionRejected += SreSpeechRecognitionRejected;

            source = new KinectAudioSource();

            source.FeatureMode          = true;
            source.AutomaticGainControl = false;
            source.SystemMode           = SystemMode.OptibeamArrayOnly;

            Stream s = source.Start();

            sre.SetInputToAudioStream(s, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));


            Console.WriteLine("Recognizing. Say: 'red', 'green' or 'blue'. Press ENTER to stop");

            sre.RecognizeAsync(RecognizeMode.Multiple);


            handPos[0] = new Vector3(0.0f, 0.0f, 0.0f);
            handPos[1] = new Vector3(0.0f, 0.0f, 0.0f);

            //set up angles
            shiftAngleRemote1 = shiftAngleLocal + 115.3733f;
            shiftAngleRemote2 = shiftAngleLocal - 93.9733f;

            //initialize hand angles
            prevHandYAngle = 0.0f;
            prevHandXAngle = 0.0f;

            //for sphere
            distortion = new Distortion(Vector3.Zero, Vector3.Backward, Vector3.Up, 1, 1);

            //for cylinder
            //distortion = new Distortion(Vector3.Zero, Vector3.Backward, Vector3.Up, 1, 1, distortionShift, 4);

            View = Matrix.CreateLookAt(new Vector3(0, 0, 2), Vector3.Zero,
                                       Vector3.Up);
            Projection = Matrix.CreatePerspectiveFieldOfView(
                MathHelper.PiOver4, 16.0f / 9.0f, 1, 500);

            //setupOSC();

            base.Initialize();
        }
        private void InitializeKinect()
        {
            kinectSensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
            kinectSensor.ColorFrameReady += new EventHandler<ColorImageFrameReadyEventArgs>(kinectSensor_ColorFrameReady);

            try
            {
                kinectSensor.Start();

                // Obtain the KinectAudioSource to do audio capture
                source = kinectSensor.AudioSource;
                source.EchoCancellationMode = EchoCancellationMode.None; // No AEC for this sample
                source.AutomaticGainControlEnabled = false; // Important to turn this off for speech recognition

                ri = GetKinectRecognizer();

                if (ri == null)
                {
                    speechStatus = "Speech is fuxor'd";
                }
                else
                {

                    speechStatus = "using speech and stuff";
                    Console.WriteLine("*** using speech");

                    int wait = 4;
                    while (wait > 0)
                    {
                       wait--;
                       speechStatus = "Device will be ready for speech recognition in " + wait + " seconds.";
                       Thread.Sleep(1000);
                    }

                    kinectSensor.Start();

                }
            }
            catch
            {
                kinectStatus = "Unable to start the Kinect Sensor";

            }
        }
Example #51
0
        public void launchVoiceRecognizer()
        {
            //Get the info of the voice recognizer engine the user wants to use
            //RecognizerInfo recognizer = GetKinectRecognizer();
            RecognizerInfo recognizer = null;
            ReadOnlyCollection <RecognizerInfo> allRecognizers = SpeechRecognitionEngine.InstalledRecognizers();

            for (int i = 0; i < allRecognizers.Count; i++)
            {
                if (allRecognizers[i].Id == server.serverMasterOptions.audioOptions.recognizerEngineID)
                {
                    recognizer = allRecognizers[i];
                    break;
                }
            }
            if (recognizer == null)
            {
                throw new Exception("Couldn't find voice recognizer core.");
            }

            //Wait 4 seconds for the Kinect to be ready, may not be necessary, but the sample does this
            //Thread.Sleep(4000);

            engine = new SpeechRecognitionEngine(server.serverMasterOptions.audioOptions.recognizerEngineID);
            Choices vocab = new Choices();

            for (int i = 0; i < server.serverMasterOptions.voiceCommands.Count; i++)
            {
                vocab.Add(server.serverMasterOptions.voiceCommands[i].recognizedWord);
            }

            GrammarBuilder gb = new GrammarBuilder {
                Culture = recognizer.Culture
            };

            gb.Append(vocab);
            Grammar grammar = new Grammar(gb);

            engine.LoadGrammar(grammar);

            //Setup events
            engine.SpeechRecognized          += new EventHandler <SpeechRecognizedEventArgs>(engine_SpeechRecognized);
            engine.SpeechHypothesized        += new EventHandler <SpeechHypothesizedEventArgs>(engine_SpeechHypothesized);
            engine.SpeechRecognitionRejected += new EventHandler <SpeechRecognitionRejectedEventArgs>(engine_SpeechRecognitionRejected);

            //According to the speech recognition sample, this turns off adaptation of the acoustical mode, which can degrade recognizer accuracy over time
            engine.UpdateRecognizerSetting("AdaptationOn", 0);

            if (server.serverMasterOptions.audioOptions.sourceID >= 0 && server.serverMasterOptions.audioOptions.sourceID < server.kinects.Count)
            {
                KinectAudioSource source = server.kinects[server.serverMasterOptions.audioOptions.sourceID].kinect.AudioSource;
                audioStream = source.Start();
                engine.SetInputToAudioStream(audioStream, new Microsoft.Speech.AudioFormat.SpeechAudioFormatInfo(Microsoft.Speech.AudioFormat.EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
            }
            else
            {
                engine.SetInputToDefaultAudioDevice();
            }

            engine.RecognizeAsync(RecognizeMode.Multiple);
        }
Example #52
0
        /// <summary>
        /// Execute startup tasks
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            brush = Brushes.White;
            // Create the drawing group we'll use for drawing
            this.drawingGroup = new DrawingGroup();

            // Create an image source that we can use in our image control
            this.imageSource = new DrawingImage(this.drawingGroup);

            // Display the drawing using our image control
            Image.Source = this.imageSource;

            // Look through all sensors and start the first connected one.
            // This requires that a Kinect is connected at the time of app startup.
            // To make your app robust against plug/unplug,
            // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit (See components in Toolkit Browser).
            foreach (var potentialSensor in KinectSensor.KinectSensors)
            {
                if (potentialSensor.Status == KinectStatus.Connected)
                {
                    this.sensor = potentialSensor;
                    break;
                }
            }

            if (null != this.sensor)
            {
                // Turn on the skeleton stream to receive skeleton frames
                this.sensor.SkeletonStream.Enable();

                // Add an event handler to be called whenever there is new color frame data
                this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;

                // Start the sensor!
                try
                {
                    this.sensor.Start();
                }
                catch (IOException)
                {
                    this.sensor = null;
                }
            }

            if (null == this.sensor)
            {
                this.statusBarText.Text = "Connect Kinect and try again";
                return;
            }

            //For audio recogninzer
            RecognizerInfo ri = (from recognizer in SpeechRecognitionEngine.InstalledRecognizers() where "en-US".Equals(recognizer.Culture.Name, StringComparison.OrdinalIgnoreCase) select recognizer).FirstOrDefault();

            if (ri != null)
            {
                this.speechEngine = new SpeechRecognitionEngine(ri.Id);
                //var fontsizes = new Choices();
                //fontsizes.Add(new SemanticResultValue("SMALL", "Small"));
                //fontsizes.Add(new SemanticResultValue("MEDIUM", "Medium"));
                //fontsizes.Add(new SemanticResultValue("LARGE", "Large"));

                //gb.Append(fontsizes);

                var colors = new Choices();
                colors.Add("yellow");
                colors.Add("red");
                colors.Add("pink");
                colors.Add("green");
                //colors.Add("quit");

                //var quit = new Choices();
                //quit.Add("quit");

                var gb = new GrammarBuilder();
                gb.Culture = ri.Culture;
                gb.Append(colors);
                //gb.Append(quit);

                var g = new Grammar(gb);
                speechEngine.LoadGrammar(g);

                this.speechEngine.SpeechRecognized += new EventHandler <SpeechRecognizedEventArgs>(speechEngine_SpeechRecognized);
                speechEngine.SetInputToAudioStream(sensor.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                speechEngine.RecognizeAsync(RecognizeMode.Multiple);

                var q = new GrammarBuilder();
                q.Append("quit");
                var quit = new Grammar(q);
                speechEngine.LoadGrammar(quit);
            }
        }
        /// <summary>
        /// 初始化語音辨識
        /// </summary>
        private void InitalizeSpeechRecognition()
        {
            // grab the audio stream
            IReadOnlyList <AudioBeam> audioBeamList = this._sensor.AudioSource.AudioBeams;

            System.IO.Stream audioStream = audioBeamList[0].OpenInputStream();

            // create the convert stream
            this.convertStream = new KinectAudioStream(audioStream);

            //RecognizerInfo
            RecognizerInfo recognizerInfo = RecognizerSelection.TryGetKinectRecognizer();

            if (null != recognizerInfo)
            {
                //Using KinectRecognizer();
                this.speechEngine = new SpeechRecognitionEngine(recognizerInfo.Id);

                var grammarBuilder = new GrammarBuilder {
                    Culture = recognizerInfo.Culture
                };

                //把語音字典放進去
                grammarBuilder.Append(vocabulary.Speech_Dictionary);

                //Grammar
                var grammar = new Grammar(grammarBuilder);

                //載入文法
                this.speechEngine.LoadGrammar(grammar);

                // let the convertStream know speech is going active
                this.convertStream.SpeechActive = true;

                // For long recognition sessions (a few hours or more), it may be beneficial to turn off adaptation of the acoustic model.
                // This will prevent recognition accuracy from degrading over time.
                speechEngine.UpdateRecognizerSetting("AdaptationOn", 0);

                try
                {
                    if (MicrophoneSetting.Microphone_Status)
                    {
                        this.speechEngine.SetInputToDefaultAudioDevice();
                    }
                    else
                    {
                        this.speechEngine.SetInputToAudioStream(this.convertStream, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("輸入設備問題" + e, ToString());
                }

                this.speechEngine.RecognizeAsync(RecognizeMode.Multiple);

                //語音辨識事件,語音辨識拒絕事件
                this.speechEngine.SpeechRecognized          += SpeechRecognized;
                this.speechEngine.SpeechRecognitionRejected += SpeechRejected;
            }
        }
Example #54
0
        private bool createSpeechEngine()
        {
            kinectRecognizerInfo = findKinectRecognizerInfo();

            if (kinectRecognizerInfo == null)
            {
                errorMessage = "Kinect recognizer not found";
                return false;
            }

            try
            {
                recognizer = new SpeechRecognitionEngine(kinectRecognizerInfo);
            }
            catch
            {
                errorMessage = "Speech recognition engine could not be loaded";
                return false;
            }

            return true;
        }
Example #55
0
 public void StartListening(Microsoft.Speech.Recognition.RecognizerInfo recognizerInfo)
 {
     _ri = recognizerInfo;
 }
Example #56
0
        /// <summary>
        /// Execute start up tasks
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            // Onle one sensor is supported
            this.kinectSensor = KinectSensor.GetDefault();

            if (this.kinectSensor != null)
            {
                // open the sensor
                this.kinectSensor.Open();

                // grab the audio stream
                var audioBeamList = this.kinectSensor.AudioSource.AudioBeams;
                var audioStream   = audioBeamList[0].OpenInputStream();

                // create the convert stream
                this.convertStream = new KinectAudioStream(audioStream);
            }
            else
            {
                return;
            }

            RecognizerInfo ri = GetKinectRecognizer();

            if (null != ri)
            {
                this.speechEngine = new SpeechRecognitionEngine(ri.Id);

                /****************************************************************
                *
                * Use this code to create grammar programmatically rather than from
                * a grammar file.
                *
                * var directions = new Choices();
                * directions.Add(new SemanticResultValue("forward", "FORWARD"));
                * directions.Add(new SemanticResultValue("forwards", "FORWARD"));
                * directions.Add(new SemanticResultValue("straight", "FORWARD"));
                * directions.Add(new SemanticResultValue("backward", "BACKWARD"));
                * directions.Add(new SemanticResultValue("backwards", "BACKWARD"));
                * directions.Add(new SemanticResultValue("back", "BACKWARD"));
                * directions.Add(new SemanticResultValue("turn left", "LEFT"));
                * directions.Add(new SemanticResultValue("turn right", "RIGHT"));
                *
                * var gb = new GrammarBuilder { Culture = ri.Culture };
                * gb.Append(directions);
                *
                * var g = new Grammar(gb);
                *
                ****************************************************************/

                // Create a grammar from grammar definition XML file.
                using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(Properties.Resources.SpeechGrammar)))
                {
                    var g = new Grammar(memoryStream);
                    this.speechEngine.LoadGrammar(g);
                }

                this.speechEngine.SpeechRecognized += this.SpeechRecognized;

                // let the convertStream know speech is going active
                this.convertStream.SpeechActive = true;

                // For long recognition sessions (a few hours or more), it may be beneficial to turn off adaptation of the acoustic model.
                // This will prevent recognition accuracy from degrading over time.
                ////speechEngine.UpdateRecognizerSetting("AdaptationOn", 0);

                this.speechEngine.SetInputToAudioStream(
                    this.convertStream, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                this.speechEngine.RecognizeAsync(RecognizeMode.Multiple);
            }
            else
            {
                // NoSpeechRecognizer
            }

            // Face detection
            for (int i = 0; i < this.bodyCount; i++)
            {
                if (this.faceFrameReaders[i] != null)
                {
                    // wire handler for face frame arrival
                    this.faceFrameReaders[i].FrameArrived += this.Reader_FaceFrameArrived;
                }
            }

            if (this.bodyFrameReader != null)
            {
                // wire handler for body frame arrival
                this.bodyFrameReader.FrameArrived += this.Reader_BodyFrameArrived;
            }
        }
Example #57
0
        /// \brief Gets the Kinect sensor and initializes it
        /// 
        /// \return boolean. True if sensor is initalized, false otherwise.
        private bool sensorInit()
        {
            // Obtain a KinectSensor if any are available
            sensor = (from sensorToCheck in KinectSensor.KinectSensors where sensorToCheck.Status == KinectStatus.Connected select sensorToCheck).FirstOrDefault();
            if (sensor == null)
            {
                Console.WriteLine("Could not connect to Kinect.");
                return false;
            }

            Console.Write("Sensor Starting ... ");
            sensor.Start();
            Console.WriteLine("Sensor Ready");

            source = sensor.AudioSource; // Obtain the KinectAudioSource to do audio capture and set options
            source.EchoCancellationMode = EchoCancellationMode.CancellationAndSuppression; // No AEC
            source.AutomaticGainControlEnabled = false; // Important to turn this off for speech recognition

            recogInfo = GetKinectRecognizer();

            if (recogInfo == null)
            {
                Console.WriteLine("Could not find Kinect speech recognizer.");
                return false;
            }

            Console.WriteLine("Using: {0}", recogInfo.Name);

            // NOTE: Need to wait 4 seconds for device to be ready right after initialization
            int wait = 4;
            while (wait > 0)
            {
                Console.Write("Device will be ready for speech recognition in {0} second(s).\r", wait--);
                Thread.Sleep(1000);
            }

            Console.WriteLine(); // clear line
            return true;
        }
Example #58
0
        /// <summary>
        ///
        /// </summary>
        public override void StartSpeechRecognition()
        {
            RecognizerInfo ri = GetKinectRecognizer();

            if (null == ri)
            {
                return;
            }

            // Check if selected recognizer is for Kinect
            string value;

            ri.AdditionalInfo.TryGetValue("Kinect", out value);
            IsKinectRecognizer = "True".Equals(value, StringComparison.OrdinalIgnoreCase);


            iSpeechEngine = new SpeechRecognitionEngine(ri.Id);

            // Create a speech recognition grammar based on our speech events
            var  ear       = Properties.Settings.Default.EarManager;
            var  choices   = new Choices();
            bool noChoices = true;

            foreach (EventSpeech e in ear.Events.Where(e => e.GetType() == typeof(EventSpeech)))
            {
                if (!e.Enabled)
                {
                    continue;
                }

                // For each events associates its phrases with its semantic
                string[] phrases = e.Phrases.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                foreach (string phrase in phrases)
                {
                    if (string.IsNullOrWhiteSpace(phrase))
                    {
                        // defensive
                        continue;
                    }
                    choices.Add(new SemanticResultValue(phrase, e.Semantic));
                    noChoices = false;
                }
            }

            if (noChoices)
            {
                // Grammar build throws exception if no choice registered
                // TODO: review error handling in that function.
                // I guess we should have a Try variant.
                return;
            }

            // Set our culture
            Culture = ri.Culture;
            var gb = new GrammarBuilder {
                Culture = ri.Culture
            };

            gb.Append(choices);

            var g = new Grammar(gb);

            iSpeechEngine.LoadGrammar(g);

            iSpeechEngine.SpeechRecognized          += this.SpeechRecognized;
            iSpeechEngine.SpeechRecognitionRejected += this.SpeechRejected;

            // For long recognition sessions (a few hours or more), it may be beneficial to turn off adaptation of the acoustic model.
            // This will prevent recognition accuracy from degrading over time.
            iSpeechEngine.UpdateRecognizerSetting("AdaptationOn", 0);

            iSpeechEngine.SetInputToDefaultAudioDevice();
            iSpeechEngine.RecognizeAsync(RecognizeMode.Multiple);
        }
Example #59
0
        // Execute initialization tasks.

        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            // Look through all sensors and start the first connected one.
            // This requires that a Kinect is connected at the time of app startup.
            // To make your app robust against plug/unplug,
            // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit (See components in Toolkit Browser).
            foreach (var potentialSensor in KinectSensor.KinectSensors)
            {
                if (potentialSensor.Status == KinectStatus.Connected)
                {
                    this.sensor = potentialSensor;
                    break;
                }
            }

            if (null != this.sensor)
            {
                try
                {
                    // Start the sensor
                    this.sensor.Start();
                }
                catch (IOException)
                {
                    // Some other application is streaming from the same Kinect sensor
                    this.sensor = null;
                }
            }

            if (null == this.sensor)
            {
                this.statusBarText.Text = Properties.Resources.NoKinectReady;
                return;
            }

            RecognizerInfo ri = GetKinectRecognizer();

            if (null != ri)
            {
                recognitionSpans = new List <Span> {
                    forwardSpan, backSpan, stopSpan, rightSpan, leftSpan
                };
                //Add the spans relating to the commands to be displayed on the main window
                this.speechEngine = new SpeechRecognitionEngine(ri.Id);

                // Create a grammar from grammar definition XML file.
                using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(Properties.Resources.SpeechGrammar)))
                {
                    var g = new Grammar(memoryStream);
                    speechEngine.LoadGrammar(g);
                }

                speechEngine.SpeechRecognized          += SpeechRecognized;
                speechEngine.SpeechRecognitionRejected += SpeechRejected;

                //For long recognition sessions (a few hours or more), it may be beneficial to turn off adaptation of the acoustic model.
                //This will prevent recognition accuracy from degrading over time.

                speechEngine.SetInputToAudioStream(sensor.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                speechEngine.RecognizeAsync(RecognizeMode.Multiple);
            }
            else
            {
                this.statusBarText.Text = Properties.Resources.NoSpeechRecognizer;
            }
        }
Example #60
0
        private bool InitializeKinect()
       {
           kinect.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
           kinect.ColorFrameReady += new EventHandler<ColorImageFrameReadyEventArgs>(kinectSensor_ColorFrameReady);
           kinect = KinectSensor.KinectSensors.FirstOrDefault();


           try
           {
               kinect.Start();

               source = kinect.AudioSource;
               source.EchoCancellationMode = EchoCancellationMode.None;
               source.AutomaticGainControlEnabled = false;

               ri = GetKinectRecognizer();

               if (ri == null)
               {
                   Console.WriteLine("ri = 0, Kinect audio not working.");
               }
               else
               {
                   Console.WriteLine("*** using speech");

                   int wait = 4;
                   while (wait > 0)
                   {
                       wait--;
                       Console.WriteLine("Device will be ready for speech recognition in " + wait + " seconds.");
                       Thread.Sleep(1000);
                   }
                   kinect.Start();
               }
               kinect.SkeletonStream.Enable(new TransformSmoothParameters()
               {
                   Smoothing = 0.5f,
                   Correction = 0.5f,
                   Prediction = 0.5f,
                   JitterRadius = 0.05f,
                   MaxDeviationRadius = 0.04f
               });
               kinect.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(kinect_SkeletonFrameReady);
           }
           catch
           {
               connectedStatus = "Unable to start the Kinect Sensor";
               return false;
           }
           return true; 

       }