From e179a3291bde494c85a8d0147b3397a7c23b1dbd Mon Sep 17 00:00:00 2001 From: Hiago Silva <97215740+Huntterxx@users.noreply.github.com> Date: Sun, 15 Mar 2026 08:02:49 -0300 Subject: [PATCH] improve: add empty-text guard and retry for Edge TTS Follow-up to PR #43385 Implements reviewer suggestions: - Add pre-check for empty or whitespace-only text - Retry once if Edge TTS produces a zero-byte file - Include file size in error message for debugging --- src/tts/tts-core.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/tts/tts-core.ts b/src/tts/tts-core.ts index 5d3000d7ad3..da464d828a8 100644 --- a/src/tts/tts-core.ts +++ b/src/tts/tts-core.ts @@ -703,6 +703,7 @@ export async function edgeTTS(params: { timeoutMs: number; }): Promise { const { text, outputPath, config, timeoutMs } = params; + const tts = new EdgeTTS({ voice: config.voice, lang: config.lang, @@ -714,11 +715,23 @@ export async function edgeTTS(params: { volume: config.volume, timeout: config.timeoutMs ?? timeoutMs, }); + + + if (!text || text.trim().length === 0) { + throw new Error("TTS text cannot be empty"); + } + await tts.ttsPromise(text, outputPath); - const { size } = statSync(outputPath); + let { size } = statSync(outputPath); if (size === 0) { - throw new Error("Edge TTS produced empty audio file"); + + await tts.ttsPromise(text, outputPath); + ({ size } = statSync(outputPath)); + + if (size === 0) { + throw new Error(`Edge TTS produced empty audio file (size=${size})`); + } } }