+
95
-

回答

这个接口获取数据需要一点时间,可以改成异步的

function setSpeech() {
return new Promise(
function (resolve, reject) {
let synth = window.speechSynthesis;
let id;

id = setInterval(() => {
if (synth.getVoices().length !== 0) {
resolve(synth.getVoices());
clearInterval(id);
}
}, 10);
}
)
}

let s = setSpeech();
s.then((voices) => console.log(voices)); // Or any other actions you want to take...


网友回复

我知道答案,我要回答