This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user