我有一个包含6个问题的问卷。这些是通过SpeechSynthesis呈现的。在提出每个问题之后,我需要等待将要处理的口头回答,然后再提出下一个问题。我的代码是一个尝试。代码确实经过回调。但是,如何依次处理逻辑,“陈述问题”,“听”,“陈述下一个问题”,“听” ...
//..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);
}
答案 0 :(得分:0)
$ mpirun -np 4 ./a.out
process 3 took 14s
process 3 performed 875000 computations
process 1 took 15s
process 1 performed 875000 computations
process 2 took 16s
process 2 performed 875000 computations
process 0 took 16s
process 0 performed 875001 computations
-3.74981e+08
$ mpirun -np 3 ./a.out
process 2 took 11s
process 2 performed 1166667 computations
process 1 took 20s
process 1 performed 1166667 computations
process 0 took 20s
process 0 performed 1166667 computations
-3.74981e+08
$ mpirun -np 2 ./a.out
process 0 took 16s
process 0 performed 1750001 computations
process 1 took 16s
process 1 performed 1750000 computations
-3.74981e+08
是异步的,因此您的代码不会等待用户一步一步地回答问题。希望以下解决方案为您服务。让我知道我是否想念一些东西。
注意:由于浏览器的安全性,代码可能无法在此处运行。使用下面的jsfiddle链接运行代码。最终结果请参见浏览器控制台
https://jsfiddle.net/ajai/L8p4aqtr/
events