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 up voice: the brasserie demo's photos and clips

Adarshc5cefc96ce9c
diff --git a/public/samples/clean-voice/clean.m4a b/public/samples/clean-voice/clean.m4a
new file mode 100644
index 00000000..0f69356d
Binary files /dev/null and b/public/samples/clean-voice/clean.m4a differ
diff --git a/public/samples/clean-voice/noisy.m4a b/public/samples/clean-voice/noisy.m4a
new file mode 100644
index 00000000..35b36e43
Binary files /dev/null and b/public/samples/clean-voice/noisy.m4a differ
diff --git a/public/samples/clean-voice/quiet.webp b/public/samples/clean-voice/quiet.webp
new file mode 100644
index 00000000..422e9e9f
Binary files /dev/null and b/public/samples/clean-voice/quiet.webp differ
diff --git a/public/samples/clean-voice/room.webp b/public/samples/clean-voice/room.webp
new file mode 100644
index 00000000..fe50c70d
Binary files /dev/null and b/public/samples/clean-voice/room.webp differ
diff --git a/scripts/gen-clean-voice-demo.mjs b/scripts/gen-clean-voice-demo.mjs
index a9823c27..4d945a2b 100644
--- a/scripts/gen-clean-voice-demo.mjs
+++ b/scripts/gen-clean-voice-demo.mjs
@@ -1,18 +1,17 @@
#!/usr/bin/env node
/**
- * Makes Clean up voice's demo pairs (public/samples/clean-voice/) with the final ComfyUI-RE-USE pack, on a ComfyUI that
- * you name (it never guesses one): NVIDIA's sample at its own rate, and the same speech as an 8 kHz phone line restored
- * to 48 kHz. Needs ffmpeg on PATH for the AAC files.
+ * Makes Clean up voice's demo files (public/samples/clean-voice/, played by src/components/audio-tools/clean-voice-demo.tsx)
+ * from their full-size sources. Needs ffmpeg on PATH (with libwebp).
*
- * node scripts/gen-clean-voice-demo.mjs --comfy http://127.0.0.1:8190 --sample path/to/mic_test2.wav [--out public/samples/clean-voice]
- * node scripts/gen-clean-voice-demo.mjs --from <folder> [--out <folder>]
+ * node scripts/gen-clean-voice-demo.mjs --room room.png --quiet quiet.png --noisy noisy.wav --clean clean.wav
+ * [--start 0] [--out public/samples/clean-voice]
*
- * --from takes pairs already made (noisy-mic-before.wav, noisy-mic-after.wav, phone-before.wav, phone-after.wav) and only
- * finishes them. Finishing a pair: the lead-in before the first word is cut to 0.2 s (found on the clean side, whose
- * gaps are silent), and both sides get the same gain, to about -18 LUFS on the louder one, so their levels still match.
- *
- * A person listens to the pairs before they ship (noise and the whine gone, no robotic sound, no seams, the phone pair
- * fuller and not harsh), then sets DEMO_READY in src/lib/av/clean-voice.ts.
+ * --room the brasserie photo (4:3); --quiet the same photo with the room softened and dimmed around her.
+ * Both become 1280x960 WebP (room.webp, quiet.webp).
+ * --noisy the recording with the room in it; --clean her voice alone. Same moment, same length: the demo plays both
+ * from one clock and switches between them. Both are cut to the same 8 s from --start, made 48 kHz mono, and
+ * given the same gain (the louder one to about -16 LUFS), so switching only changes what is around her voice.
+ * They become AAC-LC 128 kb/s .m4a (noisy.m4a, clean.m4a), with no metadata.
*/
import { execFileSync, spawnSync } from 'node:child_process';
import fs from 'node:fs';
@@ -22,95 +21,45 @@ import { fileURLToPath } from 'node:url';
const HERE = path.dirname(fileURLToPath(import.meta.url));
const args = Object.fromEntries(process.argv.slice(2).reduce((a, v, i, all) => (v.startsWith('--') ? [...a, [v.slice(2), all[i + 1]]] : a), []));
-const comfy = args.comfy?.replace(/\/$/, '');
-if (!args.from && (!comfy || !args.sample)) {
- console.error('Usage: node scripts/gen-clean-voice-demo.mjs --comfy <ComfyUI URL> --sample <mic_test2.wav> [--out <folder>]\n node scripts/gen-clean-voice-demo.mjs --from <folder with the four WAVs> [--out <folder>]');
+const missing = ['room', 'quiet', 'noisy', 'clean'].filter((k) => !args[k]);
+if (missing.length) {
+ console.error(`Missing --${missing.join(', --')}\nUsage: node scripts/gen-clean-voice-demo.mjs --room <photo> --quiet <softened photo> --noisy <recording> --clean <voice alone> [--start <s>] [--out <folder>]`);
process.exit(2);
}
const out = path.resolve(args.out ?? path.join(HERE, '..', 'public', 'samples', 'clean-voice'));
-const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'clean-voice-demo-'));
-const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
-const ffmpeg = (...a) => execFileSync('ffmpeg', ['-nostdin', '-loglevel', 'error', '-y', ...a]);
-/** ffmpeg's report (stderr) for an analysis pass. */
-const analyse = (file, filter) => spawnSync('ffmpeg', ['-nostdin', '-hide_banner', '-i', file, '-af', filter, '-f', 'null', '-'], { encoding: 'utf8' }).stderr;
-
-const LEAD_IN = 0.2;
-const TARGET_LUFS = -18;
-
-async function upload(file) {
- const form = new FormData();
- form.append('image', new Blob([fs.readFileSync(file)]), path.basename(file));
- form.append('type', 'input');
- form.append('overwrite', 'true');
- const r = await fetch(`${comfy}/upload/image`, { method: 'POST', body: form });
- if (!r.ok) throw new Error(`upload ${r.status}`);
- return (await r.json()).name;
-}
+const start = Number(args.start ?? 0);
+const LENGTH = 8;
+const TARGET_LUFS = -16;
+const W = 1280;
+const H = 960;
-/** One clean on the ComfyUI: the FLAC it saved, written to `dest`. */
-async function clean(input, rate, dest) {
- const graph = JSON.parse(fs.readFileSync(path.join(HERE, '..', 'workflows', 'comfyui', 'voice-clean-reuse.json'), 'utf8'));
- graph['1'].inputs.audio = await upload(input);
- graph['3'].inputs.rate = rate;
- graph['4'].inputs.filename_prefix = 'fuobe/clean-voice-demo';
- const r = await fetch(`${comfy}/prompt`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prompt: graph }) });
- if (!r.ok) throw new Error(`prompt ${r.status}: ${await r.text()}`);
- const { prompt_id: id } = await r.json();
- for (;;) {
- await sleep(1000);
- const h = (await (await fetch(`${comfy}/history/${id}`)).json())[id];
- if (!h) continue;
- if (h.status?.status_str === 'error') throw new Error(JSON.stringify(h.status.messages ?? h.status));
- const f = h.outputs?.['4']?.audio?.[0];
- if (!f) continue;
- console.log('report', h.outputs['5']?.text?.[0]);
- const q = new URLSearchParams({ filename: f.filename, subfolder: f.subfolder ?? '', type: f.type });
- fs.writeFileSync(dest, Buffer.from(await (await fetch(`${comfy}/view?${q}`)).arrayBuffer()));
- return;
- }
-}
-
-/** Seconds before the first word: where the clean side's first silence (under -50 dB, 0.3 s or more) at the start ends. */
-function speechStart(cleanFile) {
- const log = analyse(cleanFile, 'silencedetect=noise=-50dB:d=0.3');
- const first = /silence_start: (-?[\d.]+)[\s\S]*?silence_end: ([\d.]+)/.exec(log);
- return first && Number(first[1]) <= 0.05 ? Number(first[2]) : 0;
-}
-
-/** Integrated loudness (LUFS) of a file. */
-function loudness(file) {
- const m = /I:\s+(-?[\d.]+) LUFS/.exec(analyse(file, 'ebur128=framelog=quiet'));
+const ffmpeg = (...a) => execFileSync('ffmpeg', ['-nostdin', '-loglevel', 'error', '-y', ...a]);
+/** Integrated loudness (LUFS) of a file, from ffmpeg's report. */
+const loudness = (file) => {
+ const log = spawnSync('ffmpeg', ['-nostdin', '-hide_banner', '-i', file, '-af', 'ebur128=framelog=quiet', '-f', 'null', '-'], { encoding: 'utf8' }).stderr;
+ const m = /I:\s+(-?[\d.]+) LUFS/.exec(log);
return m ? Number(m[1]) : NaN;
-}
+};
-/** A pair, finished: the same cut and the same gain on both sides, as AAC-LC 192 kb/s. */
-function finish(name, before, after) {
- const start = Math.max(0, speechStart(after) - LEAD_IN);
- const cut = (src, dest) => ffmpeg('-ss', start.toFixed(3), '-i', src, '-c:a', 'pcm_f32le', dest);
- const b = path.join(tmp, `${name}-before-cut.wav`);
- const a = path.join(tmp, `${name}-after-cut.wav`);
- cut(before, b);
- cut(after, a);
- const loudest = Math.max(loudness(b), loudness(a));
+fs.mkdirSync(out, { recursive: true });
+const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'clean-voice-demo-'));
+try {
+ for (const name of ['room', 'quiet']) {
+ ffmpeg('-i', args[name], '-vf', `scale=${W}:${H}:flags=lanczos:force_original_aspect_ratio=increase,crop=${W}:${H}`, '-map_metadata', '-1', '-c:v', 'libwebp', '-quality', '82', '-compression_level', '6', path.join(out, `${name}.webp`));
+ }
+ const cut = Object.fromEntries(
+ ['noisy', 'clean'].map((name) => {
+ const file = path.join(tmp, `${name}.wav`);
+ ffmpeg('-ss', start.toFixed(3), '-t', String(LENGTH), '-i', args[name], '-ac', '1', '-ar', '48000', '-c:a', 'pcm_f32le', file);
+ return [name, file];
+ }),
+ );
+ const loudest = Math.max(loudness(cut.noisy), loudness(cut.clean));
const gain = Number.isFinite(loudest) ? TARGET_LUFS - loudest : 0;
- for (const [src, side] of [[b, 'before'], [a, 'after']]) {
- ffmpeg('-i', src, '-af', `volume=${gain.toFixed(2)}dB,alimiter=limit=0.89:level=false`, '-c:a', 'aac', '-b:a', '192k', '-movflags', '+faststart', path.join(out, `${name}-${side}.m4a`));
+ for (const [name, file] of Object.entries(cut)) {
+ ffmpeg('-i', file, '-af', `volume=${gain.toFixed(2)}dB,alimiter=limit=0.95:level=false`, '-map_metadata', '-1', '-fflags', '+bitexact', '-c:a', 'aac', '-b:a', '128k', '-movflags', '+faststart', path.join(out, `${name}.m4a`));
}
- console.log(`${name}: cut ${start.toFixed(2)} s of lead-in, gain ${gain.toFixed(1)} dB on both sides`);
-}
-
-fs.mkdirSync(out, { recursive: true });
-const src = args.from ? path.resolve(args.from) : tmp;
-if (!args.from) {
- const phone = path.join(tmp, 'phone-before.wav');
- ffmpeg('-i', args.sample, '-ac', '1', '-ar', '8000', phone);
- ffmpeg('-i', args.sample, path.join(tmp, 'noisy-mic-before.wav'));
- await clean(args.sample, 'source', path.join(tmp, 'noisy-mic-after.flac'));
- await clean(phone, '48000', path.join(tmp, 'phone-after.flac'));
- ffmpeg('-i', path.join(tmp, 'noisy-mic-after.flac'), path.join(tmp, 'noisy-mic-after.wav'));
- ffmpeg('-i', path.join(tmp, 'phone-after.flac'), path.join(tmp, 'phone-after.wav'));
+ console.log(`Wrote room.webp, quiet.webp, noisy.m4a and clean.m4a to ${out} (${LENGTH} s from ${start} s, gain ${gain.toFixed(1)} dB on both clips)`);
+} finally {
+ fs.rmSync(tmp, { recursive: true, force: true });
}
-finish('noisy-mic', path.join(src, 'noisy-mic-before.wav'), path.join(src, 'noisy-mic-after.wav'));
-finish('phone', path.join(src, 'phone-before.wav'), path.join(src, 'phone-after.wav'));
-fs.rmSync(tmp, { recursive: true, force: true });
-console.log(`Wrote the demo pairs to ${out}. Listen to them before they ship.`);
diff --git a/src/lib/licences.ts b/src/lib/licences.ts
index 29ffce63..c056ec8d 100644
--- a/src/lib/licences.ts
+++ b/src/lib/licences.ts
@@ -540,12 +540,6 @@ export const ATTRIBUTIONS: Attribution[] = [
url: "https://huggingface.co/nvidia/NVIDIA-NemotronLabs-RE-USE",
note: "Trained in part on WSJ (LDC) and an internal NVIDIA set (model card). The older nvidia/RE-USE repository is non-commercial (NSCLv1); Fuobe uses only the NemotronLabs repositories.",
},
- {
- for: "Clean up voice demo",
- text: "Sample recording mic_test2.wav from NVIDIA's RE-USE repository, and its cleaned copy",
- licence: "OpenMDW-1.1",
- url: "https://huggingface.co/nvidia/NVIDIA-NemotronLabs-RE-USE",
- },
];
/** The parts of a LoRA's licence snapshot the class needs (src/lib/catalog/types.ts LoraLicence). */
diff --git a/src/server/providers/mock.ts b/src/server/providers/mock.ts
index 44768986..ed620af0 100644
--- a/src/server/providers/mock.ts
+++ b/src/server/providers/mock.ts
@@ -287,8 +287,8 @@ function demoOutputs(op: Operation | undefined, kind: MediaKind, prompt: string,
case "write":
return [demoWrite(brief)];
case "enhance-voice": {
- // Clean up voice: the bundled demo "after" (NVIDIA's sample, cleaned), else a tone.
- const file = path.join(process.cwd(), "public", "samples", "clean-voice", "noisy-mic-after.m4a");
+ // Clean up voice: the demo's clean voice (public/samples/clean-voice), else a tone.
+ const file = path.join(process.cwd(), "public", "samples", "clean-voice", "clean.m4a");
const after = fs.existsSync(file) ? toDataUri(fs.readFileSync(file), "audio/mp4") : null;
return [after ? { url: after, kind: "audio", contentType: "audio/mp4", meta: { stem: "voice", demo: true } } : { url: toDataUri(demoWav(3, [220, 330], 3), "audio/wav"), kind: "audio", contentType: "audio/wav", meta: { stem: "voice", demo: true } }];
}
diff --git a/tests/comfy-reuse.test.ts b/tests/comfy-reuse.test.ts
index 20cff0a8..a9a04cf4 100644
--- a/tests/comfy-reuse.test.ts
+++ b/tests/comfy-reuse.test.ts
@@ -218,12 +218,10 @@ describe("licences, as information", () => {
expect(workflowLicence(entry("voice-clean-bed-reuse"))).toContain("DBS weights Apache-2.0");
});
- it("records the pack (MIT, adapted NVIDIA code) at its pin, the model and the demo sample", () => {
+ it("records the pack (MIT, adapted NVIDIA code) at its pin and the model", () => {
const pack = nodePack("ComfyUI-RE-USE");
expect(pack?.licence).toMatchObject({ name: "MIT", class: "commercial" });
expect(pack?.repo).toBe(`https://github.com/workingprototype/Fuobe/tree/${requirements.packs["ComfyUI-RE-USE"].commit}/comfy-nodes/ComfyUI-RE-USE`);
expect(pack?.licence.note).toMatch(/not NVIDIA's code path/);
- expect(ATTRIBUTIONS.find((a) => a.for === "RE-USE (clean up voice)")).toMatchObject({ licence: "OpenMDW-1.1", note: expect.stringMatching(/non-commercial \(NSCLv1\)/) });
- expect(ATTRIBUTIONS.find((a) => a.for === "Clean up voice demo")).toMatchObject({ licence: "OpenMDW-1.1", text: expect.stringContaining("mic_test2.wav") });
- });
+ expect(ATTRIBUTIONS.find((a) => a.for === "RE-USE (clean up voice)")).toMatchObject({ licence: "OpenMDW-1.1", note: expect.stringMatching(/non-commercial \(NSCLv1\)/) }); });
});
diff --git a/tests/public-signup-tools.test.ts b/tests/public-signup-tools.test.ts
index 1f9425ad..7cf690bc 100644
--- a/tests/public-signup-tools.test.ts
+++ b/tests/public-signup-tools.test.ts
@@ -95,7 +95,7 @@ describe("the proxy: PR #15's routes as main treats their kind", () => {
it("lets guests and accounts open the tools' pages", () => {
process.env.FUOBE_PUBLIC_SIGNUP = "1";
const cookie = auth.createSession(newAccount().id).value;
- for (const p of ["/audio/split", "/audio/clean", "/apps/app-clean-up-voice", "/samples/clean-voice/noisy-mic-after.m4a", "/character-sheet", "/cinema", "/image", "/connect"]) {
+ for (const p of ["/audio/split", "/audio/clean", "/apps/app-clean-up-voice", "/samples/clean-voice/clean.m4a", "/character-sheet", "/cinema", "/image", "/connect"]) {
expect(passed(proxy(req(p))), `guest ${p}`).toBe(true);
expect(passed(proxy(req(p, { cookie }))), `account ${p}`).toBe(true);
}