Report actual speech playback state
Build and publish frontend / publish (push) Successful in 41s

This commit is contained in:
Ein Anderssono
2026-10-16 00:55:32 +02:00
parent 557fc77a52
commit ea7e349fc2
5 changed files with 33 additions and 3 deletions
+7 -2
View File
@@ -205,7 +205,10 @@
}
function speak(text, voiceOptions = {}) {
if (!text || !win.speechSynthesis || !win.SpeechSynthesisUtterance) return false;
if (!text || !win.speechSynthesis || !win.SpeechSynthesisUtterance) {
setState('IDLE', 'Talsyntes stöds inte i den här webbläsaren. Dialogen finns kvar som text.');
return false;
}
stopListening();
const hadQueuedUtterance = currentUtterance !== null;
if (hadQueuedUtterance) cancelSpeech();
@@ -214,6 +217,7 @@
try { utterance = new win.SpeechSynthesisUtterance(text); }
catch (_) { setState('IDLE', 'Talsyntesen kunde inte startas. Dialogen finns kvar som text.'); return false; }
utterance.lang = settings.language || 'sv-SE';
utterance.volume = 1;
const profile = voiceOptions.characterId ? settings.speakerProfiles?.[voiceOptions.characterId] || {} : {};
const identityProfile = characterVoiceProfile(voiceOptions.voiceIdentity, voiceOptions.characterId);
const isNarrator = voiceOptions.role === 'narrator';
@@ -229,6 +233,7 @@
if (token !== generation) return;
if (speechStartTimer !== null) win.clearTimeout(speechStartTimer);
speechStartTimer = null;
setState('SPEAKING', 'Uppläsningen har startat. Om du inte hör ljud, kontrollera iPadens volym och ljudutgång.');
if (typeof voiceOptions.onStart === 'function') voiceOptions.onStart();
};
utterance.onend = () => {
@@ -254,7 +259,7 @@
: 'Uppläsningen avbröts. Tryck på Läs senaste repliken för att försöka igen. Dialogen finns kvar som text.';
setState('IDLE', message);
};
setState('SPEAKING', 'Läser upp dialog.');
setState('QUEUED', 'Startar uppläsningen.');
currentUtterance = utterance;
speechStartTimer = win.setTimeout(() => {
if (token !== generation || currentUtterance !== utterance) return;