fix(audio): longer Piper time for long calls, fallback voice matches the line's language (1.55.2)

This commit is contained in:
larssand committed 2026-11-03 09:16:11 +01:00
1 parent c3aafba327
commit 36fe1e3933
6 files changed
+21 -8

No files matched your search

+4 -1
View File
@@ -28,7 +28,10 @@ export function speakWithPiper(text, { language, voice = "", rate, volume = 1, i
if (current === job) current = null;
callback?.();
};
const timer = setTimeout(() => job.controller.abort(), PIPER_TIMEOUT_MS);
// Short calls (count-down) must be on time; a long line such as a heat call with every
// driver's name gets longer to be generated before the browser voice takes over.
const timeoutMs = PIPER_TIMEOUT_MS + Math.min(7500, Math.max(0, String(text || "").length - 40) * 60);
const timer = setTimeout(() => job.controller.abort(), timeoutMs);
fetch("/api/tts/speech", {
method: "POST",
headers: { "Content-Type": "application/json" },
+4 -2
View File
@@ -364,9 +364,11 @@ export function getSpeechVoicesHelper() {
export function selectSpeechVoice(voices, voiceUri, language) {
const items = Array.isArray(voices) ? voices : [];
const selected = items.find((voice) => voice.voiceURI === voiceUri);
if (selected) return selected;
const prefix = String(language || "").toLowerCase().split("-")[0];
// The chosen voice only when it speaks this line's language: a Swedish voice must not read
// an English call (and the other way round).
const selected = items.find((voice) => voice.voiceURI === voiceUri);
if (selected && (!prefix || String(selected.lang || "").toLowerCase().startsWith(prefix))) return selected;
return items.find((voice) => String(voice.lang || "").toLowerCase().startsWith(prefix) && voice.localService !== false)
|| items.find((voice) => String(voice.lang || "").toLowerCase().startsWith(prefix))
|| null;