diff --git a/skills/tts-voice/handler.ts b/skills/tts-voice/handler.ts index 15ff7db..c48dbea 100644 --- a/skills/tts-voice/handler.ts +++ b/skills/tts-voice/handler.ts @@ -8,7 +8,7 @@ * - curl CLI */ -import { execSync } from 'child_process'; +import { execSync, spawnSync } from 'child_process'; import { readFileSync, existsSync, unlinkSync } from 'fs'; const LUXTTS_BASE = 'http://localhost:7860'; @@ -113,19 +113,28 @@ function generateSpeech(text: string, params: TtsParams): string | null { const outPath = `/tmp/tts_output_${timestamp}.wav`; try { - const httpCode = execSync( - `curl -s -o ${outPath} -w "%{http_code}" ` + - `-b ${COOKIE_JAR} ` + - `-X POST ${LUXTTS_BASE}/luxtts/api/tts ` + - `-F "ref_audio=@${REF_AUDIO}" ` + - `-F "text=${text.replace(/"/g, '\\"')}" ` + - `-F "num_steps=${params.numSteps}" ` + - `-F "t_shift=${params.tShift}" ` + - `-F "speed=${params.speed}"`, - { timeout: 120000 } // 2 min timeout for CPU synthesis - ).toString().trim(); + const args = [ + '-s', + '-o', outPath, + '-w', '%{http_code}', + '-b', COOKIE_JAR, + '-X', 'POST', + `${LUXTTS_BASE}/luxtts/api/tts`, + '-F', `ref_audio=@${REF_AUDIO}`, + '-F', `text=${text}`, + '-F', `num_steps=${params.numSteps}`, + '-F', `t_shift=${params.tShift}`, + '-F', `speed=${params.speed}`, + ]; - if (httpCode === '200' && existsSync(outPath)) { + const result = spawnSync('curl', args, { + timeout: 120000, // 2 min timeout for CPU synthesis + encoding: 'utf-8', + }); + + const httpCode = (result.stdout || '').trim(); + + if (result.status === 0 && httpCode === '200' && existsSync(outPath)) { return outPath; }