feat: 西班牙语日记学习工具与知识库

This commit is contained in:
guoqingshan
2026-07-31 14:50:37 +08:00
commit 0d5b0919da
15 changed files with 2140 additions and 0 deletions
+33
View File
@@ -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);