feat(tts): multi-voice switcher for EN & RU, Irina default voice, punctuation pause normalization and speed calibration
This commit is contained in:
1 parent
7893b353aa
commit
31e105b2c2
11 files changed
+486
-61
No files matched your search
+69
-1
@@ -4,7 +4,7 @@
|
||||
// =======================================================================
|
||||
|
||||
import { api } from './modules/api.js';
|
||||
import { initTheme, openModal, closeModal, showToast } from './modules/ui.js';
|
||||
import { initTheme, openModal, closeModal, showToast, playTextSpeech } from './modules/ui.js';
|
||||
import { initDictionary, loadInitialData } from './modules/dictionary.js';
|
||||
import { initSrs, startSrsTrainingSession, openStatsDashboard } from './modules/srs.js';
|
||||
import { initReader, loadBookshelf, openBook } from './modules/reader.js';
|
||||
@@ -546,6 +546,14 @@ export function initNavigationDrawer() {
|
||||
themeToggle.click();
|
||||
});
|
||||
}
|
||||
const drawerNavVoiceSettings = document.getElementById('drawer-nav-voice-settings');
|
||||
const voiceSettingsModal = document.getElementById('voice-settings-modal');
|
||||
if (drawerNavVoiceSettings && voiceSettingsModal) {
|
||||
drawerNavVoiceSettings.addEventListener('click', () => {
|
||||
closeDrawer();
|
||||
openVoiceSettingsModal();
|
||||
});
|
||||
}
|
||||
if (drawerNavLogout && logoutBtn) {
|
||||
drawerNavLogout.addEventListener('click', () => {
|
||||
closeDrawer();
|
||||
@@ -554,6 +562,63 @@ export function initNavigationDrawer() {
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Voice Settings Modal Controller (TTS)
|
||||
// -----------------------------------------------------------------------
|
||||
function openVoiceSettingsModal() {
|
||||
const voiceSettingsModal = document.getElementById('voice-settings-modal');
|
||||
if (!voiceSettingsModal) return;
|
||||
const currentRu = localStorage.getItem('notes_tts_voice_ru') || 'ru_RU-irina';
|
||||
const currentEn = localStorage.getItem('notes_tts_voice_en') || 'en_US-lessac';
|
||||
const ruInput = voiceSettingsModal.querySelector(`input[name="tts_voice_ru"][value="${currentRu}"]`);
|
||||
if (ruInput) ruInput.checked = true;
|
||||
const enInput = voiceSettingsModal.querySelector(`input[name="tts_voice_en"][value="${currentEn}"]`);
|
||||
if (enInput) enInput.checked = true;
|
||||
openModal(voiceSettingsModal);
|
||||
}
|
||||
|
||||
function initVoiceSettingsModal() {
|
||||
const voiceSettingsModal = document.getElementById('voice-settings-modal');
|
||||
const voiceSettingsCloseBtn = document.getElementById('voice-settings-close-btn');
|
||||
const voiceSettingsSaveBtn = document.getElementById('voice-settings-save-btn');
|
||||
|
||||
if (voiceSettingsCloseBtn && voiceSettingsModal) {
|
||||
voiceSettingsCloseBtn.addEventListener('click', () => closeModal(voiceSettingsModal));
|
||||
}
|
||||
|
||||
if (voiceSettingsSaveBtn && voiceSettingsModal) {
|
||||
voiceSettingsSaveBtn.addEventListener('click', () => {
|
||||
const ruVal = voiceSettingsModal.querySelector('input[name="tts_voice_ru"]:checked')?.value || 'ru_RU-irina';
|
||||
const enVal = voiceSettingsModal.querySelector('input[name="tts_voice_en"]:checked')?.value || 'en_US-lessac';
|
||||
localStorage.setItem('notes_tts_voice_ru', ruVal);
|
||||
localStorage.setItem('notes_tts_voice_en', enVal);
|
||||
|
||||
// Sync with listening selector if on screen
|
||||
const listeningVoiceSelect = document.getElementById('listening-voice-select');
|
||||
if (listeningVoiceSelect) {
|
||||
listeningVoiceSelect.value = enVal;
|
||||
}
|
||||
|
||||
closeModal(voiceSettingsModal);
|
||||
showToast('✅ Голоса дикторов сохранены!', 'success');
|
||||
});
|
||||
}
|
||||
|
||||
// Voice test buttons
|
||||
if (voiceSettingsModal) {
|
||||
voiceSettingsModal.querySelectorAll('.voice-test-btn').forEach(btn => {
|
||||
btn.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const lang = btn.dataset.lang || 'en';
|
||||
const voice = btn.dataset.voice;
|
||||
const text = btn.dataset.text || 'Test voice';
|
||||
playTextSpeech(text, lang, 1.0, voice);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Password Change Modal
|
||||
// -----------------------------------------------------------------------
|
||||
@@ -695,6 +760,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
// 7. Change Password Modal
|
||||
initChangePasswordModal();
|
||||
|
||||
// 7b. Voice Settings Modal (TTS)
|
||||
initVoiceSettingsModal();
|
||||
|
||||
// 8. Hash Change Listener
|
||||
window.addEventListener('hashchange', handleRouting);
|
||||
|
||||
|
||||
Reference in new issue
Block a user