我有一个包含 6 个问题的问卷。这些是通过 SpeechSynthesis 呈现的。在每个问题之后,我需要等待我将处理的口头答复,然后再提出下一个问题。我的代码是一个尝试。代码确实通过回调。但是,如何依次处理逻辑,'state question','listen','state next question','listen'......
//..ToDo: Because we need verbal response for each question,
//.. we need to change the recognition.onResult call back
function processPromptedInteraction(event)
{
var speechToText = event.results[0][0].transcript;
if (speechToText.includes('yes'))
{ }
else if (speechToText.includes('no'))
{ }
else
{ }
}
var strQuestion = '';
for (i = 0; i < questions[i].length; i++)
{
recognition.onresult = processPromptedInteraction; //.. Callback function
strQuestion = questions[i].question;
say(strQuestion);
}