mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 11:26:02 +00:00
* feat(cli): move media-use engine into the CLI * fix(cli): replace media-use compatibility asset * fix(cli): replace moved media-use tree * fix(cli): copy moved media-use files cleanly * fix(cli): copy media-use engine files individually * fix(cli): keep audio helper compatibility import * fix(cli): clear copied skill destinations * test(cli): preserve moved media-use test paths * fix(cli): preserve media-use script compatibility imports * fix(cli): preserve media-use telemetry shim * fix(cli): resolve packaged media-use LUT assets * fix(cli): resolve packaged bundled SFX assets * chore(skills): regenerate media-use manifest * fix(cli): preserve media-use parity coverage * fix(cli): cover relocated media-use tests * chore(skills): regenerate media-use manifest * fix(cli): format bundled media provider * fix(ci): run relocated media-use tests with node * fix(ci): preserve fallow script exemptions * fix(ci): scope media-use fallow exemption * refactor(cli): trim media-use essay comments * feat(cli): index media-use assets for catalog search * feat(catalog): commit media-use search vectors * chore(catalog): track media vector metadata * fix(catalog): validate media vector row order * fix(catalog): validate media artifact freshness * fix(catalog): cover media metadata and credits * fix(cli): reject malformed media rows * fix(catalog): compare complete media rows * feat(cli): route media search through media-use * refactor(cli): trim relocated media-use comments * fix(cli): make media search runtime-safe * fix(cli): preserve sfx fallback diagnostics * fix(cli): probe sfx fallback provider explicitly * chore(skills): regenerate manifest * refactor(cli): keep typed media ranker source * fix(cli): align media search checks with local-first flow * fix(cli): scope vector audit exceptions * fix(cli): ship resolver registry beside skill * fix(cli): keep media-use skill scripts standalone * test(cli): cover local vector validation * test(cli): correct media vector fixtures * fix(cli): prefer exact media keys * fix(cli): stem exact media keys * test(cli): skip media lint for snippets without media * fix(cli): align skills test discovery Keep the CI skills job's bash discovery as the single source of truth so its empty-list guard covers the exact files Node executes. Make hasMediaVectors private because it has no external callers and needs no Fallow suppression. * fix(cli): close media-use review gaps Prioritize literal ids before stemmed ids and cover the collision alongside the plural regression. Add command seam tests for engine discovery, actionable failure, and argv passthrough. Add a deterministic parity check for standalone media-use copies, with documented allowlists for the standalone media-fetch shim and self-contained npx resolver. Keep the bash-discovered skills test list as the CI source of truth. * fix(cli): lower parity check complexity Split missing-copy and unallowlisted-drift checks so the parity guard keeps its behavior without a threshold CRAP score. * fix(cli): close media-use review seams Run the parity test in the skills job so skills-only edits exercise the same check. Export the verb mapping and inject command dispatch for direct coverage. Keep missing-copy diagnostics separate from drift reads.
96 lines
3.2 KiB
JavaScript
96 lines
3.2 KiB
JavaScript
import { wordListsFromMediaMeta } from "./words.mjs";
|
|
|
|
// audio_meta.json word times are relative to each line's own file.
|
|
export function speechSpans(meta, { mergeGap = 0.6, offsets, sequential = false, gap = 0 } = {}) {
|
|
const merge = Number(mergeGap);
|
|
const lists = wordListsFromMediaMeta(meta);
|
|
const voices = Array.isArray(meta?.voices) ? meta.voices : [];
|
|
if (lists.length > 1 && !offsets && !sequential) {
|
|
throw new Error(
|
|
"audio_meta has multiple voice lines with file-relative times; pass --sequential or --offsets so spans land at composition time",
|
|
);
|
|
}
|
|
const intervals = [];
|
|
let cursor = 0;
|
|
for (let i = 0; i < lists.length; i++) {
|
|
const voice = voices[i];
|
|
let offset = 0;
|
|
if (offsets) {
|
|
const id = voice?.id ?? String(i);
|
|
if (!(id in offsets)) throw new Error(`--offsets is missing voice "${id}"`);
|
|
offset = Number(offsets[id]) || 0;
|
|
} else if (sequential) {
|
|
offset = cursor;
|
|
const lineDuration = Number(voice?.duration_s) || Math.max(...lists[i].map((w) => w.end), 0);
|
|
cursor += lineDuration + (Number(gap) || 0);
|
|
}
|
|
for (const word of lists[i]) {
|
|
if (word.end > word.start)
|
|
intervals.push({ start: word.start + offset, end: word.end + offset });
|
|
}
|
|
}
|
|
return mergeIntervals(intervals, Number.isFinite(merge) && merge >= 0 ? merge : 0.6);
|
|
}
|
|
|
|
export function duckKeyframes(
|
|
spans,
|
|
{ duck = 0.25, attack = 0.15, release = 0.4, baseVolume = 1 } = {},
|
|
) {
|
|
const base = finiteOr(baseVolume, 1);
|
|
const ducked = round3(base * finiteOr(duck, 0.25));
|
|
const keyframes = [];
|
|
for (const span of spans) {
|
|
keyframes.push({
|
|
time: round3(Math.max(0, finiteOr(span.start, 0))),
|
|
volume: ducked,
|
|
duration: round3(finiteOr(attack, 0.15)),
|
|
});
|
|
keyframes.push({
|
|
time: round3(Math.max(0, finiteOr(span.end, 0))),
|
|
volume: round3(base),
|
|
duration: round3(finiteOr(release, 0.4)),
|
|
});
|
|
}
|
|
return keyframes.sort((a, b) => a.time - b.time);
|
|
}
|
|
|
|
/** Volume lane for `data-automation`: composition-time keyframes as clip-local ramps. */
|
|
export function duckLane(keyframes, { clipStart = 0, baseVolume = 1 } = {}) {
|
|
const start = finiteOr(clipStart, 0);
|
|
const points = [{ t: 0, v: round3(finiteOr(baseVolume, 1)) }];
|
|
const push = (t, v) => {
|
|
if (t > points.at(-1).t) points.push({ t: round3(t), v });
|
|
};
|
|
for (const kf of keyframes) {
|
|
const t = Math.max(0, kf.time - start);
|
|
push(t, points.at(-1).v);
|
|
push(t + kf.duration, kf.volume);
|
|
}
|
|
return { version: 1, lanes: [{ target: "volume", points }] };
|
|
}
|
|
|
|
function mergeIntervals(intervals, mergeGap) {
|
|
const sorted = intervals
|
|
.map((range) => ({ start: round3(range.start), end: round3(range.end) }))
|
|
.sort((a, b) => a.start - b.start || a.end - b.end);
|
|
const merged = [];
|
|
for (const range of sorted) {
|
|
const prev = merged.at(-1);
|
|
if (prev && (range.start <= prev.end || range.start - prev.end < mergeGap)) {
|
|
prev.end = Math.max(prev.end, range.end);
|
|
} else {
|
|
merged.push({ ...range });
|
|
}
|
|
}
|
|
return merged;
|
|
}
|
|
|
|
function finiteOr(value, fallback) {
|
|
const n = Number(value);
|
|
return Number.isFinite(n) ? n : fallback;
|
|
}
|
|
|
|
function round3(n) {
|
|
return Math.round(Number(n) * 1000) / 1000;
|
|
}
|