forked from Selig/openclaw-skill
improve(tts-voice): use spawnSync args to avoid shell quoting issues
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
* - curl CLI
|
* - curl CLI
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { execSync } from 'child_process';
|
import { execSync, spawnSync } from 'child_process';
|
||||||
import { readFileSync, existsSync, unlinkSync } from 'fs';
|
import { readFileSync, existsSync, unlinkSync } from 'fs';
|
||||||
|
|
||||||
const LUXTTS_BASE = 'http://localhost:7860';
|
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`;
|
const outPath = `/tmp/tts_output_${timestamp}.wav`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const httpCode = execSync(
|
const args = [
|
||||||
`curl -s -o ${outPath} -w "%{http_code}" ` +
|
'-s',
|
||||||
`-b ${COOKIE_JAR} ` +
|
'-o', outPath,
|
||||||
`-X POST ${LUXTTS_BASE}/luxtts/api/tts ` +
|
'-w', '%{http_code}',
|
||||||
`-F "ref_audio=@${REF_AUDIO}" ` +
|
'-b', COOKIE_JAR,
|
||||||
`-F "text=${text.replace(/"/g, '\\"')}" ` +
|
'-X', 'POST',
|
||||||
`-F "num_steps=${params.numSteps}" ` +
|
`${LUXTTS_BASE}/luxtts/api/tts`,
|
||||||
`-F "t_shift=${params.tShift}" ` +
|
'-F', `ref_audio=@${REF_AUDIO}`,
|
||||||
`-F "speed=${params.speed}"`,
|
'-F', `text=${text}`,
|
||||||
{ timeout: 120000 } // 2 min timeout for CPU synthesis
|
'-F', `num_steps=${params.numSteps}`,
|
||||||
).toString().trim();
|
'-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;
|
return outPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user