private void processSensorConnected(KinectSensor sensor)
 {
     lock (activeSensorLock)
     {
         if (sensor.IsAvailable)
         {
             if (activeSensor == null)
             {
                 activeSensor = sensor;
                 Connected    = true;
                 if (SensorConnected != null)
                 {
                     SensorConnected.Invoke(this);
                 }
             }
         }
         else
         {
             if (activeSensor == sensor)
             {
                 disconnectSensor();
             }
         }
     }
 }
        void sensorManager_SensorConnected(KinectSensorManager sensorManager)
        {
            destroySpeechEngine();

            Console.WriteLine("{0} Found", sensorManager.Type);

            RecognizerInfo ri = GetKinectRecognizer();

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

                var choices = new Choices();

                foreach (var command in commands)
                {
                    //Ignore
                    choices.Add(new SemanticResultValue(command.Item1, "IGNORE"));
                    //Require prefix
                    speechActions.Add(command.Item1, command.Item2);
                    choices.Add(new SemanticResultValue(String.Format(prefix, command.Item1), command.Item1));
                }

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

                var g = new Grammar(gb);

                speechEngine.LoadGrammar(g);

                speechEngine.SpeechRecognized          += speechEngine_SpeechRecognized;
                speechEngine.SpeechRecognitionRejected += speechEngine_SpeechRecognitionRejected;

                // 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(sensorManager.startAudioSource(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                speechEngine.RecognizeAsync(RecognizeMode.Multiple);
            }
            else
            {
                //No recognizer
            }

            if (SensorConnected != null)
            {
                SensorConnected.Invoke();
            }
        }
Esempio n. 3
0
 private void Manager_SensorConnected(KinectSensorManager obj)
 {
     lock (activeSensorLock)
     {
         if (activeSensor == null)
         {
             activeSensor = obj;
             if (SensorConnected != null)
             {
                 SensorConnected.Invoke(this);
             }
         }
     }
 }
Esempio n. 4
0
        private void findSensor()
        {
            if (activeSensor == null)
            {
                KinectSensor localSensor = null;
                // Look through all sensors and start the first connected one.
                foreach (var potentialSensor in KinectSensor.KinectSensors)
                {
                    if (potentialSensor.Status == KinectStatus.Connected)
                    {
                        localSensor = potentialSensor;
                        break;
                    }
                }

                //If a sensor was found start it and enable its skeleton listening.
                if (localSensor != null)
                {
                    // Start the sensor!
                    try
                    {
                        localSensor.Start();
                        CurrentStatus = KinectStatus.Connected;
                    }
                    catch (IOException)
                    {
                        localSensor = null;
                    }

                    activeSensor = localSensor; //Make the class aware of the sensor

                    if (activeSensor != null)
                    {
                        if (SensorConnected != null)
                        {
                            SensorConnected.Invoke(this);
                        }
                    }
                }
            }
        }