예제 #1
0
        private void CheckIfWebcamResolutionChanged(object sender, ElapsedEventArgs e)
        {
            if (Store.Data.Webcam.Source == null)
            {
                changeResolutionTimer?.Stop();
                changeResolutionTimer.Dispose();
                changeResolutionTimer = null;
                return;
            }

            elapsedTimerTime += (int)changeResolutionTimer.Interval;

            if (webcamWidthBeforeChange != Store.Data.Webcam.Source.Width ||
                webcamHeightBeforeChange != Store.Data.Webcam.Source.Height)
            {
                changeResolutionTimer?.Stop();
                changeResolutionTimer.Dispose();
                changeResolutionTimer = null;

                WebcamService.CalculateItemPosition();
            }
            else if (elapsedTimerTime % 1000 == 0)
            {
                WebcamService.CalculateItemPosition();
            }

            if (elapsedTimerTime >= 5000)
            {
                // If it doesn't work in 5 seconds, stop trying
                changeResolutionTimer?.Stop();
                changeResolutionTimer.Dispose();
                changeResolutionTimer = null;
            }
        }
예제 #2
0
        public WebcamWindow()
        {
            InitializeComponent();
            this.DataContext = this;

            EnumerateAndSetWebcams();
            WebcamService.UpdateAudioDevice();
        }
예제 #3
0
        private void MouseButtonUpBehavior()
        {
            if (Store.Data.Webcam.Item != null)
            {
                WebcamService.CalculateItemPosition();
            }

            ResizeMode = ResizeMode.CanResize; // Re-enable resizing on this window. Resizing disabled when mouse is dragged o nthe winform child (in DisplayPanelMoveBehavior)
        }
예제 #4
0
 private static void MouseLeftButtonDownBehavior()
 {
     if (Store.Data.Webcam.Item != null)
     {
         // When moving the webcam, put it outside the bounds of the recording and
         // show the preview instead this avoids a window lag when dragging.
         // Can't set visibility to false cause then the audio will cut out as well.
         WebcamService.SetWebcamItemOffscreen();
     }
 }
예제 #5
0
        // Navigations

        public async Task GoToMenuPage(PersonDto person)
        {
            // Clean up services and messenger
            await VoiceInterface.StopListening();

            await WebcamService.CleanUpAsync();

            Messenger.Default.Unregister(this);

            NavigationService.NavigateTo(ViewModelLocator.MenuPage, person);
        }
예제 #6
0
        private void Window_Closing(object sender, CancelEventArgs e)
        {
            e.Cancel = true;
            Hide();

            wfPanel?.Controls.Remove(itemPreviewPanel);
            itemPreviewPanel?.Dispose();
            itemPreviewPanel = null;
            windowsFormsHostOverlay?.Close();
            windowsFormsHostOverlay = null;

            WebcamService.DestroyObsWebcam();
        }
예제 #7
0
        private async Task TakePicture(string conversID)
        {
            if (!WebcamService.IsInitialized)
            {
                await WebcamService.InitializeCameraAsync();

                await WebcamService.StartCameraPreviewAsync();
            }

            using (var stream = new InMemoryRandomAccessStream())
            {
                ImageEncodingProperties imgFormat = ImageEncodingProperties.CreatePng();

                // create storage file in local app storage
                StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(
                    "AdaPhotoTMP.png",
                    CreationCollisionOption.ReplaceExisting);

                // take photo
                await WebcamService.MediaCapture.CapturePhotoToStorageFileAsync(imgFormat, file);

                FileStream fileStream  = new FileStream(file.Path, FileMode.Open);
                Stream     streamFinal = fileStream.AsRandomAccessStream().AsStream();

                StringConstructorSDK client = new StringConstructorSDK()
                {
                    WebAppUrl = $"{ AppConfig.WebUri}"
                };

                try
                {
                    var activity = new Activity
                    {
                        From = new ChannelAccount("Jean"),
                        Text = "Picture from UWP",
                        Type = ActivityTypes.Message,
                        //Envoyer le stream
                        ChannelData = await client.PictureAnalyseAsync(AppConfig.Vision, streamFinal),
                        //ATTENTION CONVERSID DIFFERENT!!!!!
                        Name = conversID,
                        //Summary = serviceUrl
                    };
                    await _client.Conversations.PostActivityAsync(_conversation.ConversationId, activity);
                }
                catch (HttpRequestException)
                {
                    //Impossible to take picture
                }
            }
        }
