mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
fix: muted preview/render parity, tts --out alias, HYPERFRAMES_PYTHON override
- producer: muted media elements were silent in preview but mixed at full volume in renders. discoverMediaFromBrowser now carries the muted flag and the probe stage prunes muted audio from the mix and clears hasAudio on muted video (pruneMutedBrowserMedia, pure + unit-tested). Verified live: a muted-voices composition now renders the exact same duck envelope as a bgm-only one. - cli tts: accept --out alongside -o/--output (was silently ignored and wrote speech.wav into the cwd). - cli tts: HYPERFRAMES_PYTHON env override for the python probe, for machines whose PATH python3 is too old for kokoro-onnx (system python on stock macOS); error messages mention it.
This commit is contained in:
@@ -48,7 +48,7 @@ export default defineCommand({
|
||||
output: {
|
||||
type: "string",
|
||||
description: "Output file path (default: speech.wav in current directory)",
|
||||
alias: "o",
|
||||
alias: ["o", "out"],
|
||||
},
|
||||
voice: {
|
||||
type: "string",
|
||||
|
||||
@@ -8,8 +8,21 @@
|
||||
|
||||
import { execFileSync } from "node:child_process";
|
||||
|
||||
/** Locate a `python3` (or `python`) on PATH that reports as Python 3. */
|
||||
/** Locate a Python 3: `HYPERFRAMES_PYTHON` env override first, then PATH. */
|
||||
export function findPython(): string | undefined {
|
||||
const override = process.env.HYPERFRAMES_PYTHON;
|
||||
if (override) {
|
||||
try {
|
||||
const version = execFileSync(override, ["--version"], {
|
||||
encoding: "utf-8",
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
timeout: 5000,
|
||||
});
|
||||
if (/Python 3/.test(version)) return override;
|
||||
} catch {
|
||||
// fall through to the PATH probe
|
||||
}
|
||||
}
|
||||
for (const name of ["python3", "python"]) {
|
||||
try {
|
||||
const cmd = process.platform === "win32" ? "where" : "which";
|
||||
|
||||
@@ -124,13 +124,13 @@ export async function synthesize(
|
||||
const python = findPython();
|
||||
if (!python) {
|
||||
throw new Error(
|
||||
"Python 3 is required for text-to-speech. Install Python 3.8+ and run: pip install kokoro-onnx soundfile",
|
||||
"Python 3 is required for text-to-speech. Install Python 3.10+ and run: pip install kokoro-onnx soundfile (or point HYPERFRAMES_PYTHON at a venv python that has them)",
|
||||
);
|
||||
}
|
||||
|
||||
if (!hasPythonPackage(python, "kokoro_onnx")) {
|
||||
throw new Error(
|
||||
"The kokoro-onnx package is not installed. Run: pip install kokoro-onnx soundfile",
|
||||
"The kokoro-onnx package is not installed. Run: pip install kokoro-onnx soundfile (or point HYPERFRAMES_PYTHON at a venv python that has them)",
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1731,6 +1731,8 @@ export interface BrowserMediaElement {
|
||||
loop: boolean;
|
||||
hasAudio: boolean;
|
||||
volume: number;
|
||||
/** The `muted` attribute/property. Preview silences muted media; the mix must too. */
|
||||
muted: boolean;
|
||||
}
|
||||
|
||||
export interface BrowserAudioVolumeAutomation {
|
||||
@@ -1751,6 +1753,7 @@ export async function discoverMediaFromBrowser(page: Page): Promise<BrowserMedia
|
||||
loop: boolean;
|
||||
hasAudio: boolean;
|
||||
volume: number;
|
||||
muted: boolean;
|
||||
}[] = [];
|
||||
|
||||
const mediaEls = document.querySelectorAll("video[data-start], audio[data-start]");
|
||||
@@ -1767,6 +1770,7 @@ export async function discoverMediaFromBrowser(page: Page): Promise<BrowserMedia
|
||||
const loop = htmlEl.hasAttribute("loop");
|
||||
const hasAudio = htmlEl.getAttribute("data-has-audio") === "true";
|
||||
const volume = parseFloat(htmlEl.getAttribute("data-volume") || "1");
|
||||
const muted = htmlEl.hasAttribute("muted") || htmlEl.muted;
|
||||
|
||||
results.push({
|
||||
id,
|
||||
@@ -1779,6 +1783,7 @@ export async function discoverMediaFromBrowser(page: Page): Promise<BrowserMedia
|
||||
loop,
|
||||
hasAudio,
|
||||
volume,
|
||||
muted,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { pruneMutedBrowserMedia } from "./probeStage.js";
|
||||
|
||||
describe("pruneMutedBrowserMedia", () => {
|
||||
it("drops muted audio from the mix and clears hasAudio on muted video", () => {
|
||||
const composition = {
|
||||
videos: [
|
||||
{ id: "clip", hasAudio: true },
|
||||
{ id: "other", hasAudio: true },
|
||||
],
|
||||
audios: [{ id: "bgm" }, { id: "voice" }],
|
||||
};
|
||||
const ids = new Set(["bgm", "voice"]);
|
||||
pruneMutedBrowserMedia(
|
||||
composition,
|
||||
[
|
||||
{ id: "clip", tagName: "video", muted: true },
|
||||
{ id: "voice", tagName: "audio", muted: true },
|
||||
{ id: "bgm", tagName: "audio", muted: false },
|
||||
],
|
||||
ids,
|
||||
);
|
||||
expect(composition.audios.map((a) => a.id)).toEqual(["bgm"]);
|
||||
expect(ids.has("voice")).toBe(false);
|
||||
expect(composition.videos.find((v) => v.id === "clip")?.hasAudio).toBe(false);
|
||||
expect(composition.videos.find((v) => v.id === "other")?.hasAudio).toBe(true);
|
||||
});
|
||||
|
||||
it("is a no-op when nothing is muted", () => {
|
||||
const composition = { videos: [{ id: "v", hasAudio: true }], audios: [{ id: "a" }] };
|
||||
pruneMutedBrowserMedia(composition, [
|
||||
{ id: "v", tagName: "video", muted: false },
|
||||
{ id: "a", tagName: "audio" },
|
||||
]);
|
||||
expect(composition.audios.length).toBe(1);
|
||||
expect(composition.videos[0]?.hasAudio).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -293,8 +293,11 @@ export async function runProbeStage(input: ProbeStageInput): Promise<ProbeStageR
|
||||
const existingVideoIds = new Set(composition.videos.map((v) => v.id));
|
||||
const existingAudioIds = new Set(composition.audios.map((a) => a.id));
|
||||
|
||||
pruneMutedBrowserMedia(composition, browserMedia, existingAudioIds);
|
||||
|
||||
for (const el of browserMedia) {
|
||||
if (!el.src || el.src === "about:blank") continue;
|
||||
if (el.muted && el.tagName === "audio") continue;
|
||||
|
||||
// Convert absolute localhost URLs back to relative paths
|
||||
let src = el.src;
|
||||
@@ -328,7 +331,7 @@ export async function runProbeStage(input: ProbeStageInput): Promise<ProbeStageR
|
||||
) {
|
||||
existing.mediaStart = el.mediaStart;
|
||||
}
|
||||
if (el.hasAudio && !existing.hasAudio) {
|
||||
if (el.hasAudio && !el.muted && !existing.hasAudio) {
|
||||
existing.hasAudio = true;
|
||||
}
|
||||
if (el.loop && !existing.loop) {
|
||||
@@ -344,7 +347,7 @@ export async function runProbeStage(input: ProbeStageInput): Promise<ProbeStageR
|
||||
end: el.end,
|
||||
mediaStart: el.mediaStart,
|
||||
loop: el.loop,
|
||||
hasAudio: el.hasAudio,
|
||||
hasAudio: el.hasAudio && !el.muted,
|
||||
});
|
||||
existingVideoIds.add(el.id);
|
||||
}
|
||||
@@ -525,3 +528,31 @@ export async function runProbeStage(input: ProbeStageInput): Promise<ProbeStageR
|
||||
browserProbeMs,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Preview/render parity for `muted` media: the runtime keeps muted elements
|
||||
* silent, so the mixer must exclude their audio too (they used to be mixed at
|
||||
* full volume). Muted video still renders frames but loses its audio track;
|
||||
* muted audio drops out of the mix entirely. Pure over its inputs so the
|
||||
* parity rule is testable without the probe-session harness.
|
||||
*/
|
||||
export function pruneMutedBrowserMedia(
|
||||
composition: {
|
||||
videos: { id: string; hasAudio?: boolean }[];
|
||||
audios: { id: string }[];
|
||||
},
|
||||
browserMedia: { id: string; tagName: string; muted?: boolean }[],
|
||||
existingAudioIds?: Set<string>,
|
||||
): void {
|
||||
for (const el of browserMedia) {
|
||||
if (!el.muted) continue;
|
||||
if (el.tagName === "video") {
|
||||
const existing = composition.videos.find((v) => v.id === el.id);
|
||||
if (existing) existing.hasAudio = false;
|
||||
} else {
|
||||
const idx = composition.audios.findIndex((a) => a.id === el.id);
|
||||
if (idx >= 0) composition.audios.splice(idx, 1);
|
||||
existingAudioIds?.delete(el.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user