0

我使用响应式语音(文本到语音),我在数组中创建了一些简单的数据,我用一个承诺循环它但是当我将解决方案放入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

4

2 回答 2

0

我试图超时,它的工作,但我想对此有任何选择

setTimeout(function(){ resolve(); }, 6000);
于 2019-06-25T04:35:37.923 回答
0

您的代码正在运行。更改 responsiveVoice.speak(data[i].textEN, data[i].langEN, { rate: .7, onend: resolve()});responsiveVoice.speak(data[i].textEN, data[i].langEN, { rate: .7, onend: resolve});

于 2019-06-25T05:09:55.483 回答