window.speechSynthesis.getVoices()如何工作

时间:2018-11-25 13:01:42

标签: javascript

无法获得此方法的工作方式。我已经尝试过使用eventListener(DOMContentLoaded)和window.onload。我不明白的是这种方法在不同情况下的响应。

// 1)
console.log(window.speechSynthesis,window.speechSynthesis.getVoices()) //Obj, empty Array
// 2)
setTimeout(() => {
    console.log(window.speechSynthesis.getVoices()); //empty Array
}, 10 * 1000);
// 3)
const x = window.speechSynthesis;
setTimeout(() => {
  console.log(window.speechSynthesis.getVoices()); //Array of objects
}, 0);
// 4)
const x = window.speechSynthesis;
console.log(window.speechSynthesis.getVoices()); //empty Array
// 5)
const x = window.speechSynthesis;
for(let i =0;i<10000;i++){
    console.log(i)
}
console.log(window.speechSynthesis.getVoices()); //empty Array

0 个答案:

没有答案