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 1/7] 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})`); + } } } From 729ef4f2679ee293567d2ce0cbdee9ac22c8f969 Mon Sep 17 00:00:00 2001 From: Hiago Silva <97215740+Huntterxx@users.noreply.github.com> Date: Sun, 15 Mar 2026 08:27:42 -0300 Subject: [PATCH 2/7] fix: address review comments (guard order + error message) --- src/tts/tts-core.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/tts/tts-core.ts b/src/tts/tts-core.ts index da464d828a8..a0c112d82bb 100644 --- a/src/tts/tts-core.ts +++ b/src/tts/tts-core.ts @@ -681,6 +681,7 @@ export async function openaiTTS(params: { export function inferEdgeExtension(outputFormat: string): string { const normalized = outputFormat.toLowerCase(); + if (normalized.includes("webm")) { return ".webm"; } @@ -690,9 +691,14 @@ export function inferEdgeExtension(outputFormat: string): string { if (normalized.includes("opus")) { return ".opus"; } - if (normalized.includes("wav") || normalized.includes("riff") || normalized.includes("pcm")) { + if ( + normalized.includes("wav") || + normalized.includes("riff") || + normalized.includes("pcm") + ) { return ".wav"; } + return ".mp3"; } @@ -704,6 +710,11 @@ export async function edgeTTS(params: { }): Promise { const { text, outputPath, config, timeoutMs } = params; + + if (!text || text.trim().length === 0) { + throw new Error("TTS text cannot be empty"); + } + const tts = new EdgeTTS({ voice: config.voice, lang: config.lang, @@ -716,11 +727,6 @@ export async function edgeTTS(params: { timeout: config.timeoutMs ?? timeoutMs, }); - - if (!text || text.trim().length === 0) { - throw new Error("TTS text cannot be empty"); - } - await tts.ttsPromise(text, outputPath); let { size } = statSync(outputPath); @@ -731,7 +737,7 @@ export async function edgeTTS(params: { ({ size } = statSync(outputPath)); if (size === 0) { - throw new Error(`Edge TTS produced empty audio file (size=${size})`); + throw new Error("Edge TTS produced empty audio file after retry"); } } } From bb506c4db1c0aa741f7dadd3f9b32a4195c29da8 Mon Sep 17 00:00:00 2001 From: Hiago Silva <97215740+Huntterxx@users.noreply.github.com> Date: Sun, 15 Mar 2026 08:42:39 -0300 Subject: [PATCH 4/7] style: fix formatter issues --- src/tts/tts-core.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/tts/tts-core.ts b/src/tts/tts-core.ts index a0c112d82bb..4472b1e38af 100644 --- a/src/tts/tts-core.ts +++ b/src/tts/tts-core.ts @@ -681,7 +681,6 @@ export async function openaiTTS(params: { export function inferEdgeExtension(outputFormat: string): string { const normalized = outputFormat.toLowerCase(); - if (normalized.includes("webm")) { return ".webm"; } @@ -691,14 +690,9 @@ export function inferEdgeExtension(outputFormat: string): string { if (normalized.includes("opus")) { return ".opus"; } - if ( - normalized.includes("wav") || - normalized.includes("riff") || - normalized.includes("pcm") - ) { + if (normalized.includes("wav") || normalized.includes("riff") || normalized.includes("pcm")) { return ".wav"; } - return ".mp3"; } @@ -710,7 +704,6 @@ export async function edgeTTS(params: { }): Promise { const { text, outputPath, config, timeoutMs } = params; - if (!text || text.trim().length === 0) { throw new Error("TTS text cannot be empty"); } @@ -732,7 +725,6 @@ export async function edgeTTS(params: { let { size } = statSync(outputPath); if (size === 0) { - await tts.ttsPromise(text, outputPath); ({ size } = statSync(outputPath)); From d2515519987245f161b0516a230529202f016850 Mon Sep 17 00:00:00 2001 From: Hiago Silva <97215740+Huntterxx@users.noreply.github.com> Date: Sun, 15 Mar 2026 08:52:05 -0300 Subject: [PATCH 5/7] fix: avoid breaking behavior for empty text --- src/tts/tts-core.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tts/tts-core.ts b/src/tts/tts-core.ts index 4472b1e38af..a21964a46cc 100644 --- a/src/tts/tts-core.ts +++ b/src/tts/tts-core.ts @@ -705,7 +705,7 @@ export async function edgeTTS(params: { const { text, outputPath, config, timeoutMs } = params; if (!text || text.trim().length === 0) { - throw new Error("TTS text cannot be empty"); + throw new Error("Edge TTS requires non-empty text"); } const tts = new EdgeTTS({ From 91d96821b0abf2e1c3ede15baf8769b03005c626 Mon Sep 17 00:00:00 2001 From: Hiago Silva <97215740+Huntterxx@users.noreply.github.com> Date: Sun, 15 Mar 2026 08:56:36 -0300 Subject: [PATCH 6/7] style: fix formatter issues --- src/tts/tts-core.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tts/tts-core.ts b/src/tts/tts-core.ts index a21964a46cc..ea449e4fcef 100644 --- a/src/tts/tts-core.ts +++ b/src/tts/tts-core.ts @@ -705,7 +705,7 @@ export async function edgeTTS(params: { const { text, outputPath, config, timeoutMs } = params; if (!text || text.trim().length === 0) { - throw new Error("Edge TTS requires non-empty text"); + throw new Error("Edge TTS requires non-empty text"); } const tts = new EdgeTTS({ From 133fb1a3005f35183ca0ff2400474fe9866c5588 Mon Sep 17 00:00:00 2001 From: Hiago Silva <97215740+Huntterxx@users.noreply.github.com> Date: Sun, 15 Mar 2026 11:40:30 -0300 Subject: [PATCH 7/7] style: fix indentation --- src/tts/tts-core.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tts/tts-core.ts b/src/tts/tts-core.ts index ea449e4fcef..82276f8d356 100644 --- a/src/tts/tts-core.ts +++ b/src/tts/tts-core.ts @@ -729,7 +729,7 @@ export async function edgeTTS(params: { ({ size } = statSync(outputPath)); if (size === 0) { - throw new Error("Edge TTS produced empty audio file after retry"); + throw new Error("Edge TTS produced empty audio file after retry."); } } }