SpeechSynthesis API在Firefox上不会说普通话。它不受支持吗?我无法在文档中找到列表。我尝试了几种不同的语言tags。
var msg = new SpeechSynthesisUtterance();
msg.text = '你好';
msg.lang = 'zh';
window.speechSynthesis.speak(msg);
(你应该听到" nihao"如果它有效。它在Chrome上听起来很好,在Safari上听起来 OK 。在Ubuntu上的Firefox 53.0.2上,我听到"信函"。)
答案 0 :(得分:3)
在Windows上,Firefox只有3个声音,都是英语。
我写了一个显示浏览器声音的jsbin:
https://jsbin.com/ginanegoqu/edit?js,output
if ('speechSynthesis' in window) {
// Start an html table for languages details
var text = '<table border=1><tr><th>Default<th>Language<th>Local<th>Name<th>URI</tr>';
// Get voices; add to table markup
function loadVoices() {
var voices = speechSynthesis.getVoices();
voices.forEach(function(voice, i) {
// Add all details to table
text += '<tr><td>' + voice.default + '<td>'
+ voice.lang + '<td>' + voice.localService
+ '<td>' + voice.name + '<td>' + voice.voiceURI;
});
}
loadVoices();
langList.innerHTML = text;
// Chrome loads voices asynchronously.
window.speechSynthesis.onvoiceschanged = function(e) {
loadVoices();
langList.innerHTML = text;
}
}