From 36e0d349b26d043557b7ccaa78e77a9c2b87f5bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E6=88=90?= Date: Fri, 13 Mar 2026 12:02:57 +0800 Subject: [PATCH] improve(tts-voice): use spawnSync args to avoid shell quoting issues --- skills/tts-voice/handler.ts | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) 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; } -- 2.43.0