下面的代码在过去的两个月里一直运行良好,直到昨天它停止读取中文文本,但它可以读取英文文本,尽管lang is zh-CN。显然,它现在只读英语了。我在互联网上搜索了大约一天,做了很多修改和尝试(加载和添加语音,添加Chrome扩展'Chrome Speak‘等),但仍然无法解决这个问题。(Chrome Speak读起来不错,但我不知道如何通过javaScript发送文本)
var repete = 0;
function simpleSpeak(text, callback) {
var u = new SpeechSynthesisUtterance();
u.text = text;
u.lang = 'zh-CN';
u.rate = (repete % 2 == 0) ? 1 : 0.8;
repete++;
u.onerror = function (e) {
alert('error!')
if (callback) {
callback(e);
}
window.speechSynthesis.speak(u);
};你能帮帮我吗?操作系统: Windows Vista,Chrome版本48.0.2564.97 m
发布于 2016-01-30 23:42:11
这似乎与web speech api - speech synthesis .lang property not working有关,因为'pt-BR‘(葡萄牙语)不再起作用。
这里的答案引用了Chromium Issue 582455: SpeechSynthesisUtterance does not change language,并建议直接设置.voice属性的解决方案。
发布于 2016-02-03 15:12:28
我想我解决了这个问题,我希望它也能解决你的问题。在下面的代码中,17代表'zh-CN',代表'pt-BR',15。
var voiceSelected;
function loadVoices() {
var voices = speechSynthesis.getVoices();
voices.forEach(function (voice, i) {
if (i == 17) voiceSelected = voice.name;
});
}
loadVoices();
window.speechSynthesis.onvoiceschanged = function (e) {
loadVoices();
};
function speakTTS(text) {
var laf = new SpeechSynthesisUtterance();
laf.text = text;
laf.volume = 1;
laf.rate = 1;
laf.pitch = 1;
laf.voice = speechSynthesis.getVoices().filter(function (voice) {
return voice.name == voiceSelected;
})[0];
window.speechSynthesis.speak(laf);
}https://stackoverflow.com/questions/35103192
复制相似问题