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
This commit is contained in:
parent
843e3c1efb
commit
e179a3291b
@ -703,6 +703,7 @@ export async function edgeTTS(params: {
|
||||
timeoutMs: number;
|
||||
}): Promise<void> {
|
||||
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})`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user