Beispiel #1
0
        /// <summary>
        /// Process Face Recognition events
        /// Should only be called if FaceRec is on
        /// </summary>
        /// <param name="faceRecEvent"></param>
        private async void ProcessFaceRecognitionEvent(IFaceRecognitionEvent faceRecEvent)
        {
            try
            {
                string label = faceRecEvent.Label.ToLower();

                ITakePictureResponse takePictureResponse = await _misty.TakePictureAsync(label, false, true, true, null, null);

                if (label == "unknown person")
                {
                    Stream stream      = new MemoryStream((byte[])takePictureResponse.Data.Image);
                    string description = await _azureCognitive.AnalyzeImage(stream);

                    BroadcastDetails($"I see a person, {(string.IsNullOrWhiteSpace(description) ? "but I cannot describe them." : description)}", _defaultVoice);
                }
                else
                {
                    BroadcastDetails($"Hello, {label}!", _defaultVoice);
                }

                //Wait a bit so we don't flood with face events, how about 10 seconds?
                _misty.Wait(10000);
                _misty.RegisterFaceRecognitionEvent(ProcessFaceRecognitionEvent, 100, false, null, null, null);
                _assetWrapper.ShowSystemImage(SystemImage.Amazement);
            }
            catch (Exception ex)
            {
                _misty.SkillLogger.Log("Failed to process the face recognition event.", ex);
            }
        }
        /// <summary>
        /// Callback called when a face is detected or recognized
        /// </summary>
        /// <param name="faceRecEvent"></param>
        private void FaceRecCallback(IFaceRecognitionEvent faceRecEvent)
        {
            string audioFile;

            if (_busyTalking)
            {
                return;
            }

            if (faceRecEvent.Label == "unknown person")
            {
                // Save randomness for future use
                // AudioDetails randomAudio = _audioList[_randomGenerator.Next(0, _audioList.Count - 1)];
                // ImageDetails randomImage = _imageList[_randomGenerator.Next(0, _imageList.Count - 1)];
                _misty.DisplayImage(eyeImages[_randomGenerator.Next(0, eyeImages.Length - 1)], 1, null);
                audioFile = "Misty_Hi.wav";
                if (AudioFileExist(audioFile))
                {
                    _misty.PlayAudio(audioFile, 80, null);
                }
                else
                {
                    _misty.PlayAudio("s_Awe.wav", 80, null);
                }
            }
            else
            {
                if (faceRecEvent.Label == "Daddy")
                {
                    _misty.DisplayImage("e_EcstacyStarryEyed.jpg", 1, null);
                    audioFile = "Misty_Hi_Daddy.wav";
                }
                else
                {
                    _misty.DisplayImage("e_Joy.jpg", 1, null);
                    audioFile = "Misty_Hi.wav";
                }

                if (AudioFileExist(audioFile))
                {
                    _misty.PlayAudio(audioFile, 80, null);
                }
                else
                {
                    _misty.PlayAudio("s_Awe.wav", 80, null);
                }
            }

            if (!_misty.Wait(5000))
            {
                return;
            }
            _misty.DisplayImage("e_DefaultContent.jpg", 1, null);
            if (!_misty.Wait(5000))
            {
                return;
            }
            _misty.RegisterFaceRecognitionEvent(FaceRecCallback, 0, false, null, null, null);
        }
