예제 #1
0
        public async Task <string> AskReason()
        {
            using (var sttService = new SttService())
            {
                await TtsService.SayAsync(SpeechDictionnary.GetReasonSentence());

                await sttService.AddConstraintAsync(ConstraintsDictionnary.ConstraintForCertification, false);

                await sttService.AddConstraintAsync(ConstraintsDictionnary.ConstraintForMeeting, false);

                await sttService.AddConstraintAsync(ConstraintsDictionnary.ConstraintForSandwichs, false);

                await sttService.AddConstraintAsync(ConstraintsDictionnary.ConstraintForOtherWords);

                var result = await sttService.RecognizeAsync();

                if (result.Confidence != SpeechRecognitionConfidence.Rejected)
                {
                    var firedConstraint = (SpeechRecognitionListConstraint)result.Constraint;
                    return(firedConstraint.Commands.First());
                }

                return("Autre");
            }
        }
예제 #2
0
        public async Task <string> AskNameAsync()
        {
            using (var sttService = new SttService())
            {
                bool   repeat;
                string name;

                do
                {
                    // --> 1 : Asking the name
                    await TtsService.SayAsync(SpeechDictionnary.GetAskNameSentence());

                    await sttService.AddConstraintAsync(ConstraintsDictionnary.GetConstraintForName());

                    var result = await RecognitionWithFallBack(sttService);

                    name = result.Text;

                    // Clean up stt service to clean constraints of prévious recognitions
                    await sttService.CleanConstraintsAsync();

                    // --> 3 : Asking confirmation for the name
                    await sttService.AddConstraintAsync(ConstraintsDictionnary.ConstraintForYes, false);

                    await sttService.AddConstraintAsync(ConstraintsDictionnary.ConstraintForNo, false);

                    await sttService.AddConstraintAsync(ConstraintsDictionnary.ConstraintForAbortWords);

                    await TtsService.SayAsync(SpeechDictionnary.GetYesOrNoSentence(result.Text));

                    result = await RecognitionWithFallBack(sttService);

                    var firedConstraint = (SpeechRecognitionListConstraint)result.Constraint;

                    switch (firedConstraint.Tag)
                    {
                    case "constraint_yes":
                        repeat = false;
                        break;

                    case "constraint_abord_words":
                        name   = null;
                        repeat = false;
                        break;

                    default:
                        repeat = true;
                        break;
                    }

                    await sttService.CleanConstraintsAsync();
                } while (repeat);

                return(name);
            }
        }
예제 #3
0
        public async Task SayDescriptionOfSomeone(PersonDto person)
        {
            if (person == null)
            {
                return;
            }

            var genderSentence = person.Gender == GenderValues.Male ? "un homme" : "une femme";

            await TtsService.SayAsync($"Il semblerait que tu soies {genderSentence} de {person.Age} ans");
        }
예제 #4
0
        public async Task SayHelloAsync(PersonDto person)
        {
            if (person == null)
            {
                return;
            }

            if (person.FirstName == null)
            {
                await TtsService.SayAsync("Bonjour, il semblerait que je ne te connaisse pas.");
            }
            else
            {
                await TtsService.SayAsync($"Bonjour {person.FirstName}");
            }
        }
예제 #5
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);
            }
        }
예제 #6
0
        public async Task SayHelloAsync(PersonDto[] persons)
        {
            if (persons == null)
            {
                return;
            }

            var listPersons = persons
                              .Select(p => p)
                              .Where(p => !string.IsNullOrEmpty(p.FirstName) && p.NbPasses <= 1)
                              .ToArray();

            if (listPersons.Any())
            {
                await TtsService.SayAsync(SpeechDictionnary.GetHelloSentence(listPersons));
            }
        }
예제 #7
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(); });
            }
        }
예제 #8
0
        private static async Task <SpeechRecognitionResult> RecognitionWithFallBack(SttService sttService)
        {
            SpeechRecognitionResult result;

            do
            {
                result = await sttService.RecognizeAsync();

                if (result.Confidence == SpeechRecognitionConfidence.Rejected)
                {
                    await TtsService.SayAsync(SpeechDictionnary.GetNotUnderstoodSentence());
                }
                else
                {
                    break;
                }
            } while (true);

            return(result);
        }
