發現其中 中文的發音 在部分電腦可以正常發音,有些則不行
之後參考 SpeechSynthesisUtterance、Getting Started with the Speech Synthesis API 修正
// Chrome loads voices asynchronously.
window.speechSynthesis.onvoiceschanged = function(e) {
var synth = window.speechSynthesis;
voices = synth.getVoices();
var voice_1 = document.getElementById('voice_1');
while (voice_1.options.length) {
voice_1.remove(0);
}
var voice_2 = document.getElementById('voice_2');
while (voice_2.options.length) {
voice_2.remove(0);
}
voices.forEach(function(voice, i) {
var opt1 = document.createElement("option");
opt1.textContent = voice.name + ' (' + voice.lang + ")";
opt1.setAttribute('data-lang', voice.lang);
opt1.setAttribute('data-name', voice.name);
if (voice.lang == "en-US") {
opt1.selected = true;
}
voice_1.appendChild(opt1);
});
沒有留言:
張貼留言