Beispiel #3
0
        /// <summary>
        /// Callback called when a face is detected or recognized
        /// </summary>
        /// <param name="faceRecEvent"></param>
        private void FaceRecCallback(IFaceRecognitionEvent faceRecEvent)
        {
            if (faceRecEvent.Label == "unknown person")
            {
                AudioDetails randomAudio = _audioList[_randomGenerator.Next(0, _audioList.Count - 1)];
                ImageDetails randomImage = _imageList[_randomGenerator.Next(0, _imageList.Count - 1)];
                _misty.DisplayImage(randomImage.Name, 1, null);
                _misty.PlayAudio(randomAudio.Name, 100, null);
            }
            else
            {
                _misty.DisplayImage("e_EcstacyStarryEyed.jpg", 1, null);
                _misty.PlayAudio("sEcstacy.wav", 100, null);
            }

            if (!_misty.Wait(5000))
            {
                return;
            }
            _misty.DisplayImage("e_ContentLeft.jpg", 1, null);
            if (!_misty.Wait(5000))
            {
                return;
            }
            _misty.RegisterFaceRecognitionEvent(FaceRecCallback, 0, false, null, null, null);
        }
        /// <summary>
        /// Register the desired startup events, more may be registered separately as needed
        /// </summary>
        private void RegisterEvents()
        {
            //Voice Rec
            _misty.RegisterKeyPhraseRecognizedEvent(KeyPhraseRecognizedCallback, 0, true, null, null);

            //Face rec
            _misty.RegisterFaceRecognitionEvent(FaceRecCallback, 0, false, null, null, null);

            //Bumps
            _misty.RegisterBumpSensorEvent(BumpCallback, 0, true, null, null, null);

            //Cap touch
            _misty.RegisterCapTouchEvent(CapTouchCallback, 0, true, null, null, null);

            //TOF
            List <TimeOfFlightValidation> tofFrontRightValidations = new List <TimeOfFlightValidation>();

            tofFrontRightValidations.Add(new TimeOfFlightValidation {
                Name = TimeOfFlightFilter.DistanceInMeters, Comparison = ComparisonOperator.LessThanOrEqual, ComparisonValue = 0.15
            });
            tofFrontRightValidations.Add(new TimeOfFlightValidation {
                Name = TimeOfFlightFilter.SensorName, Comparison = ComparisonOperator.Equal, ComparisonValue = TimeOfFlightPosition.FrontRight
            });
            _misty.RegisterTimeOfFlightEvent(TOFRangeCallback, 50, true, tofFrontRightValidations, null, null);

            List <TimeOfFlightValidation> tofFrontLeftValidations = new List <TimeOfFlightValidation>();

            tofFrontLeftValidations.Add(new TimeOfFlightValidation {
                Name = TimeOfFlightFilter.DistanceInMeters, Comparison = ComparisonOperator.LessThanOrEqual, ComparisonValue = 0.15
            });
            tofFrontLeftValidations.Add(new TimeOfFlightValidation {
                Name = TimeOfFlightFilter.SensorName, Comparison = ComparisonOperator.Equal, ComparisonValue = TimeOfFlightPosition.FrontLeft
            });
            _misty.RegisterTimeOfFlightEvent(TOFRangeCallback, 50, true, tofFrontLeftValidations, null, null);

            List <TimeOfFlightValidation> tofBackValidations = new List <TimeOfFlightValidation>();

            tofBackValidations.Add(new TimeOfFlightValidation {
                Name = TimeOfFlightFilter.DistanceInMeters, Comparison = ComparisonOperator.LessThanOrEqual, ComparisonValue = 0.15
            });
            tofBackValidations.Add(new TimeOfFlightValidation {
                Name = TimeOfFlightFilter.SensorName, Comparison = ComparisonOperator.Equal, ComparisonValue = TimeOfFlightPosition.Back
            });
            _misty.RegisterTimeOfFlightEvent(TOFRangeCallback, 50, true, tofBackValidations, null, null);
        }
        /// <summary>
        /// Get the assets and startup some timers to do random movements and other things...
        /// </summary>
        /// <param name="parameters"></param>
        public async void OnStart(object sender, IDictionary <string, object> parameters)
        {
            try
            {
                var deviceInfo = await _misty.GetDeviceInformationAsync();

                if (!_misty.Wait(0))
                {
                    return;
                }

                //Get the audio and image lists for use in the skill
                _audioList = (await _misty.GetAudioListAsync())?.Data;

                if (!_misty.Wait(0))
                {
                    return;
                }
                _imageList = (await _misty.GetImageListAsync())?.Data;


                if (!_misty.Wait(0))
                {
                    return;
                }

                if (_audioList != null && _audioList.Count > 0)
                {
                    AudioDetails randomAudio = _audioList[_randomGenerator.Next(0, _audioList.Count - 1)];
                    _misty.PlayAudio(randomAudio.Name, 100, null);
                }

                if (_imageList != null && _imageList.Count > 0)
                {
                    ImageDetails randomImage = _imageList[_randomGenerator.Next(0, _imageList.Count - 1)];
                    _misty.DisplayImage(randomImage.Name, 1, null);
                }


                if (!_misty.Wait(2000))
                {
                    return;
                }

                _misty.ChangeLED(255, 255, 255, null);

                //Register a number of events
                _misty.RegisterAudioPlayCompleteEvent(AudioPlayCallback, 0, true, null, null);
                _misty.RegisterCapTouchEvent(CapTouchCallback, 0, true, null, null, null);
                _misty.RegisterKeyPhraseRecognizedEvent(KeyPhraseRecognizedCallback, 250, true, null, null);
                _misty.StartKeyPhraseRecognition(null);
                _misty.StartFaceRecognition(null);

                //Create an event with a specific name so we can unregister it when needed using that name
                _misty.RegisterBumpSensorEvent(BumpCallback, 0, true, null, "MyBumpSensorName", null);

                //Register face rec with keepAlive = false, it will need to be reregistered after triggering if the user wants it to run again
                _misty.RegisterFaceRecognitionEvent(FaceRecCallback, 0, false, null, null, null);

                //Play audio indicator that the event registration state has changed
                if (_audioList != null && _audioList.Count > 0)
                {
                    AudioDetails randomAudio = _audioList[_randomGenerator.Next(0, _audioList.Count - 1)];
                    _misty.PlayAudio(randomAudio.Name, 100, null);
                    await Task.Delay(1000);

                    _misty.PlayAudio(randomAudio.Name, 100, null);
                }

                if (!_misty.Wait(30000))
                {
                    return;
                }


                //Unregister the bump sensor
                _misty.UnregisterEvent("MyBumpSensorName", UnregisterCallback);

                //Play audio indicator that the event registration state has changed
                if (_audioList != null && _audioList.Count > 0)
                {
                    AudioDetails randomAudio = _audioList[_randomGenerator.Next(0, _audioList.Count - 1)];
                    _misty.PlayAudio(randomAudio.Name, 100, null);
                    await Task.Delay(1000);

                    _misty.PlayAudio(randomAudio.Name, 100, null);
                }

                if (!_misty.Wait(20000))
                {
                    return;
                }

                //Unregister ALL events
                _misty.UnregisterAllEvents(UnregisterCallback);

                //Play audio indicator that the event registration state has changed
                if (_audioList != null && _audioList.Count > 0)
                {
                    AudioDetails randomAudio = _audioList[_randomGenerator.Next(0, _audioList.Count - 1)];
                    _misty.PlayAudio(randomAudio.Name, 100, null);
                    await Task.Delay(1000);

                    _misty.PlayAudio(randomAudio.Name, 100, null);
                }


                if (!_misty.Wait(20000))
                {
                    return;
                }

                //Play audio indicator that the event registration state has changed
                if (_audioList != null && _audioList.Count > 0)
                {
                    AudioDetails randomAudio = _audioList[_randomGenerator.Next(0, _audioList.Count - 1)];
                    _misty.PlayAudio(randomAudio.Name, 100, null);
                    await Task.Delay(1000);

                    _misty.PlayAudio(randomAudio.Name, 100, null);
                }

                //Re-register events
                _misty.RegisterAudioPlayCompleteEvent(AudioPlayCallback, 0, true, null, null);
                _misty.RegisterFaceRecognitionEvent(FaceRecCallback, 0, false, null, null, null);
                _misty.RegisterCapTouchEvent(CapTouchCallback, 0, true, null, null, null);
                _misty.RegisterKeyPhraseRecognizedEvent(KeyPhraseRecognizedCallback, 0, true, null, null);

                //You can also register events without callbacks, it requires a user to subscribe to that event as follows...
                //Note that this re-registers bump events to play a sound on release, not contact as they were previously handled
                _misty.RegisterBumpSensorEvent(0, true, null, null, null);
                _misty.BumpSensorEventReceived += ProcessBumpEvent;

                //Will continue to process events until timeout of cancel
            }
            catch (Exception ex)
            {
                _misty.SkillLogger.Log($"InteractiveMistySkill : OnStart: => Exception", ex);
            }
        }