Example #1
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();
        }