Javascript getVoices()未在Firefox中列出语音
我正在开发一个需要在web浏览器中使用文本到语音的应用程序。我正在使用HTML5语音合成。在Google Chrome上,代码运行良好,使用| getVoices()|列出所有可用的语音,但在Firefox中根本没有列出任何语音。我正在Firefox 56.0(Ubuntu)上测试我的代码 在互联网上搜索时,我确实遇到了一个StackOverflow,它建议在| onVoiceChanged |事件之后调用getVoices()函数Javascript getVoices()未在Firefox中列出语音,javascript,html,firefox,text-to-speech,speech-synthesis,Javascript,Html,Firefox,Text To Speech,Speech Synthesis,我正在开发一个需要在web浏览器中使用文本到语音的应用程序。我正在使用HTML5语音合成。在Google Chrome上,代码运行良好,使用| getVoices()|列出所有可用的语音,但在Firefox中根本没有列出任何语音。我正在Firefox 56.0(Ubuntu)上测试我的代码 在互联网上搜索时,我确实遇到了一个StackOverflow,它建议在| onVoiceChanged |事件之后调用getVoices()函数 window.speechSynthesis.onvo
window.speechSynthesis.onvoiceschanged = function() {
window.speechSynthesis.getVoices();
...
};
我以上述方式调用该调用,它在Chrome中可以正常工作,但在Firefox上不能
另一个StackOverflow回答建议我在Firefox的about:config中启用| media.webspeech.synth.enabled |,但在我的Firefox中,首选项| media.webspeech.synth.enabled |已设置为true
我查看了MDN文档,该页面上的示例在Firefox中没有运行,但在Chrome中运行良好。我发现Firefox55以后的版本都支持SpeechSynthesis,但它对我不起作用
此外,Mozilla开发者网络还演示了语音合成在我的Firefox上无法工作,但在Google Chrome上运行良好。我在网上广泛搜索了一个解决方案,但没有找到。有人能给我指出正确的方向吗。遇到了同样的问题,下面是我的答案
- 在Firefox Ubuntu 16.04上对我不起作用
- 在virtualbox Windows上工作。声音来自窗户。“微软大卫”就是其中之一
- Chrome可以在Ubuntu上运行,但只有在在线的情况下才能运行。它不会在控制台中显示任何流量,但语音仅在联机时才起作用李>
populateVoiceList()
(下面底部第四行,从):
函数populateVoiceList(){
voices=synth.getVoices();
var selectedIndex=voiceSelect.selectedIndex<0?0:voiceSelect.selectedIndex;
voiceSelect.innerHTML='';
对于(i=0;i
这是我在web应用程序中采用的方法否则我的语音列表永远不会被Firefox填充。这段代码也恰好解决了Safari的类似问题;请参阅。该演示在Fx ESR 53.3.0和当前的56中对我有效,在Win 10上是否调用
.getVoices()
在onvoiceschanged
事件处理程序之外?
function populateVoiceList() {
voices = synth.getVoices();
var selectedIndex = voiceSelect.selectedIndex < 0 ? 0 : voiceSelect.selectedIndex;
voiceSelect.innerHTML = '';
for(i = 0; i < voices.length ; i++) {
var option = document.createElement('option');
option.textContent = voices[i].name + ' (' + voices[i].lang + ')';
if(voices[i].default) {
option.textContent += ' -- DEFAULT';
}
option.setAttribute('data-lang', voices[i].lang);
option.setAttribute('data-name', voices[i].name);
voiceSelect.appendChild(option);
}
voiceSelect.selectedIndex = selectedIndex;
}
populateVoiceList();
if (speechSynthesis.onvoiceschanged !== undefined) {
speechSynthesis.onvoiceschanged = populateVoiceList;
}