예제 #8
0
        private async Task CameraLoadExecute()
        {
            LogHelper.Log <WebcamService>("Je me mets au travail!");

            await WebcamService.InitializeCameraAsync();

            WebcamService.CaptureElement = CaptureElement;

            await WebcamService.StartCameraPreviewAsync();

            if (WebcamService.IsInitialized && await WebcamService.StartFaceDetectionAsync(300))
            {
                WebcamService.FaceDetectionEffect.FaceDetected += OnFaceDetected;
            }
        }
예제 #9
0
        private async Task SolicitExecute()
        {
            if (WebcamService.FaceDetectionEffect != null)
            {
                await WebcamService.StopFaceDetectionAsync();
            }

            LogHelper.Log("Que puis-je faire pour toi?");
            await TtsService.SayAsync("Que puis-je faire pour toi?");

            var str = await VoiceInterface.Listen();

            LogHelper.Log(str);

            var activity = new Activity
            {
                From = new ChannelAccount("Jean"),
                Text = str,
                Type = ActivityTypes.Message
            };

            if (activity.Text == "")
            {
                await TtsService.SayAsync("au revoir");

                connection.OnMessage -= Connection_OnMessage;

                if (WebcamService.FaceDetectionEffect != null)
                {
                    await WebcamService.StopFaceDetectionAsync();
                }

                if (WebcamService.IsInitialized && await WebcamService.StartFaceDetectionAsync(300))
                {
                    WebcamService.FaceDetectionEffect.FaceDetected += OnFaceDetected;
                }

                await VoiceInterface.ListeningHelloAda();
            }
            else
            {
                activity.Text = (activity.Text).Replace('.', ' ');
                activity.Text = (activity.Text).ToLower();

                await _client.Conversations.PostActivityAsync(_conversation.ConversationId, activity);
            }
        }
예제 #10
0
        private ObsData CreateWebcamSettings()
        {
            ObsData webcamSettings = new ObsData();

            webcamSettings.SetString(VideoCapture.VIDEO_DEVICE_ID, selectedWebcam.value);

            int buffering = 2;

            webcamSettings.SetInt(VideoCapture.BUFFERING, buffering); // 0 = Auto, 1 = Enable, 2 = Disable

            // need to check webcam whitelist
            if (Store.Data.Webcam.WebcamSettings.ShouldUseCustomSettings)
            {
                webcamSettings.SetString(VideoCapture.RESOLUTION, Store.Data.Webcam.WebcamSettings.Resolution);
                webcamSettings.SetInt(VideoCapture.RESOLUTION_TYPE, 1);
                webcamSettings.SetInt(VideoCapture.VIDEO_FORMAT, (int)Store.Data.Webcam.WebcamSettings.VideoFormat);
                webcamSettings.SetInt(VideoCapture.FRAME_INTERVAL, Store.Data.Webcam.WebcamSettings.Fps);
            }
            else
            {
                if (selectedWebcamResolution != null)
                {
                    webcamSettings.SetString(VideoCapture.RESOLUTION, selectedWebcamResolution.value);
                    webcamSettings.SetInt(VideoCapture.RESOLUTION_TYPE, 1);
                }
                else
                {
                    var preferredResolution = WebcamService.GetOptimalWebcamResolution(selectedWebcam.dsDeviceValue);

                    if (!string.IsNullOrEmpty(preferredResolution))
                    {
                        webcamSettings.SetString(VideoCapture.RESOLUTION, preferredResolution);
                        webcamSettings.SetInt(VideoCapture.RESOLUTION_TYPE, 1);
                    }
                    else
                    {
                        webcamSettings.Erase(VideoCapture.RESOLUTION);
                        webcamSettings.SetInt(VideoCapture.RESOLUTION_TYPE, 0);
                    }
                }
            }

            webcamSettings.SetBool(VideoCapture.ACTIVATE, true);

            return(webcamSettings);
        }
예제 #11
0
        public override void Execute()
        {
            if (WebcamValue == Store.Data.Webcam.ActiveWebcamValue)
            {
                return;
            }

            var webcam = WebcamService.GetWebcam(WebcamValue);

            if (webcam == null)
            {
                webcam = Store.Data.Webcam.Webcams.FirstOrDefault();
            }

            Store.Data.Webcam.Window.Dispatcher.Invoke(new Action(() =>
            {
                Store.Data.Webcam.Window.SetWebcam(webcam);
            }));
        }
