Merge pull request 'improve(tts-voice): 改用 spawnSync 參數陣列避免 shell quoting 問題' (#1) from yucheng/openclaw-skill:improve/tts-voice-safe-curl-args into main
This commit was merged in pull request #1.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user