voice.lang.includes('zh') &&
(voice.name.includes('Xiaoxiao') || voice.name.includes('Google') || voice.name.includes('Huihui'))
);
if (zhVoice) {
utterance.voice = zhVoice;
console.log(`使用语音: ${zhVoice.name}`);
} else {
console.warn('未找到特定的高质量中文语音,将使用系统默认中文语音。');
}
utterance.onerror = function(event) {
console.error('朗读发生错误:', event);
};
utterance.onend = function() {
console.log('朗读结束');
};
synth.speak(utterance);
}
// 暂停
document.getElementById('pause').addEventListener('click', () => {
speechSynthesis.pause();
});
// 继续
document.getElementById('resume').addEventListener('click', () => {
speechSynthesis.resume();
});
// 5. 绑定按钮点击事件
document.getElementById('read_txt').addEventListener('click', () => {
const article1 = document.querySelector('#layerF4D44C04EEB038B899478DBDF95197FE .artview_intro');
const article2 = document.querySelector('#layerF4D44C04EEB038B899478DBDF95197FE .artview_detail');
//const article = article1 + article2;
if (!article1 && !article2) {
alert("找不到 article 标签");
return;
}
const content = article1.innerText+article2.innerText;
console.log("准备朗读的内容:", content);
speakText(content);
});
var this_span = 0;
var sharelen = 0;
layer.find('.sourcedata').children("span").not(".bdsharebuttonbox").each(function(){
if($(this).css("display")=="none"){}else{
var shis_spanw = $(this).outerWidth();
this_span = this_span + shis_spanw;
}
})
this_span = this_span + sharelen*28 + 4;
var sourcmax_width = $('.artview_info').width();
if(sourcmax_width==0) sourcmax_width='100%';
layer.find('.sourcedata').width(this_span);
layer.find('.sourcedata').css("max-width",sourcmax_width);
})