From 592d627c90ca295be4b8bc0b1f66becc391c7c3c Mon Sep 17 00:00:00 2001 From: Miguel Angel Simon Sierra Date: Sat, 4 Jul 2026 13:14:02 -0700 Subject: [PATCH] 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. --- packages/cli/src/commands/tts.ts | 2 +- packages/cli/src/tts/python.ts | 15 +++++++- packages/cli/src/tts/synthesize.ts | 4 +- .../producer/src/services/htmlCompiler.ts | 5 +++ .../render/stages/mutedParity.test.ts | 38 +++++++++++++++++++ .../src/services/render/stages/probeStage.ts | 35 ++++++++++++++++- 6 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 packages/producer/src/services/render/stages/mutedParity.test.ts diff --git a/packages/cli/src/commands/tts.ts b/packages/cli/src/commands/tts.ts index bf0bc03c1b..1938c3a6b3 100644 --- a/packages/cli/src/commands/tts.ts +++ b/packages/cli/src/commands/tts.ts @@ -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", diff --git a/packages/cli/src/tts/python.ts b/packages/cli/src/tts/python.ts index 13e6111d40..5c849b06a5 100644 --- a/packages/cli/src/tts/python.ts +++ b/packages/cli/src/tts/python.ts @@ -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"; diff --git a/packages/cli/src/tts/synthesize.ts b/packages/cli/src/tts/synthesize.ts index cc887b81f2..403b2fadbe 100644 --- a/packages/cli/src/tts/synthesize.ts +++ b/packages/cli/src/tts/synthesize.ts @@ -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)", ); } diff --git a/packages/producer/src/services/htmlCompiler.ts b/packages/producer/src/services/htmlCompiler.ts index b0dd795080..99114046c9 100644 --- a/packages/producer/src/services/htmlCompiler.ts +++ b/packages/producer/src/services/htmlCompiler.ts @@ -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 { + 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); + }); +}); diff --git a/packages/producer/src/services/render/stages/probeStage.ts b/packages/producer/src/services/render/stages/probeStage.ts index 3dbc45b7c0..9f1365d8eb 100644 --- a/packages/producer/src/services/render/stages/probeStage.ts +++ b/packages/producer/src/services/render/stages/probeStage.ts @@ -293,8 +293,11 @@ export async function runProbeStage(input: ProbeStageInput): Promise 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, +): 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); + } + } +}