diff --git a/src/tts/tts-core.ts b/src/tts/tts-core.ts index 4472b1e38af..4ce8681c470 100644 --- a/src/tts/tts-core.ts +++ b/src/tts/tts-core.ts @@ -704,10 +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"); - } - const tts = new EdgeTTS({ voice: config.voice, lang: config.lang, @@ -720,16 +716,18 @@ export async function edgeTTS(params: { timeout: config.timeoutMs ?? timeoutMs, }); - await tts.ttsPromise(text, outputPath); - - let { size } = statSync(outputPath); - - if (size === 0) { + if (text && text.trim().length > 0) { await tts.ttsPromise(text, outputPath); - ({ size } = statSync(outputPath)); + + let { size } = statSync(outputPath); if (size === 0) { - throw new Error("Edge TTS produced empty audio file after retry"); + await tts.ttsPromise(text, outputPath); + ({ size } = statSync(outputPath)); + + if (size === 0) { + throw new Error("Edge TTS produced empty audio file after retry"); + } } } }