Skip to content

Commit 835e0c1

Browse files
fix(media-use): forward TTS speed to Kokoro (#4930)
* fix(media-use): forward TTS speed to Kokoro synthesizeOne built the `npx hyperframes tts` argv without --speed, so a request speed (audio_request.json `speed` or audio.mjs --speed) was ignored on the Kokoro path and every line rendered at 1.0. Forward it when it is not the default. Kokoro now enforces the CLI's speed range, so audio.mjs rejects a speed outside (0, 3] up front instead of dropping every line with an opaque subprocess exit. Fixes #4926 Co-Authored-By: Miguel Ángel <[email protected]> * fix(media-use): reject zero and non-numeric TTS speed `Number(x) || 1.0` turned 0 and non-numeric speeds into 1 before the range check, so they passed silently. The engine now parses the raw request or --speed value once, with no fallback, and the faceless-explainer, pr-to-video and product-launch-video adapters forward the raw flag instead of applying their own copy of the fallback. Co-Authored-By: Miguel Ángel <[email protected]> --------- Co-authored-by: Miguel Ángel <[email protected]>
1 parent 9123628 commit 835e0c1

8 files changed

Lines changed: 89 additions & 12 deletions

File tree

‎skills-manifest.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"files": 144
77
},
88
"faceless-explainer": {
9-
"hash": "db87ee2e6a1e9a6a",
9+
"hash": "3611c7079a4ccb28",
1010
"files": 27
1111
},
1212
"figma": {
@@ -54,7 +54,7 @@
5454
"files": 1
5555
},
5656
"media-use": {
57-
"hash": "3002f29ef00d0a13",
57+
"hash": "e2e523d50ce6baec",
5858
"files": 104
5959
},
6060
"motion-graphics": {
@@ -66,11 +66,11 @@
6666
"files": 169
6767
},
6868
"pr-to-video": {
69-
"hash": "92fa20d196073c17",
69+
"hash": "d11e258069d74db7",
7070
"files": 33
7171
},
7272
"product-launch-video": {
73-
"hash": "ec928631f3058f98",
73+
"hash": "1598d7f96e858d01",
7474
"files": 34
7575
},
7676
"remotion-to-hyperframes": {

‎skills/faceless-explainer/scripts/audio.mjs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ function runGenerate(argv) {
131131
const scriptPath = resolve(flag(argv, "script", join(hyperframesDir, "SCRIPT.md")));
132132
const outPath = resolve(flag(argv, "out", join(hyperframesDir, "audio_meta.json")));
133133
const userVoice = flag(argv, "voice", null);
134-
const speed = Number(flag(argv, "speed", "1.0")) || 1.0;
135134

136135
if (!existsSync(storyboardPath)) die(`STORYBOARD.md not found at ${storyboardPath}`);
137136
const manifest = parseStoryboard(readFileSync(storyboardPath, "utf8"));
@@ -166,7 +165,7 @@ function runGenerate(argv) {
166165
const query = (g.extra && g.extra.music) || g.message || g.arc || "calm cinematic underscore";
167166
const request = {
168167
provider: "auto",
169-
speed,
168+
speed: flag(argv, "speed", "1.0"),
170169
lines,
171170
bgm: bgmOff
172171
? { mode: "none" }

‎skills/media-use/audio/scripts/audio.mjs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ try {
109109
}
110110
const lines = Array.isArray(request.lines) ? request.lines : [];
111111
const lang = langOverride || request.lang || "en";
112-
const speed = Number(speedOverride ?? request.speed ?? 1.0) || 1.0;
112+
const speedInput = speedOverride ?? request.speed ?? 1;
113+
const speed = Number(speedInput);
114+
if (!(speed > 0 && speed <= 3))
115+
die(`speed must be above 0 and at most 3, got ${JSON.stringify(speedInput)}`);
113116

114117
// ── env + HeyGen availability (the single switch) ─────────────────────────────
115118
loadEnvFromDir(hyperframesDir);

‎skills/media-use/audio/scripts/audio.test.mjs‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { strict as assert } from "node:assert";
22
import { test } from "node:test";
33
import { mkdtempSync, mkdirSync, readFileSync, rmSync, existsSync, writeFileSync } from "node:fs";
4+
import { spawnSync } from "node:child_process";
45
import { join, dirname } from "node:path";
56
import { tmpdir } from "node:os";
67
import { fileURLToPath } from "node:url";
@@ -124,3 +125,35 @@ test("two effects never share a file when one's name is taken by the person, run
124125
rmSync(dir, { recursive: true, force: true });
125126
}
126127
});
128+
129+
// The engine owns speed parsing; a fallback before the check would turn 0 or junk into 1.
130+
function runEngineWith(request, ...args) {
131+
const dir = mkdtempSync(join(tmpdir(), "audio-speed-range-"));
132+
try {
133+
writeFileSync(join(dir, "audio_request.json"), JSON.stringify({ lines: [], ...request }));
134+
return spawnSync(process.execPath, [join(HERE, "audio.mjs"), "--hyperframes", dir, ...args], {
135+
encoding: "utf8",
136+
});
137+
} finally {
138+
rmSync(dir, { recursive: true, force: true });
139+
}
140+
}
141+
142+
for (const [label, request, args, shown] of [
143+
["request speed 5", { speed: 5 }, [], "5"],
144+
["request speed 0", { speed: 0 }, [], "0"],
145+
["request speed -1", { speed: -1 }, [], "-1"],
146+
["request speed text", { speed: "fast" }, [], '"fast"'],
147+
["--speed 0", {}, ["--speed", "0"], '"0"'],
148+
["--speed text", { speed: 1 }, ["--speed", "abc"], '"abc"'],
149+
]) {
150+
test(`${label} stops the engine before any TTS runs`, () => {
151+
const r = runEngineWith(request, ...args);
152+
assert.equal(r.status, 1);
153+
assert.ok(r.stderr.includes(`speed must be above 0 and at most 3, got ${shown}`), r.stderr);
154+
});
155+
}
156+
157+
test("a numeric string speed, as the adapters forward it, passes the check", () => {
158+
assert.doesNotMatch(runEngineWith({ speed: "0.8" }, "--only", "tts").stderr, /speed must/);
159+
});

‎skills/media-use/audio/scripts/lib/tts.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ export async function synthesizeOne({
290290
const wavRel = relTo(hyperframesDir, wavAbs);
291291
const args = ["hyperframes", "tts", writeTmpText(text), "--voice", voiceId, "--output", wavRel];
292292
if (lang !== "en") args.push("--lang", lang);
293+
if (speed !== 1) args.push("--speed", String(speed));
293294
const r = await spawnP("npx", args, { cwd: hyperframesDir });
294295
return synthResult(r, wavAbs, "kokoro (npx hyperframes tts)");
295296
}

‎skills/media-use/audio/scripts/lib/tts.test.mjs‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { test } from "node:test";
22
import assert from "node:assert/strict";
3-
import { mkdtempSync, writeFileSync, chmodSync, rmSync, existsSync } from "node:fs";
3+
import { mkdtempSync, readFileSync, writeFileSync, chmodSync, rmSync, existsSync } from "node:fs";
44
import { join, dirname } from "node:path";
55
import { tmpdir } from "node:os";
66
import {
@@ -155,3 +155,46 @@ test("synthResult names a non-zero subprocess exit", () => {
155155
assert.equal(res.ok, false);
156156
assert.match(res.error, /kokoro .* exited with status 2/);
157157
});
158+
159+
// Kokoro shells out to `npx hyperframes tts`; a fake npx on PATH records the argv
160+
// synthesizeOne really builds, so a dropped flag fails here. Windows runs npx via
161+
// node directly, so the stub never resolves there.
162+
async function kokoroArgv(options) {
163+
const dir = mkdtempSync(join(tmpdir(), "tts-kokoro-argv-"));
164+
const argvLog = join(dir, "argv.txt");
165+
writeFileSync(join(dir, "npx"), `#!/bin/sh\nprintf '%s\\n' "$@" > "${argvLog}"\n`);
166+
chmodSync(join(dir, "npx"), 0o755);
167+
const originalPath = process.env.PATH;
168+
try {
169+
process.env.PATH = dir;
170+
await synthesizeOne({
171+
provider: "kokoro",
172+
text: "hi",
173+
voiceId: "am_michael",
174+
wavAbs: join(dir, "line-0.wav"),
175+
hyperframesDir: dir,
176+
...options,
177+
});
178+
return readFileSync(argvLog, "utf8").trim().split("\n");
179+
} finally {
180+
process.env.PATH = originalPath;
181+
rmSync(dir, { recursive: true, force: true });
182+
}
183+
}
184+
185+
test(
186+
"synthesizeOne(kokoro) forwards a non-default speed to the CLI",
187+
{ skip: process.platform === "win32" },
188+
async () => {
189+
const argv = await kokoroArgv({ speed: 0.8, lang: "es" });
190+
assert.deepEqual(argv.slice(-4), ["--lang", "es", "--speed", "0.8"]);
191+
},
192+
);
193+
194+
test(
195+
"synthesizeOne(kokoro) leaves --speed off at the default",
196+
{ skip: process.platform === "win32" },
197+
async () => {
198+
assert.ok(!(await kokoroArgv({})).includes("--speed"));
199+
},
200+
);

‎skills/pr-to-video/scripts/audio.mjs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ function runGenerate(argv) {
131131
const scriptPath = resolve(flag(argv, "script", join(hyperframesDir, "SCRIPT.md")));
132132
const outPath = resolve(flag(argv, "out", join(hyperframesDir, "audio_meta.json")));
133133
const userVoice = flag(argv, "voice", null);
134-
const speed = Number(flag(argv, "speed", "1.0")) || 1.0;
135134

136135
if (!existsSync(storyboardPath)) die(`STORYBOARD.md not found at ${storyboardPath}`);
137136
const manifest = parseStoryboard(readFileSync(storyboardPath, "utf8"));
@@ -166,7 +165,7 @@ function runGenerate(argv) {
166165
const query = (g.extra && g.extra.music) || g.message || g.arc || "calm cinematic underscore";
167166
const request = {
168167
provider: "auto",
169-
speed,
168+
speed: flag(argv, "speed", "1.0"),
170169
lines,
171170
bgm: bgmOff
172171
? { mode: "none" }

‎skills/product-launch-video/scripts/audio.mjs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ function runGenerate(argv) {
130130
const outPath = resolve(flag(argv, "out", join(hyperframesDir, "audio_meta.json")));
131131
const userVoice = flag(argv, "voice", null);
132132
const provider = flag(argv, "provider", process.env.HF_TTS_PROVIDER || "auto");
133-
const speed = Number(flag(argv, "speed", "1.0")) || 1.0;
134133

135134
if (!existsSync(storyboardPath)) die(`STORYBOARD.md not found at ${storyboardPath}`);
136135
const manifest = parseStoryboard(readFileSync(storyboardPath, "utf8"));
@@ -165,7 +164,7 @@ function runGenerate(argv) {
165164
const query = (g.extra && g.extra.music) || g.message || g.arc || "calm cinematic underscore";
166165
const request = {
167166
provider,
168-
speed,
167+
speed: flag(argv, "speed", "1.0"),
169168
lines,
170169
bgm: bgmOff
171170
? { mode: "none" }

0 commit comments

Comments
 (0)