Skip to content

Commit a5ece8c

Browse files
committed
feat(media-use): transcription (parakeet), transcript-cut, audio-duck editing tools
1 parent b5cd776 commit a5ece8c

11 files changed

Lines changed: 1221 additions & 2 deletions

skills-manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
"files": 10
4747
},
4848
"media-use": {
49-
"hash": "4e07a35f60f1378e",
50-
"files": 87
49+
"hash": "21951022f0d7066f",
50+
"files": 97
5151
},
5252
"motion-graphics": {
5353
"hash": "73771b2d1300236d",
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/usr/bin/env node
2+
3+
import { readFileSync } from "node:fs";
4+
import { resolve } from "node:path";
5+
import { parseArgs } from "node:util";
6+
import { duckKeyframes, speechSpans } from "./lib/duck.mjs";
7+
import { track } from "./lib/telemetry.mjs";
8+
9+
const { values: args } = parseArgs({
10+
options: {
11+
meta: { type: "string" },
12+
target: { type: "string" },
13+
duck: { type: "string", default: "0.25" },
14+
attack: { type: "string", default: "0.15" },
15+
release: { type: "string", default: "0.4" },
16+
"merge-gap": { type: "string", default: "0.6" },
17+
sequential: { type: "boolean", default: false },
18+
gap: { type: "string", default: "0" },
19+
offsets: { type: "string" },
20+
composition: { type: "string" },
21+
json: { type: "boolean", default: false },
22+
help: { type: "boolean", short: "h", default: false },
23+
},
24+
strict: true,
25+
});
26+
27+
if (args.help) {
28+
console.log(`media-use audio-duck — generate GSAP volume ducking keyframes
29+
30+
Usage:
31+
node audio-duck.mjs --meta audio_meta.json --target "#bgm"
32+
33+
Options:
34+
--meta audio_meta.json or JSON word transcript
35+
--target GSAP selector for the background audio element
36+
--duck Duck multiplier (default: 0.25)
37+
--attack Duck-in duration seconds (default: 0.15)
38+
--release Restore duration seconds (default: 0.4)
39+
--merge-gap Bridge speech gaps smaller than this many seconds (default: 0.6)
40+
--sequential Place multi-line meta back to back at composition time
41+
--gap Extra seconds between sequential lines (default: 0)
42+
--offsets Explicit placement, "l1=0,l2=3.4" (voice id = start seconds)
43+
--composition Read target data-volume from this HTML file
44+
--json Output { spans, keyframes }
45+
--help, -h Show this help`);
46+
process.exit(0);
47+
}
48+
49+
try {
50+
run();
51+
await track("media_use_duck", { sequential: !!args.sequential });
52+
} catch (err) {
53+
if (args.json) console.log(JSON.stringify({ ok: false, error: err.message }));
54+
else console.error(`error: ${err.message}`);
55+
process.exit(1);
56+
}
57+
58+
function run() {
59+
if (!args.meta || !args.target) throw new Error("--meta and --target are required");
60+
const meta = JSON.parse(readFileSync(resolve(args.meta), "utf8"));
61+
const target = args.target;
62+
const baseVolume = readBaseVolume(args.composition, target);
63+
const offsets = args.offsets
64+
? Object.fromEntries(
65+
args.offsets.split(",").map((pair) => {
66+
const [id, t] = pair.split("=");
67+
return [id.trim(), Number(t)];
68+
}),
69+
)
70+
: undefined;
71+
const spans = speechSpans(meta, {
72+
mergeGap: Number(args["merge-gap"]),
73+
sequential: args.sequential,
74+
gap: Number(args.gap),
75+
offsets,
76+
});
77+
const keyframes = duckKeyframes(spans, {
78+
duck: Number(args.duck),
79+
attack: Number(args.attack),
80+
release: Number(args.release),
81+
baseVolume,
82+
});
83+
84+
if (args.json) {
85+
console.log(JSON.stringify({ spans, keyframes }));
86+
return;
87+
}
88+
89+
console.log(
90+
`// auto-duck: ${target} under narration (generated; base volume ${fmt(baseVolume)})`,
91+
);
92+
for (const keyframe of keyframes) {
93+
console.log(
94+
`tl.to(${JSON.stringify(target)}, { volume: ${fmt(keyframe.volume)}, duration: ${fmt(
95+
keyframe.duration,
96+
)} }, ${fmt(keyframe.time)});`,
97+
);
98+
}
99+
}
100+
101+
function readBaseVolume(composition, target) {
102+
if (!composition || !target.startsWith("#")) return 1;
103+
const id = target.slice(1);
104+
const html = readFileSync(resolve(composition), "utf8");
105+
// ponytail: regex is enough here because this only reads one attribute from
106+
// one user-authored composition element, not arbitrary HTML.
107+
const tag = html.match(new RegExp(`<[^>]*\\bid=["']${escapeRegExp(id)}["'][^>]*>`, "i"))?.[0];
108+
const raw = tag?.match(/\bdata-volume=["']([^"']+)["']/i)?.[1];
109+
const volume = Number(raw);
110+
return Number.isFinite(volume) ? volume : 1;
111+
}
112+
113+
function escapeRegExp(value) {
114+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
115+
}
116+
117+
function fmt(n) {
118+
return Number(n)
119+
.toFixed(3)
120+
.replace(/\.?0+$/, "");
121+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import { strict as assert } from "node:assert";
2+
import { test } from "node:test";
3+
import { existsSync } from "node:fs";
4+
import { join, dirname } from "node:path";
5+
import { fileURLToPath } from "node:url";
6+
import { listTypes, getProviders } from "./registry.mjs";
7+
import { CAPABILITIES, listModels } from "./local-models.mjs";
8+
9+
// Capstone: media-use must actually OWN each hyperframes media weakness. This
10+
// test enforces the weakness→owner matrix in SKILL.md so a claim can't rot — if
11+
// a capability's entrypoint disappears, this fails.
12+
13+
const SKILL = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
14+
15+
test("weakness: audio-only → media-use resolves image + icon", () => {
16+
for (const t of ["image", "icon"]) {
17+
assert.ok(getProviders(t).length > 0, `no provider for ${t}`);
18+
}
19+
});
20+
21+
test("weakness: no voice/audio gen → media-use exposes voice + the audio engine", () => {
22+
assert.ok(listTypes().includes("voice"), "voice type missing");
23+
assert.ok(getProviders("voice").length > 0, "no enabled voice provider (Bin approved)");
24+
assert.ok(existsSync(join(SKILL, "audio", "scripts", "audio.mjs")), "audio engine missing");
25+
});
26+
27+
test("weakness: scattered audio engine → consolidated under media-use (hyperframes-media gone)", () => {
28+
assert.ok(existsSync(join(SKILL, "audio", "scripts", "lib", "tts.mjs")), "tts engine missing");
29+
assert.ok(
30+
existsSync(join(SKILL, "audio", "assets", "sfx", "manifest.json")),
31+
"bundled SFX missing",
32+
);
33+
});
34+
35+
test("weakness: no media-ops → ops guidance reference exists", () => {
36+
assert.ok(existsSync(join(SKILL, "references", "operations.md")), "operations.md missing");
37+
});
38+
39+
test("weakness: no transcript-driven cutting → cut compiler entrypoints exist", async () => {
40+
assert.ok(existsSync(join(SKILL, "scripts", "transcript-cut.mjs")), "transcript-cut missing");
41+
assert.ok(existsSync(join(SKILL, "scripts", "lib", "cutlist.mjs")), "cutlist lib missing");
42+
const cutlist = await import("./cutlist.mjs");
43+
assert.equal(typeof cutlist.compileCutList, "function");
44+
});
45+
46+
test("weakness: whisper.cpp is weak → better local ASR (Parakeet) entrypoint exists", async () => {
47+
assert.ok(existsSync(join(SKILL, "scripts", "transcribe.mjs")), "transcribe.mjs missing");
48+
const pw = await import("./parakeet-words.mjs");
49+
assert.equal(typeof pw.mergeTokensToWords, "function", "token->word merge missing");
50+
const lm = await import("./local-models.mjs");
51+
const asr = lm.listModels("asr");
52+
const parakeet = asr.find((m) => m.id === "parakeet-mlx");
53+
assert.ok(parakeet && parakeet.rank === 0, "Parakeet must be the rank-0 preferred ASR");
54+
});
55+
56+
test("weakness: no auto-duck/loudness → duck compiler and recipes exist", async () => {
57+
assert.ok(existsSync(join(SKILL, "scripts", "audio-duck.mjs")), "audio-duck missing");
58+
assert.ok(existsSync(join(SKILL, "scripts", "lib", "duck.mjs")), "duck lib missing");
59+
assert.ok(existsSync(join(SKILL, "references", "operations.md")), "operations.md missing");
60+
const duck = await import("./duck.mjs");
61+
assert.equal(typeof duck.speechSpans, "function");
62+
assert.equal(typeof duck.duckKeyframes, "function");
63+
});
64+
65+
test("weakness: no cross-project memory → global cache + ingest entrypoints exist", async () => {
66+
const cache = await import("./cache.mjs");
67+
assert.equal(typeof cache.cachePut, "function");
68+
assert.equal(typeof cache.promote, "function");
69+
assert.equal(typeof cache.globalMediaDir, "function");
70+
const freeze = await import("./freeze.mjs");
71+
assert.equal(typeof freeze.isDirectMediaUrl, "function", "ingest URL guard missing");
72+
});
73+
74+
// Wenbo (06-29): heygen free-usage is the default; local models are the opt-out
75+
// fallback ("if user no, then local"). We still assert the fallback table is
76+
// populated so the opt-out path stays real.
77+
test("weakness: weak local defaults → local models exist as the opt-out fallback (tts/asr/upscale)", () => {
78+
for (const cap of ["tts", "asr", "upscale"]) {
79+
assert.ok(CAPABILITIES.includes(cap), `capability ${cap} missing`);
80+
assert.ok(listModels(cap).length > 0, `no local models for ${cap}`);
81+
}
82+
});
83+
84+
test("weakness: no image generation → local mflux (RAM-graded) + codex upsell", async () => {
85+
const ps = getProviders("image");
86+
assert.ok(
87+
ps.some((p) => p.name === "mflux.local" && typeof p.generate === "function"),
88+
"local image gen missing",
89+
);
90+
assert.ok(
91+
ps.some((p) => p.name === "codex.image_gen" && typeof p.generate === "function"),
92+
"codex image upsell missing",
93+
);
94+
const lm = await import("./local-models.mjs");
95+
assert.ok(lm.CAPABILITIES.includes("imagegen"), "imagegen capability missing");
96+
assert.ok(lm.listModels("imagegen").length >= 3, "imagegen RAM ladder too small");
97+
assert.equal(typeof lm.describeModelLadder, "function", "agent-facing ladder missing");
98+
});
99+
100+
test("weakness: no video generation → local videogen ladder + heygen avatar upsell", async () => {
101+
const lm = await import("./local-models.mjs");
102+
assert.ok(lm.CAPABILITIES.includes("videogen"), "videogen capability missing");
103+
assert.ok(lm.listModels("videogen").length >= 2, "videogen ladder too small");
104+
const ops = existsSync(join(SKILL, "references", "operations.md"));
105+
assert.ok(ops, "operations.md (avatar-upsell recipe) missing");
106+
});
107+
108+
test("every resolve type has at least one enabled provider", () => {
109+
for (const t of listTypes()) {
110+
assert.ok(getProviders(t).length > 0, `type ${t} has no enabled provider`);
111+
}
112+
});

0 commit comments

Comments
 (0)