feat: 西班牙语日记学习工具与知识库
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
function initSpeech() {
|
||||
if (!window.speechSynthesis) return;
|
||||
var voices = window.speechSynthesis.getVoices();
|
||||
if (voices.length > 0) return;
|
||||
window.speechSynthesis.onvoiceschanged = function() {};
|
||||
}
|
||||
|
||||
function speakText(text, lang) {
|
||||
if (!text) return;
|
||||
if (!window.speechSynthesis) { return; }
|
||||
if (window.speechSynthesis.getVoices().length === 0) {
|
||||
window.speechSynthesis.onvoiceschanged = function() {
|
||||
doSpeak(text, lang);
|
||||
window.speechSynthesis.onvoiceschanged = null;
|
||||
};
|
||||
window.speechSynthesis.getVoices();
|
||||
return;
|
||||
}
|
||||
doSpeak(text, lang);
|
||||
}
|
||||
|
||||
function doSpeak(text, lang) {
|
||||
window.speechSynthesis.cancel();
|
||||
var utterance = new SpeechSynthesisUtterance(text);
|
||||
var langMap = { 'es': 'es-ES', 'en': 'en-US', 'zh': 'zh-CN' };
|
||||
utterance.lang = langMap[lang] || lang;
|
||||
utterance.rate = 0.9;
|
||||
utterance.pitch = 1;
|
||||
window.speechSynthesis.speak(utterance);
|
||||
}
|
||||
|
||||
if (document.readyState === 'complete') initSpeech();
|
||||
else document.addEventListener('DOMContentLoaded', initSpeech);
|
||||
Reference in New Issue
Block a user