示例#1
0
        public IEnumerator AskQuestion(QuestionSpec questionSpec)
        {
            _speechRecognizer.Setup(questionSpec.CorrectAnswers);
            yield return(PlayVoice(questionSpec.QuestionElements[QuestionSpec.DefaultKeys.Intro]));

            yield return(PlayVoice(questionSpec.QuestionElements[QuestionSpec.DefaultKeys.BaseQuestion]));

            yield return(_speechRecognizer.Recognize(questionSpec.QuestionElements[QuestionSpec.DefaultKeys.BaseQuestion].Text,
                                                     _questionsSpec.GeneralQuestionsSpec.AnswerListeningDuration));

            if (_speechRecognizer.IsCorrectAnswer())
            {
                OnAnswer?.Invoke(_statisticsInfo
                                 .AddTimeBeforeAnswer(_speechRecognizer.TimeBeforeAnswer)
                                 .AddCorrectAnswerAttempt(1));
                yield return(OnCorrectAnswer(questionSpec));

                yield break;
            }

            yield return(PlayVoice(questionSpec.QuestionElements[QuestionSpec.DefaultKeys.SupportQuestion]));

            yield return(_speechRecognizer.Recognize(questionSpec.QuestionElements[QuestionSpec.DefaultKeys.BaseQuestion].Text,
                                                     _questionsSpec.GeneralQuestionsSpec.AnswerListeningDuration));

            if (_speechRecognizer.IsCorrectAnswer())
            {
                OnAnswer?.Invoke(_statisticsInfo
                                 .AddTimeBeforeAnswer(_speechRecognizer.TimeBeforeAnswer)
                                 .AddCorrectAnswerAttempt(2));
                yield return(OnCorrectAnswer(questionSpec));

                yield break;
            }

            OnAnswer?.Invoke(_statisticsInfo);
            yield return(PlayVoice(questionSpec.QuestionElements[QuestionSpec.DefaultKeys.RepeatOnIncorrect]));
        }