diff --git a/src/tts/tts-core.ts b/src/tts/tts-core.ts index 7bdc8f56288..78e0029bf5a 100644 --- a/src/tts/tts-core.ts +++ b/src/tts/tts-core.ts @@ -706,6 +706,11 @@ export async function edgeTTS(params: { timeoutMs: number; }): Promise { const { text, outputPath, config, timeoutMs } = params; + + if (!text || text.trim().length === 0) { + throw new Error("Edge TTS requires non-empty text"); + } + const tts = new EdgeTTS({ voice: config.voice, lang: config.lang, @@ -717,11 +722,17 @@ export async function edgeTTS(params: { volume: config.volume, timeout: config.timeoutMs ?? timeoutMs, }); + 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 after retry"); + } } }