예제 #9
0
        public async Task ListeningWhatToDo()
        {
            await PrepareListening();

            await TtsService.SayAsync(SpeechDictionnary.GetAskWhatToDoSentence());

            await _continuousRecognitionSession.AddConstraintAsync(ConstraintsDictionnary.ConstraintForEvents, false);

            await _continuousRecognitionSession.AddConstraintAsync(ConstraintsDictionnary.ConstraintForAbortWords, false);

            await _continuousRecognitionSession.AddConstraintAsync(ConstraintsDictionnary.ConstraintForSandwichs, false);

            await _continuousRecognitionSession.AddConstraintAsync(ConstraintsDictionnary.ConstraintForCallingSomeone, false);

            await _continuousRecognitionSession.AddConstraintAsync(ConstraintsDictionnary.ConstraintForToDescribeSomeOne, false);

            await _continuousRecognitionSession.AddConstraintAsync(ConstraintsDictionnary.ConstraintForReservation);

            await _continuousRecognitionSession.StartContinuousRecognitionAsync();
        }
예제 #10
0
        public async Task <string> AskIdentified()
        {
            using (var sttService = new SttService())
            {
                await TtsService.SayAsync("Veux tu t'identifier ?");

                await sttService.AddConstraintAsync(ConstraintsDictionnary.ConstraintForYes, false);

                await sttService.AddConstraintAsync(ConstraintsDictionnary.ConstraintForNo);

                var result = await sttService.RecognizeAsync();

                if (result.Confidence != SpeechRecognitionConfidence.Rejected)
                {
                    var firedConstraint = (SpeechRecognitionListConstraint)result.Constraint;
                    return(firedConstraint.Commands.First());
                }

                return("non");
            }
        }
예제 #11
0
        public async Task <PersonDto[]> MakeRecognition()
        {
            AdaClient client = new AdaClient()
            {
                WebAppUrl = AppConfig.WebUri
            };

            using (var stream = new InMemoryRandomAccessStream())
            {
                await WebcamService.MediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);

                await stream.FlushAsync();

                stream.Seek(0);

                try
                {
                    PersonDto[] persons = await DataService.RecognizePersonsAsync(stream.AsStreamForRead());

                    // Logs results on screen
                    if (persons != null)
                    {
                        LogHelper.LogPersons(persons);

                        foreach (PersonDto person in persons)
                        {
                            Guid faceApi       = person.PersonId;
                            var  personMessage = await client.GetPersonByFaceId(faceApi);

                            if (personMessage != null)
                            {
                                List <MessageDto> messages = await client.GetMessageByReceiver(personMessage.PersonId);

                                foreach (MessageDto message in messages)
                                {
                                    if (message.From != null)
                                    {
                                        await TtsService.SayAsync("Bonjour" + person.FirstName + "Tu as un nouveau message de la part de " + message.From);
                                    }
                                    else
                                    {
                                        await TtsService.SayAsync("Bonjour" + person.FirstName + "Tu as un nouveau message ");
                                    }
                                    await TtsService.SayAsync(message.Contenu);

                                    message.IsRead = true;
                                    message.Read   = DateTime.Now;

                                    await client.PutMessage(message);
                                }

                                List <IndicatePassageDto> indicatePassages = await client.GetIndicatePassageByPerson(personMessage.PersonId);

                                foreach (IndicatePassageDto indicatePassage in indicatePassages)
                                {
                                    // need to send message to the person on facebook
                                    try
                                    {
                                        var activity = new Activity
                                        {
                                            From        = new ChannelAccount("Jean"),
                                            Type        = ActivityTypes.Message,
                                            Text        = "Passage person from UWP",
                                            ChannelData = indicatePassage.Firtsname,
                                            Name        = "Passage person from UWP"
                                        };

                                        //await _client.Conversations.PostActivityAsync(indicatePassage.IdFacebookConversation, activity);
                                    }
                                    catch (HttpRequestException)
                                    {
                                        //Impossible to take picture
                                    }

                                    indicatePassage.IsSend = true;
                                    await client.PutIndicatePassage(indicatePassage);
                                }
                            }
                        }
                    }
                    if (persons == null)
                    {
                        LogHelper.Log("Ho, j'ai cru voir quelqu'un :'(");
                    }

                    return(persons);
                }
                catch (HttpRequestException)
                {
                    await TtsService.SayAsync("Veuillez m'excuser je ne suis pas disponible pour le moment. Veuillez ré-éssayer dans quelque secondes");

                    await Task.Delay(5000);

                    return(null);
                }
            }
        }
예제 #12
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();
        }
예제 #13
0
 public async Task SayGoodBye()
 {
     await TtsService.SayAsync("Passe une bonne journée !");
 }
예제 #14
0
 public async Task SayEventsAvailable()
 {
     await TtsService.SayAsync(SpeechDictionnary.GetEventsAvailableSentence());
 }
예제 #15
0
 public async Task SayNotAvailableService()
 {
     await TtsService.SayAsync("Ce service n'est pas encore disponible !");
 }