예제 #1
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);
            }
        }