fix(media-use): forward Kokoro speech speed

This commit is contained in:
Miguel Ángel
2026-07-14 22:32:58 +00:00
parent 14df58f017
commit c3e215b800
2 changed files with 46 additions and 2 deletions
+23 -2
View File
@@ -241,6 +241,22 @@ save(audio, sys.argv[3])
// [{text,start,end}] array for HeyGen (native), or null for ElevenLabs/Kokoro
// (caller must transcribeWav). Never throws; failures return { ok:false, error }
// where `error` states WHY (so the caller can surface it, not a bare "TTS failed").
export function buildKokoroTtsArgs({ textPath, voiceId, wavRel, lang = "en", speed = 1.0 }) {
const args = [
"hyperframes",
"tts",
textPath,
"--voice",
voiceId,
"--output",
wavRel,
"--speed",
String(speed),
];
if (lang !== "en") args.push("--lang", lang);
return args;
}
export async function synthesizeOne({
provider,
text,
@@ -276,8 +292,13 @@ export async function synthesizeOne({
}
// kokoro — via the published CLI; --output is relative to the project dir.
const wavRel = relTo(hyperframesDir, wavAbs);
const args = ["hyperframes", "tts", writeTmpText(text), "--voice", voiceId, "--output", wavRel];
if (lang !== "en") args.push("--lang", lang);
const args = buildKokoroTtsArgs({
textPath: writeTmpText(text),
voiceId,
wavRel,
lang,
speed,
});
const r = await spawnP("npx", args, { cwd: hyperframesDir });
return synthResult(r, wavAbs, "kokoro (npx hyperframes tts)");
}
@@ -9,8 +9,31 @@ import {
synthesizeOne,
synthesizeHeygen,
synthResult,
buildKokoroTtsArgs,
} from "./tts.mjs";
test("forwards a non-default speed to the Kokoro CLI", () => {
const args = buildKokoroTtsArgs({
textPath: "/tmp/narration.txt",
voiceId: "am_michael",
wavRel: "audio/narration.wav",
lang: "en",
speed: 1.15,
});
assert.deepEqual(args, [
"hyperframes",
"tts",
"/tmp/narration.txt",
"--voice",
"am_michael",
"--output",
"audio/narration.wav",
"--speed",
"1.15",
]);
});
test("parseFfmpegDurationBanner reads ffmpeg's stderr Duration line", () => {
const stderr = [
"ffmpeg version 6.0",