/** * TTS worker — run as a separate Bun subprocess so a crash in the Edge-TTS * path cannot take down the main server. * Usage: bun tts-worker.mjs "" "" * Writes MP3 audio bytes to stdout; non-zero exit on error. */ import { EdgeTTS } from "edge-tts-universal"; const voice = process.argv[2] || "vi-VN-HoaiMyNeural"; const text = process.argv[3] || ""; try { const tts = new EdgeTTS(text, voice, { rate: "+0%", volume: "+0%", pitch: "+0Hz" }); const result = await tts.synthesize(); const audio = Buffer.from(await result.audio.arrayBuffer()); if (!audio || !audio.length) process.exit(2); process.stdout.write(audio); } catch (e) { console.error("TTS_WORKER_ERROR:", e?.message || e); process.exit(1); }