Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Clean the voice first: on for a clip in Lipsync, the time or price under the words on a phone, and a browser check of the three composers

Claude0da27fcddad3
diff --git a/src/components/studio/voice-first-switch.tsx b/src/components/studio/voice-first-switch.tsx
index 68fbea59..a83201eb 100644
--- a/src/components/studio/voice-first-switch.tsx
+++ b/src/components/studio/voice-first-switch.tsx
@@ -45,13 +45,14 @@ export function VoiceFirstSwitch({
const line = price ?? voiceFirstLine({ engine, seconds, device, bed, getModel });
return (
<div className={cn("flex min-w-0 flex-col gap-0.5", className)} data-voice-first>
- <div className="flex min-w-0 items-start gap-2">
+ {/* On a phone the time or price goes under the words, so they keep the width. */}
+ <div className="flex min-w-0 flex-wrap items-start gap-x-2 gap-y-0.5">
<Switch id={id} checked={on} onCheckedChange={onChange} className="mt-px shrink-0" />
<label htmlFor={id} className="min-w-0 flex-1 text-[12px] leading-snug">
<span className="font-medium">{VOICE_FIRST_LABEL}</span>
<span className="text-muted-foreground"> · {VOICE_FIRST_HINTS[engine]}</span>
</label>
- <span className="shrink-0 font-mono text-[11px] text-muted-foreground tabular-nums">{line}</span>
+ <span className="basis-full pl-11 font-mono text-[11px] text-muted-foreground tabular-nums sm:basis-auto sm:shrink-0 sm:pl-0">{line}</span>
</div>
{clip && <p className="pl-11 text-[11.5px] leading-snug text-muted-foreground">{BED_NOTES[engine]}</p>}
</div>
diff --git a/src/lib/av/voice-first.ts b/src/lib/av/voice-first.ts
index 476fb4e8..0a1890e5 100644
--- a/src/lib/av/voice-first.ts
+++ b/src/lib/av/voice-first.ts
@@ -62,14 +62,14 @@ export function voiceSource(req: Pick<GenerationRequest, "inputs">, op: Operatio
}
/**
- * The switch's default: on when the speech comes with a picture (a video to transcribe, a clip to re-sync), off for an
- * audio upload, which is usually speech alone.
+ * The switch's default: on when the speech comes with a picture (a video to transcribe, a clip in Lipsync), off for an
+ * audio upload with a portrait, or a recording to transcribe, which is usually speech alone.
*/
export function voiceFirstDefault(req: Pick<GenerationRequest, "inputs">, op: Operation | undefined): boolean {
const src = voiceSource(req, op);
if (!src) return false;
if (op === "transcribe") return src.slot === "video";
- return op === "lipsync" && !!req.inputs?.video;
+ return !!req.inputs?.video;
}
/** Whether a run puts the clip's music and effects back after the lip sync (open engine, a clip with sound). */
diff --git a/tests/e2e/voice-first.mjs b/tests/e2e/voice-first.mjs
new file mode 100644
index 00000000..481adfda
--- /dev/null
+++ b/tests/e2e/voice-first.mjs
@@ -0,0 +1,125 @@
+// Browser check of "Clean the voice first" (DBS D6).
+// Usage: node tests/e2e/voice-first.mjs [appUrl] [outDir] (the app in demo mode: no keys, no ComfyUI)
+// Checks, at 1440 px and 390 px in light and dark: Transcribe with a video shows the switch on with its hint and "Free ·
+// adds …" on the open engine, and its price on the cloud; with a recording only, off. Lipsync with a clip and a voice
+// shows it on and says the clip's music and effects go back (open) or don't (cloud). Captions shows it on under
+// "Transcribe the speech". Toggling never changes the composer's height, nothing scrolls sideways, no console errors.
+// Screenshots go to outDir.
+import { spawnSync } from "node:child_process";
+import fs from "node:fs";
+import path from "node:path";
+import { DESKTOP, PHONE, launch, openRoute } from "./_browser.mjs";
+
+const args = process.argv.slice(2).filter((a) => !a.startsWith("--"));
+const app = args[0] ?? "http://localhost:3000";
+const out = args[1] ?? fs.mkdtempSync("/tmp/fuobe-voice-first-");
+fs.mkdirSync(out, { recursive: true });
+
+const ff = (a) => {
+ const r = spawnSync("ffmpeg", ["-hide_banner", "-loglevel", "error", "-y", ...a]);
+ if (r.status !== 0) throw new Error(`ffmpeg failed: ${r.stderr}`);
+};
+const wav = path.join(out, "speech.wav");
+const mp4 = path.join(out, "clip.mp4");
+ff(["-f", "lavfi", "-i", "aevalsrc=0.2*sin(2*PI*330*t):s=44100:d=6", wav]);
+ff(["-f", "lavfi", "-i", "color=c=teal:s=640x360:d=6:r=25", "-f", "lavfi", "-i", "aevalsrc=0.2*sin(2*PI*220*t)|0.2*sin(2*PI*277*t):s=44100:d=6", "-shortest", "-c:v", "libx264", "-pix_fmt", "yuv420p", "-c:a", "aac", mp4]);
+
+const failures = [];
+const check = (ok, what) => {
+ console.log(`${ok ? "✓" : "✗"} ${what}`);
+ if (!ok) failures.push(what);
+};
+async function noSideScroll(page, label) {
+ const over = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
+ check(over <= 0, `${label}: no horizontal scroll (${over}px)`);
+}
+function watchConsole(page, label) {
+ page.on("console", (m) => m.type() === "error" && check(false, `${label}: console error: ${m.text().slice(0, 200)}`));
+ page.on("pageerror", (e) => check(false, `${label}: page error: ${e.message.slice(0, 200)}`));
+}
+const sw = (page) => page.locator("[data-voice-first]").first();
+const switchOn = async (page) => (await sw(page).getByRole("switch").getAttribute("aria-checked")) === "true";
+const box = (page, sel) => page.locator(sel).first().boundingBox();
+
+/** Toggle twice: the block's own height and the composer's never change. */
+async function noShift(page, label, holder) {
+ const before = [await box(page, "[data-voice-first]"), holder && (await box(page, holder))];
+ await sw(page).getByRole("switch").click();
+ await page.waitForTimeout(250);
+ const mid = [await box(page, "[data-voice-first]"), holder && (await box(page, holder))];
+ await sw(page).getByRole("switch").click();
+ await page.waitForTimeout(250);
+ const same = (a, b) => !a || !b || Math.abs(a.height - b.height) < 0.5;
+ check(same(before[0], mid[0]) && same(before[1], mid[1]), `${label}: toggling moves nothing (${before[0]?.height} → ${mid[0]?.height})`);
+}
+
+const browser = await launch();
+try {
+ for (const [dname, device] of [
+ ["1440", DESKTOP],
+ ["390", PHONE],
+ ]) {
+ for (const theme of ["light", "dark"]) {
+ const label = `${dname} ${theme}`;
+ for (const engine of ["open", "cloud"]) {
+ const ctx = await browser.newContext({ ...device, colorScheme: theme });
+ await ctx.addInitScript(([e]) => localStorage.setItem("fuobe.engine", e), [engine]);
+ const page = await ctx.newPage();
+ const l = `${label} ${engine}`;
+ watchConsole(page, l);
+
+ // Transcribe: a video → on, with its time or price.
+ await openRoute(page, `${app}/audio/transcribe`);
+ await page.locator('[data-slot-key="video"] input[type="file"]').setInputFiles(mp4);
+ await sw(page).waitFor({ timeout: 60_000 });
+ check(await switchOn(page), `${l} Transcribe: on for a video`);
+ const line = engine === "open" ? /Free · adds (under|about)/ : /\+\$0\.0\d$/;
+ await sw(page).getByText(line).waitFor({ timeout: 30_000 }).catch(() => {});
+ const text = (await sw(page).innerText()).replace(/\s+/g, " ");
+ check(line.test(text), `${l} Transcribe: says what it adds (“${text}”)`);
+ await noShift(page, `${l} Transcribe`, "[data-composer]");
+ await page.screenshot({ path: path.join(out, `transcribe-${engine}-${dname}-${theme}.png`), fullPage: true });
+ await noSideScroll(page, `${l} Transcribe`);
+ // A recording only → off.
+ await page.getByRole("button", { name: "Remove Video" }).first().click();
+ await page.locator('[data-slot-key="audio"] input[type="file"]').setInputFiles(wav);
+ await sw(page).waitFor({ timeout: 60_000 });
+ await page.waitForTimeout(500);
+ check(!(await switchOn(page)), `${l} Transcribe: off for a recording`);
+
+ // Lipsync: a clip and a voice → on, and what happens to the clip's music and effects.
+ // A lip re-sync model on each engine (the studio opens on a talking-avatar model).
+ await openRoute(page, `${app}/lipsync?model=${engine === "open" ? "oss-infinitetalk-v2v" : "sync-lipsync-3"}`);
+ await page.locator('[data-slot-key="video"] input[type="file"]').setInputFiles(mp4);
+ await page.locator('[data-slot-key="audio"] input[type="file"]').setInputFiles(wav);
+ await sw(page).waitFor({ timeout: 60_000 });
+ // The voice's header times or prices the step (a moment after the upload).
+ await sw(page).getByText(engine === "open" ? /Free · adds (under|about)/ : /\+\$0\.0\d$/).waitFor({ timeout: 30_000 }).catch(() => {});
+ check(await switchOn(page), `${l} Lipsync: on for a re-sync of a clip`);
+ const note = engine === "open" ? "go back under the new lip movement" : "keeps the clean voice only";
+ await sw(page).getByText(note).waitFor({ timeout: 30_000 }).catch(() => {});
+ check(await sw(page).getByText(note).isVisible(), `${l} Lipsync: says what happens to the clip's music and effects`);
+ await noShift(page, `${l} Lipsync`, "[data-composer]");
+ await page.screenshot({ path: path.join(out, `lipsync-${engine}-${dname}-${theme}.png`), fullPage: true });
+ await noSideScroll(page, `${l} Lipsync`);
+
+ // Captions: on under "Transcribe the speech".
+ await openRoute(page, `${app}/video-tools/captions`);
+ await page.locator('input[type="file"]').first().setInputFiles(mp4);
+ await sw(page).waitFor({ timeout: 60_000 });
+ // The player reads the clip's length, which prices the cloud's step.
+ if (engine === "cloud") await sw(page).getByText(/\+\$0\.0\d$/).waitFor({ timeout: 30_000 }).catch(() => {});
+ check(await switchOn(page), `${l} Captions: on`);
+ check(await page.getByRole("button", { name: /Transcribe the speech/ }).isVisible(), `${l} Captions: beside Transcribe the speech`);
+ await noShift(page, `${l} Captions`);
+ await page.screenshot({ path: path.join(out, `captions-${engine}-${dname}-${theme}.png`), fullPage: true });
+ await noSideScroll(page, `${l} Captions`);
+ await ctx.close();
+ }
+ }
+ }
+} finally {
+ await browser.close();
+}
+console.log(failures.length ? `\n${failures.length} failed (screenshots in ${out})` : `\nAll good (screenshots in ${out})`);
+process.exit(failures.length ? 1 : 0);
diff --git a/tests/voice-first.test.ts b/tests/voice-first.test.ts
index 4fb85c81..7ab729a8 100644
--- a/tests/voice-first.test.ts
+++ b/tests/voice-first.test.ts
@@ -62,6 +62,7 @@ describe("where it applies, and its default", () => {
expect(voiceFirstDefault({ inputs: { audio: AUDIO } }, "transcribe")).toBe(false);
expect(voiceFirstDefault({ inputs: { video: VIDEO, audio: AUDIO } }, "lipsync")).toBe(true);
expect(voiceFirstDefault({ inputs: { images: ["/api/files/a.png"], audio: AUDIO } }, "avatar")).toBe(false);
+ expect(voiceFirstDefault({ inputs: { video: VIDEO, audio: AUDIO } }, "avatar")).toBe(true);
});
it("puts the music and effects back only after a lip re-sync on your GPU of a clip with sound", () => {