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