Exemplo n.º 1
0
 public void SetSpeaker(UWPLocalSpeaker spk)
 {
     Say.Speaker     = (UWPLocalSpeaker)spk;
     SayFast.Speaker = spk;
     Play.Speaker    = spk;
     ShutUp.Speaker  = spk;
     Quiz.Speaker    = spk;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Первоначальная инициализация страницы
        /// </summary>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            var spk = new UWPLocalSpeaker(media, Windows.Media.SpeechSynthesis.VoiceGender.Female);

            Trace("Loading knowlegdebase");
//            var xdoc = XDocument.Load("Robot.kb.xml");
//            RE = XMLRuleEngine.LoadXml(xdoc);
            var filename = "Robot.kb.brc";

            RE = BracketedRuleEngine.LoadBracketedKb(filename);
            RE.SetSpeaker(spk);
            RE.SetExecutor(ExExecutor);
            FaceWaitTimer.Tick  += StartDialog;
            DropoutTimer.Tick   += FaceDropout;
            InferenceTimer.Tick += InferenceStep;

            GpioTimer.Tick += ButtonPressed;
            InitGpio();
            GpioTimer.Start();

            media.MediaEnded += EndSpeech;
            CoreWindow.GetForCurrentThread().KeyDown += KeyPressed;
            await Init();

            LEDMgr = new LEDManager(canvas);
            if (!Config.Headless)
            {
                LEDMgr.AddLED("LE", 8, 8, 0.3, 0.2);
                LEDMgr.AddLED("RE", 8, 8, 0.7, 0.2);
                LEDMgr.AddLED("M", 10, 5, 0.5, 0.8);
                LEDMgr.LEDS["LE"].Load(new LEDImage("eye_blink"));
                LEDMgr.LEDS["RE"].Load(new LEDImage("eye_blink"));
                LEDMgr.LEDS["M"].Load(new LEDImage("mouth_neutral"));
            }
        }
Exemplo n.º 3
0
        private async Task InitLongRunning()
        {
            var spk = new UWPLocalSpeaker(media, Windows.Media.SpeechSynthesis.VoiceGender.Female);

            string localIp = GetLocalIp();

            if (localIp == null)
            {
                localIp = "127.0.0.1";
            }
            if (localIp == "")
            {
                localIp = "127.0.0.1";
            }
            spk.Speak($"мой адрес не дом и не улица, мой адрес {localIp} и точка");
            CoreWindow.GetForCurrentThread().KeyDown += KeyPressed;
            Log.Trace("BEFORE receive actual kb");

            try {
                HttpResponseMessage httpResponseMessage = await httpClient.GetAsync("https://github.com/");

                if (httpResponseMessage.IsSuccessStatusCode)
                {
                    byte[] git_kb = await httpClient.GetByteArrayAsync(Config.GitKBUrl);

                    StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
                    StorageFile   sampleFile    =
                        await storageFolder.CreateFileAsync(Config.GitKBFileName, CreationCollisionOption.ReplaceExisting);

                    await Windows.Storage.FileIO.WriteBytesAsync(sampleFile, git_kb);

                    RE = BracketedRuleEngine.LoadBracketedKb(sampleFile);
                    Log.Trace("Using actual git's config version");
                }
                else
                {
                    //try {
                    //    StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
                    //    StorageFile sampleFile = await storageFolder.GetFileAsync(Config.GitKBFileName);
                    //    RE = BracketedRuleEngine.LoadBracketedKb(sampleFile);
                    //    Log.Trace("Using local git's config version");
                    //    offline = true;
                    //}
                    //catch (Exception) {
                    RE = BracketedRuleEngine.LoadBracketedKb(Config.KBFileName);
                    Log.Trace("Using local nongit config version");
                    offline = true;
                    //}
                }
            }
            catch (Exception)
            {
                //try
                //{
                //    StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
                //    StorageFile sampleFile = await storageFolder.GetFileAsync(Config.GitKBFileName);
                //    RE = BracketedRuleEngine.LoadBracketedKb(sampleFile);
                //    Log.Trace("Using local git's config version");
                //    offline = true;
                //}
                //catch (Exception)
                //{
                RE = BracketedRuleEngine.LoadBracketedKb(Config.KBFileName);
                Log.Trace("Using local nongit config version");
                offline = true;
                //}
            }
            Log.Trace("AFTER receive actual kb");


            RE.SetSpeaker(spk);
            RE.Initialize();
            RE.SetExecutor(ExExecutor);
            FaceWaitTimer.Tick   += StartDialog;
            DropoutTimer.Tick    += FaceDropout;
            PreDropoutTimer.Tick += PreDropout;
            InferenceTimer.Tick  += InferenceStep;
            InitGpio();
            if (gpio != null)
            {
                ArduinoInputTimer.Tick += ArduinoInput;
                ArduinoInputTimer.Start();
            }
            yesNoCancelGPIO.Execute(RE.State);
            media.MediaEnded += EndSpeech;

            // Create face detection
            var def = new FaceDetectionEffectDefinition();

            def.SynchronousDetectionEnabled = false;
            def.DetectionMode                     = FaceDetectionMode.HighPerformance;
            FaceDetector                          = (FaceDetectionEffect)(await MC.AddVideoEffectAsync(def, MediaStreamType.VideoPreview));
            FaceDetector.FaceDetected            += FaceDetectedEvent;
            FaceDetector.DesiredDetectionInterval = TimeSpan.FromMilliseconds(100);
            LogLib.Log.Trace("Ready to start face recognition");
            await MC.StartPreviewAsync();

            LogLib.Log.Trace("Face Recognition Started");
            var props = MC.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview);

            VideoProps           = props as VideoEncodingProperties;
            FaceDetector.Enabled = true;

            InferenceTimer.Start();
        }