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] 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"); } } }