feat(tts): multi-voice switcher for EN & RU, Irina default voice, punctuation pause normalization and speed calibration
This commit is contained in:
@@ -185,8 +185,12 @@ export const api = {
|
||||
|
||||
// Listening Comprehension Trainer
|
||||
listening: {
|
||||
async getExercise(topic = 'all', level = 'B1') {
|
||||
const resp = await fetch(`/api/listening/exercise?topic=${encodeURIComponent(topic)}&level=${encodeURIComponent(level)}`);
|
||||
async getExercise(topic = 'all', level = 'B1', voice = null) {
|
||||
let url = `/api/listening/exercise?topic=${encodeURIComponent(topic)}&level=${encodeURIComponent(level)}`;
|
||||
if (voice) {
|
||||
url += `&voice=${encodeURIComponent(voice)}`;
|
||||
}
|
||||
const resp = await fetch(url);
|
||||
if (resp.ok) return await resp.json();
|
||||
throw new Error(`Failed to load listening exercise: ${resp.status}`);
|
||||
},
|
||||
@@ -206,6 +210,14 @@ export const api = {
|
||||
}
|
||||
},
|
||||
|
||||
// Neural Speech Synthesis (TTS)
|
||||
tts: {
|
||||
async getStatus() {
|
||||
const resp = await fetch('/api/tts/status');
|
||||
return resp.ok ? await resp.json() : null;
|
||||
}
|
||||
},
|
||||
|
||||
// Bookshelf & Reader
|
||||
books: {
|
||||
async getAll() {
|
||||
|
||||
@@ -111,6 +111,7 @@ export function initSrs() {
|
||||
const listeningLevelBadge = document.getElementById('listening-level-badge');
|
||||
const listeningTopicBadge = document.getElementById('listening-topic-badge');
|
||||
const listeningTopicSelect = document.getElementById('listening-topic-select');
|
||||
const listeningVoiceSelect = document.getElementById('listening-voice-select');
|
||||
const listeningSpeedSelect = document.getElementById('listening-speed-select');
|
||||
const listeningNewScenarioBtn = document.getElementById('listening-new-scenario-btn');
|
||||
const listeningTitle = document.getElementById('listening-title');
|
||||
@@ -715,8 +716,9 @@ export function initSrs() {
|
||||
if (listeningTitle) listeningTitle.textContent = 'Загрузка аудио-ситуации...';
|
||||
|
||||
const topic = listeningTopicSelect ? listeningTopicSelect.value : 'all';
|
||||
const voice = listeningVoiceSelect ? listeningVoiceSelect.value : (localStorage.getItem('notes_tts_voice_en') || 'en_US-lessac');
|
||||
try {
|
||||
const data = await api.listening.getExercise(topic, 'B1');
|
||||
const data = await api.listening.getExercise(topic, 'B1', voice);
|
||||
currentListeningExercise = data;
|
||||
|
||||
if (listeningTitle) listeningTitle.textContent = data.title || 'Ситуация для аудирования';
|
||||
@@ -788,6 +790,14 @@ export function initSrs() {
|
||||
});
|
||||
}
|
||||
|
||||
if (listeningVoiceSelect) {
|
||||
listeningVoiceSelect.value = localStorage.getItem('notes_tts_voice_en') || 'en_US-lessac';
|
||||
listeningVoiceSelect.addEventListener('change', () => {
|
||||
localStorage.setItem('notes_tts_voice_en', listeningVoiceSelect.value);
|
||||
loadListeningExercise(true);
|
||||
});
|
||||
}
|
||||
|
||||
if (listeningForm) {
|
||||
listeningForm.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -194,8 +194,14 @@ export function playAudio(url, speed = 1.0) {
|
||||
}
|
||||
}
|
||||
|
||||
export function playTextSpeech(text, lang = 'en', speed = 1.0) {
|
||||
export function playTextSpeech(text, lang = 'en', speed = 1.0, voice = null) {
|
||||
if (!text || !text.trim()) return null;
|
||||
const url = `/api/tts?text=${encodeURIComponent(text.trim())}&lang=${lang}&speed=${speed}`;
|
||||
const isRu = lang && lang.toLowerCase().startsWith('ru');
|
||||
const savedVoice = isRu ? localStorage.getItem('notes_tts_voice_ru') : localStorage.getItem('notes_tts_voice_en');
|
||||
const activeVoice = voice || savedVoice;
|
||||
let url = `/api/tts?text=${encodeURIComponent(text.trim())}&lang=${lang}&speed=${speed}`;
|
||||
if (activeVoice) {
|
||||
url += `&voice=${encodeURIComponent(activeVoice)}`;
|
||||
}
|
||||
return playAudio(url, speed);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user