mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 12:54:29 +00:00
* feat(hyperframes-creative): add frame-preset library Add a library of ready-made visual frame presets (claude, biennale-yellow, blockframe, blue-professional, bold-poster, broadside, capsule, cartesian, cobalt-grid, coral, creative-mode, daisy-days, editorial-forest, …), each with a FRAME.md spec, a frame-showcase.html, and a per-preset caption-skin.html. Registered in the creative design-spec so workflows can remix a preset onto brand tokens. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(hyperframes-media): shared TTS/BGM/SFX audio engine Add a shared audio engine under hyperframes-media (scripts/audio.mjs + lib/ tts.mjs, bgm.mjs, sfx.mjs, heygen.mjs) plus a bundled SFX pack and manifest. Workflows resolve this engine by path (../../hyperframes-media/scripts/ audio.mjs) for text-to-speech, background music, and sound effects, so audio is authored once and reused across skills instead of duplicated per workflow. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(skills): gate render on user review; refresh router, core, general-video - hyperframes-cli: render is now user-gated — preview opens Studio (the timeline editor where the user can hand-edit anything, not just watch); never auto-render once checks pass, pause at preview and render only after approval. - hyperframes (router): tighten the entry SKILL.md description + routing. - hyperframes-core: rewrite SKILL.md and add script-format.md + storyboard-format.md references for the script-driven authoring architecture. - general-video: tidy the fallback-workflow description and routing table. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * style(hyperframes-creative): reformat frame-preset showcase HTML Run the HTML formatter over the frame-showcase.html files (indentation, self-closing void tags, one CSS declaration per line). Formatting only — no content or markup changes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(hyperframes-media): correct wait-bgm field mapping and guard credential parse Two correctness fixes from review (#1632): - wait-bgm.mjs read audioMeta.bgm_path / audioMeta.bgm_enabled, but audio.mjs writes the path nested as bgm.path and the flag as bgm_pending. The detached generate path (Lyria/MusicGen) therefore always saw an empty path and exited status: disabled, silently dropping the music track even while generation was running. Read audioMeta.bgm?.path and gate on bgm_pending. - heygenCredential() had an unguarded JSON.parse despite documenting that it never throws — a malformed ~/.heygen credentials file crashed the engine at startup instead of degrading to no-credential. Wrap the parse and return null. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore(hyperframes): add router tag to entry skill metadata Fold the router metadata tag into the foundation rewrite of the entry SKILL.md. This file is owned by this PR (the full router rewrite); keeping the tag tweak here — instead of a separate edit on the pre-rewrite version in another PR — avoids a guaranteed merge conflict between the two. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
129 lines
4.6 KiB
JavaScript
129 lines
4.6 KiB
JavaScript
// sfx.mjs — sound effects for the media audio engine. Provider-gated (NOT a
|
||
// per-cue merge): the decision is made once, by whether HeyGen is configured —
|
||
// mirroring how TTS and BGM degrade.
|
||
//
|
||
// HeyGen credential present → retrieve EVERY cue from HeyGen's audio library
|
||
// (/v3/audio/sounds, type=sound_effects, min_score=0.4). The bundled
|
||
// library is NOT consulted.
|
||
// HeyGen credential absent → resolve cues against the bundled 21-file
|
||
// library (assets/sfx/manifest.json), copying matched files into the
|
||
// project. Offline, deterministic, free.
|
||
//
|
||
// A cue that matches nothing is skipped (recorded as an anomaly); SFX never
|
||
// blocks a render. Every cue sits at volume ~0.35, under voice + BGM.
|
||
|
||
import { copyFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
||
import { join } from "node:path";
|
||
import { downloadTo, searchSounds } from "./heygen.mjs";
|
||
|
||
const SFX_VOLUME = 0.35;
|
||
const slug = (s) =>
|
||
s
|
||
.toLowerCase()
|
||
.replace(/[^a-z0-9]+/g, "-")
|
||
.replace(/^-+|-+$/g, "")
|
||
.slice(0, 40) || "x";
|
||
const r3 = (x) => Number(x.toFixed(3));
|
||
|
||
// cues: [{ id, name }] (id = the line/frame/scene the cue fires in). Returns
|
||
// { sfx: [{ id, name, file, source, offset_s, duration_s, volume }], anomalies }.
|
||
export async function resolveSfx({ cues, heygenOK, headers, hyperframesDir, sfxLibDir }) {
|
||
const sfx = [];
|
||
const anomalies = [];
|
||
const destDir = join(hyperframesDir, "assets", "sfx");
|
||
|
||
// Dedupe identical (id,name) cues — the same effect named twice in one line
|
||
// downloads/copies once.
|
||
const seen = new Set();
|
||
const uniq = cues.filter((c) => {
|
||
const k = `${c.id}:${c.name}`;
|
||
if (seen.has(k)) return false;
|
||
seen.add(k);
|
||
return true;
|
||
});
|
||
|
||
if (heygenOK) {
|
||
for (const { id, name } of uniq) {
|
||
try {
|
||
// SFX hits score low (~0.5–0.67), below the API's default 0.7 which
|
||
// silently drops most named cues — floor to 0.4. (BGM/music score high
|
||
// and keep the default.)
|
||
const results = await searchSounds(name, "sound_effects", headers, {
|
||
limit: 3,
|
||
minScore: 0.4,
|
||
});
|
||
if (!results.length) {
|
||
anomalies.push(`sfx "${name}" (id ${id}): no HeyGen match — skipped`);
|
||
continue;
|
||
}
|
||
const top = results[0];
|
||
const file = `assets/sfx/${slug(name)}.mp3`;
|
||
await downloadTo(top.audio_url, join(hyperframesDir, file));
|
||
sfx.push({
|
||
id,
|
||
name,
|
||
file,
|
||
source: "heygen",
|
||
offset_s: 0,
|
||
duration_s: typeof top.duration === "number" ? r3(top.duration) : 1.0,
|
||
volume: SFX_VOLUME,
|
||
});
|
||
} catch (e) {
|
||
anomalies.push(`sfx "${name}" (id ${id}): retrieval failed — ${e.message}`);
|
||
}
|
||
}
|
||
return { sfx, anomalies };
|
||
}
|
||
|
||
// ── offline: bundled library ──
|
||
const manifestPath = join(sfxLibDir, "manifest.json");
|
||
if (!existsSync(manifestPath)) {
|
||
if (uniq.length)
|
||
anomalies.push(`no HeyGen credential and no SFX library at ${sfxLibDir} — all cues dropped`);
|
||
return { sfx, anomalies };
|
||
}
|
||
let manifest;
|
||
try {
|
||
manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
||
} catch (e) {
|
||
anomalies.push(`SFX manifest parse failed (${e.message}) — all cues dropped`);
|
||
return { sfx, anomalies };
|
||
}
|
||
// Build lookups: by manifest key, by file basename, and by slug of either, so
|
||
// a cue can name "whoosh", "whoosh.mp3", or "ui click" (→ slug match).
|
||
const byKey = new Map();
|
||
for (const [key, entry] of Object.entries(manifest)) {
|
||
if (!entry?.file || !isFinite(entry.duration)) continue;
|
||
const rec = { key, file: entry.file, duration: entry.duration };
|
||
byKey.set(key, rec);
|
||
byKey.set(entry.file, rec);
|
||
byKey.set(slug(key), rec);
|
||
byKey.set(slug(entry.file.replace(/\.\w+$/, "")), rec);
|
||
}
|
||
mkdirSync(destDir, { recursive: true });
|
||
for (const { id, name } of uniq) {
|
||
const hit = byKey.get(name) ?? byKey.get(slug(name));
|
||
if (!hit) {
|
||
const known = [...new Set([...byKey.values()].map((v) => v.key))].slice(0, 8).join(", ");
|
||
anomalies.push(
|
||
`sfx "${name}" (id ${id}): not in bundled library — skipped (have: ${known}…)`,
|
||
);
|
||
continue;
|
||
}
|
||
const src = join(sfxLibDir, hit.file);
|
||
const destRel = `assets/sfx/${hit.file}`;
|
||
const dest = join(hyperframesDir, destRel);
|
||
if (existsSync(src) && !existsSync(dest)) copyFileSync(src, dest);
|
||
sfx.push({
|
||
id,
|
||
name,
|
||
file: destRel,
|
||
source: "local",
|
||
offset_s: 0,
|
||
duration_s: r3(hit.duration),
|
||
volume: SFX_VOLUME,
|
||
});
|
||
}
|
||
return { sfx, anomalies };
|
||
}
|