我使用响应式语音(文本到语音),我在数组中创建了一些简单的数据,我用一个承诺循环它但是当我将解决方案放入onend
响应式语音的方法中时,它并不是语音的结束,它调用下一个数据。请看我的代码。
var data = [
{'textTH': "สวัสดี ค่ะ", 'lang': "Thai Female", 'textEN': "Hello", 'langEN': "US English Female"},
{'textTH': "สวัสดี ค่ะ", 'lang': "Thai Female", 'textEN': "Hello 2", 'langEN': "US English Female"}
];
var j = data.length;
function step2(i){
return new Promise(function(resolve, reject){
if (typeof data[i] == 'undefined'){
reject("out of rang");
}
else{
var runEnglistSpeech = function () {
responsiveVoice.speak(data[i].textEN, data[i].langEN, { rate: .7, onend: resolve()});
console.log("done >>>> " + i);
};
responsiveVoice.speak(data[i].textTH, data[i].lang, { rate: .9, onend: runEnglistSpeech });
}
})
}
(async () => {
for (let i = 0; i < j; i++) {
await step2(i);
}
})();
响应式 CDN => https://code.responsivevoice.org/responsivevoice.js