예제 #12
0
        private async void HandleActivity(Activity activity)
        {
            var text        = WebUtility.HtmlDecode(activity.Text);
            var attachments = activity.Attachments;

            if (attachments?.Count > 0)
            {
                var token = new CancellationTokenSource();

                await VoiceInterface.StopListening();

                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                                            async() =>
                {
                    await WebcamService.CleanUpAsync();
                    await GoToCarouselPageExecute(attachments);
                }
                                                                                                            );
            }
            LogHelper.Log(text);
            await TtsService.SayAsync(text);

            if (activity.Name == "End")
            {
                connection.OnMessage -= Connection_OnMessage;

                if (WebcamService.FaceDetectionEffect != null)
                {
                    await WebcamService.StopFaceDetectionAsync();
                }

                if (WebcamService.IsInitialized && await WebcamService.StartFaceDetectionAsync(300))
                {
                    WebcamService.FaceDetectionEffect.FaceDetected += OnFaceDetected;
                }

                await VoiceInterface.ListeningHelloAda();
            }
            else if (activity.Name != "NotFinish")
            {
                await DispatcherHelper.RunAsync(async() => { await SolicitExecute(); });
            }
        }
예제 #13
0
        public override void Execute()
        {
            if (WebcamValue == Store.Data.Webcam.ActiveWebcamValue)
            {
                return;
            }

            Store.Data.Webcam.Window.Dispatcher.Invoke(new Action(() =>
            {
                if (!Left.HasValue || !Top.HasValue)
                {
                    Store.Data.Webcam.Window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                }
                else
                {
                    Store.Data.Webcam.Window.Left = Left.Value;
                    Store.Data.Webcam.Window.Top  = Top.Value;
                }

                Store.Data.Webcam.Window.Show(Width, Height);

                var webcam = WebcamService.GetWebcam(WebcamValue);

                if (webcam == null)
                {
                    webcam = Store.Data.Webcam.Webcams.FirstOrDefault();
                }

                Store.Data.Webcam.Window.SetWebcam(webcam);

                Store.Data.Webcam.Window.mainBorder.Visibility = Visibility.Visible;
                EmitService.EmitEnableWebcamResponse(AvailableCommand.EnableWebcam, Store.Data.Webcam.Window.selectedWebcam.value, true);
            }));

            Store.Data.Webcam.IsWebcamEnabled = true;
        }
 public override void Execute()
 {
     AudioService.UpdateAudioInput(DeviceId);
     WebcamService.UpdateAudioDevice();
 }
예제 #15
0
        protected override async Task OnLoadedAsync()
        {
            await Task.Run(() => { while (!_isDirectLineInitialized)
                                   {
                                   }
                           });

            connection.OnMessage += Connection_OnMessage;

            // Registers to messenger for on screen log messages
            Messenger.Default.Register <LogMessage>(this, async e => await DispatcherHelper.RunAsync(() => LogMessage += e.Message));

            // Begins to listening "hello ada"
            await VoiceInterface.ListeningHelloAda();

            // Registers to messenger to catch messages when a speech recognition result
            // was generated
            Messenger.Default.Register <SpeechResultGeneratedMessage>(this, async e =>
            {
                if (e.Result.Constraint.Tag == "constraint_hello_ada")
                {
                    if (VoiceInterface != null)
                    {
                        await VoiceInterface.StopListening();
                    }

                    LogHelper.Log("Message reçu ;)");
                    LogHelper.Log("Je suis à toi dans un instant");
                    await TtsService.SayAsync("Message reçu, je suis à toi dans un instant");

                    PersonDto person = null;

                    if (WebcamService.FaceDetectionEffect != null)
                    {
                        await WebcamService.StopFaceDetectionAsync();
                        person = (await MakeRecognition())?.FirstOrDefault();
                    }

                    if (person != null)
                    {
                        PersonUpdateDto updateDto = new PersonUpdateDto
                        {
                            PersonId      = person.PersonId,
                            RecognitionId = person.RecognitionId
                        };

                        await VoiceInterface.SayHelloAsync(person);

                        // Update person's name
                        if (person.FirstName == null)
                        {
                            string answer = await VoiceInterface.AskIdentified();

                            if (answer != "non")
                            {
                                string name = await VoiceInterface.AskNameAsync();

                                if (name == null)
                                {
                                    return;
                                }

                                updateDto.FirstName = name;
                                person.FirstName    = name;

                                AdaClient client = new AdaClient()
                                {
                                    WebAppUrl = AppConfig.WebUri
                                };

                                await client.PutPerson(updateDto);
                            }
                        }
                    }
                    else
                    {
                        await TtsService.SayAsync("Bonjour");
                    }
                    await DispatcherHelper.RunAsync(async() => { await SolicitExecute(); });
                }
            });

            //// Prepares capture element to camera feed and load camera
            CaptureElement = new CaptureElement();
            await CameraLoadExecute();
        }