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.

Voices: a Qwen3-TTS clone of a sample with no transcript clones from the voice alone, and a saved voice keeps one embedding file

Claudec2c362802b18
diff --git a/scripts/comfy/library.spec.mjs b/scripts/comfy/library.spec.mjs
index 3fc01173..c8354b52 100644
--- a/scripts/comfy/library.spec.mjs
+++ b/scripts/comfy/library.spec.mjs
@@ -2007,8 +2007,8 @@ export const SPEC = [
'ComfyUI-QwenTTS downloads Qwen/Qwen3-TTS-12Hz-1.7B-Base (whole repository at its current revision; fd4b254389122332181a7c3db7f27e918eec64e3 when this was written: model.safetensors 3.86 GB + speech_tokenizer 0.68 GB) into models/tts/Qwen3-TTS/Qwen3-TTS-12Hz-1.7B-Base on first run (models/TTS/Qwen3-TTS when no tts folder is registered: ComfyUI-VoxCPM2 registers models/tts)',
],
notes:
- 'AILab_Qwen3TTSVoiceClone_Advanced(target_text = the line, reference_audio = the voice sample, reference_text = what the sample says (optional: closer clone; empty = the pack allows it), ' +
- 'x_vector_only false, model_size 1.7B, do_sample true, the same sampling as the design graph). A saved voice from Design a voice passes its take and the take\'s line. Output MP3 V0. Get consent for cloned voices.',
+ 'AILab_Qwen3TTSVoiceClone_Advanced(target_text = the line, reference_audio = the voice sample, reference_text = what the sample says (a closer clone), ' +
+ 'x_vector_only false with a transcript; the pack refuses an empty reference_text otherwise, so without one the provider turns x_vector_only on (a timbre-only clone), model_size 1.7B, do_sample true, the same sampling as the design graph). A saved voice from Design a voice passes its take and the take\'s line. Output MP3 V0. Get consent for cloned voices.',
},
{
id: 'tts-voxcpm2',
diff --git a/src/server/providers/comfyui.ts b/src/server/providers/comfyui.ts
index 1ebcf19a..70a0fb2c 100644
--- a/src/server/providers/comfyui.ts
+++ b/src/server/providers/comfyui.ts
@@ -1746,6 +1746,14 @@ export async function prepareWorkflow(endpointTemplate: string, input: GenInput,
const realMissing = bound.missing.filter((m) => !/^maxDimension\b/.test(m));
if (realMissing.length) throw new ProviderError(`Workflow ${manifest.id} bindings point at missing nodes: ${realMissing.join(", ")}`);
let wf = bound.workflow;
+ // Qwen3-TTS's clone needs the sample's words unless it clones from the voice's timbre alone (x_vector_only):
+ // a sample with no transcript clones that way instead of failing.
+ for (const t of b.voiceTranscript ?? []) {
+ const inputs = wf[t.node]?.inputs;
+ if (!inputs || !("x_vector_only" in inputs)) continue;
+ const words = inputs[t.input];
+ inputs.x_vector_only = !(typeof words === "string" && words.trim());
+ }
const outputIds = manifest.outputs.map((o) => o.node);
// The prompt helper (FLUX 3 Image Klein's upsampler) off, or a layout with boxes it would rewrite: the words as typed.
if (PROMPT_HELPER_GRAPHS.has(manifest.id) && (helper === "off" || laidOut)) wf = skipPromptHelper(wf, outputIds);
diff --git a/src/server/voices.ts b/src/server/voices.ts
index 2c2dd350..ba50154f 100644
--- a/src/server/voices.ts
+++ b/src/server/voices.ts
@@ -27,6 +27,8 @@ export function savedVoiceFor(sample: string | undefined): (StudioElement & { vo
/** Hosts fal answers a clone with (its CDN and storage). The file is fetched from nowhere else. */
const FAL_FILE_HOST = /(^|\.)(fal\.media|fal\.run|fal\.ai)$/i;
+/** fal's own bucket on Google Cloud Storage (its schema examples answer from it): that bucket only, not the whole host. */
+const isFalFile = (u: URL) => FAL_FILE_HOST.test(u.hostname) || (u.hostname === "storage.googleapis.com" && u.pathname.startsWith("/falserverless/"));
/** A Qwen3-TTS speaker embedding is a few kilobytes; anything near this is not one. */
const MAX_EMBEDDING_BYTES = 8 * 2 ** 20;
@@ -38,20 +40,19 @@ const MAX_EMBEDDING_BYTES = 8 * 2 ** 20;
export async function keepVoiceEmbedding(sample: string | undefined, url: string | undefined, fetchFile = fetchRemote): Promise<string | null> {
const saved = savedVoiceFor(sample);
if (!saved || saved.voice.embedding || !url) return null;
- let host: string;
+ let u: URL;
try {
- const u = new URL(url);
- if (u.protocol !== "https:") return null;
- host = u.hostname;
+ u = new URL(url);
} catch {
return null;
}
- if (!FAL_FILE_HOST.test(host)) return null;
+ if (u.protocol !== "https:" || !isFalFile(u)) return null;
const file = await fetchFile(url, { maxBytes: MAX_EMBEDDING_BYTES, timeoutMs: 60_000 });
- const asset = saveFile({ data: file.data, contentType: "application/octet-stream", name: `${saved.handle}-voice.safetensors`, source: "derived" });
- // The clip may have changed while the file came down: only the clip it was cloned from keeps it.
+ // The clip may have changed while the file came down, or another line kept its embedding first: only the clip it was
+ // cloned from keeps it, and nothing is stored that the element wouldn't keep.
const now = savedVoiceFor(sample);
if (!now || now.id !== saved.id || now.voice.embedding) return null;
+ const asset = saveFile({ data: file.data, contentType: "application/octet-stream", name: `${saved.handle}-voice.safetensors`, source: "derived" });
updateElement(saved.id, { voice: { ...now.voice, embedding: asset.url } });
return asset.url;
}
diff --git a/tests/account-voice-design.test.ts b/tests/account-voice-design.test.ts
new file mode 100644
index 00000000..198bc6ba
--- /dev/null
+++ b/tests/account-voice-design.test.ts
@@ -0,0 +1,104 @@
+import fs from "node:fs";
+import os from "node:os";
+import path from "node:path";
+import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
+import { startFakeComfy, type FakeComfy } from "./helpers/fake-comfy-runner";
+
+// Design a voice under public sign-up: an account designs and clones voices on its own GPU with its own samples. The
+// owner's saved voices (their take, its line, the kept fal embedding) never reach an account's run, and nothing is
+// fetched or stored on the owner's elements for it.
+const dir = fs.mkdtempSync(path.join(os.tmpdir(), "fuobe-account-voice-"));
+process.env.FUOBE_DATA_DIR = dir;
+process.env.COMFYUI_URL = "http://owner-comfy.test:8188";
+process.env.FUOBE_PUBLIC_SIGNUP = "1";
+delete process.env.FUOBE_PASSWORD;
+delete process.env.FUOBE_ALLOW_PRIVATE_URLS;
+globalThis.__fuobeTestDiskFree = 1e13;
+
+const realFetch = globalThis.fetch;
+const fetched: string[] = [];
+globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
+ const url = String(input instanceof Request ? input.url : input);
+ if (url.startsWith("http://127.0.0.1:")) return realFetch(input, init);
+ fetched.push(url);
+ return new Response("not stubbed", { status: 599 });
+}) as typeof fetch;
+
+const auth = await import("@/server/auth");
+const { POST } = await import("@/app/api/generations/route");
+const { saveFile } = await import("@/server/storage");
+const { createElement, getElement } = await import("@/server/elements");
+const { db } = await import("@/server/db");
+const { resetRates } = await import("@/server/rate");
+
+const WAV = Buffer.concat([Buffer.from("RIFF"), Buffer.from([36, 0, 0, 0]), Buffer.from("WAVEfmt "), Buffer.alloc(32)]);
+let fake: FakeComfy;
+let a = "";
+let cookie = "";
+let ownerClip = "";
+let ownerVoiceId = "";
+beforeAll(async () => {
+ fake = await startFakeComfy({ loras: [], delayMs: 60_000 });
+ globalThis.__fuobeTestGpuPort = fake.port;
+ auth.setPassword("install password");
+ a = auth.createAccount("[email protected]", "long enough").id;
+ auth.setAccountGpu(a, { url: fake.url });
+ cookie = `${auth.SESSION_COOKIE}=${auth.createSession(a).value}`;
+ ownerClip = saveFile({ data: WAV, contentType: "audio/wav", name: "take.wav", source: "upload" }).url;
+ ownerVoiceId = createElement({ name: "Owner's narrator", kind: "voice", references: [ownerClip], voice: { modelId: "qwen-3-tts", engine: "cloud", description: "A warm narrator.", transcript: "The owner's line." } }).id;
+});
+afterAll(async () => {
+ globalThis.fetch = realFetch;
+ globalThis.__fuobeTestGpuPort = undefined;
+ globalThis.__fuobeTestDiskFree = undefined;
+ await fake.close();
+ try {
+ fs.rmSync(dir, { recursive: true, force: true });
+ } catch {}
+});
+beforeEach(() => {
+ resetRates();
+ db().prepare("UPDATE generations SET status = 'canceled' WHERE status IN ('queued', 'running')").run();
+});
+
+function run(body: unknown) {
+ const text = JSON.stringify(body);
+ return POST(new Request("http://localhost:3000/api/generations", { method: "POST", headers: { cookie, host: "localhost:3000", "content-type": "application/json", "content-length": String(Buffer.byteLength(text)) }, body: text }));
+}
+const clone = (voiceAudio: string) => ({ feature: "audio", modelId: "oss-qwen3-tts", engine: "open", op: "tts", prompt: "A new line.", inputs: { voiceAudio } });
+const sentGraphs = () => fake.log.filter((l) => l.path === "/prompt" && l.prompt).map((l) => l.prompt as Record<string, { class_type: string; inputs: Record<string, unknown> }>);
+const waitForGraph = async (n: number) => {
+ for (let i = 0; i < 200 && sentGraphs().length < n; i++) await new Promise((r) => setTimeout(r, 25));
+ return sentGraphs();
+};
+
+describe("Design a voice for an account", () => {
+ it("can't clone the owner's saved voice: the take is the owner's file", async () => {
+ const r = await run(clone(ownerClip));
+ expect(r.status).toBe(403);
+ expect(await r.json()).toMatchObject({ code: "input-not-yours" });
+ });
+
+ it("designs a voice on its own GPU", async () => {
+ const r = await run({ feature: "audio", modelId: "oss-qwen3-tts", engine: "open", op: "voice-design", prompt: "Hello there.", params: { voiceDescription: "A bright young voice." } });
+ expect(r.status).toBe(201);
+ const graphs = await waitForGraph(1);
+ const node = Object.values(graphs.at(-1)!).find((n) => n.class_type === "AILab_Qwen3TTSVoiceDesign_Advanced")!;
+ expect(node.inputs).toMatchObject({ text: "Hello there.", instruct: "A bright young voice." });
+ });
+
+ it("clones its own sample with no owner's line or embedding; with no transcript, from the timbre alone", async () => {
+ const mine = saveFile({ data: WAV, contentType: "audio/wav", name: "me.wav", source: "upload", accountId: a }).url;
+ const before = sentGraphs().length;
+ const r = await run(clone(mine));
+ expect(r.status).toBe(201);
+ const { items } = await r.json();
+ expect(items[0].request.account).toBe(a);
+ const graphs = await waitForGraph(before + 1);
+ const node = Object.values(graphs.at(-1)!).find((n) => n.class_type === "AILab_Qwen3TTSVoiceClone_Advanced")!;
+ expect(node.inputs).toMatchObject({ target_text: "A new line.", reference_text: "", x_vector_only: true });
+ // The owner's saved voice is as it was, and nothing went out to fetch an embedding.
+ expect(getElement(ownerVoiceId)!.voice).toEqual({ modelId: "qwen-3-tts", engine: "cloud", description: "A warm narrator.", transcript: "The owner's line." });
+ expect(fetched.filter((u) => !u.endsWith("/system_stats"))).toEqual([]);
+ });
+});
diff --git a/tests/hosted-runs-voice-design.test.ts b/tests/hosted-runs-voice-design.test.ts
new file mode 100644
index 00000000..bf039beb
--- /dev/null
+++ b/tests/hosted-runs-voice-design.test.ts
@@ -0,0 +1,95 @@
+import fs from "node:fs";
+import http from "node:http";
+import os from "node:os";
+import path from "node:path";
+import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
+import { FAKE_POLICY, listenInRange, startFakeBilling, type FakeBilling } from "./helpers/fake-billing";
+import { startFakeComfy, type FakeComfy } from "./helpers/fake-comfy-runner";
+
+// Design a voice on hosted runs (FUOBE_HOSTED_RUNS=1): an account with no GPU of its own may design a voice on this
+// install's ComfyUI like any open model, priced by the billing service as an audio run. A clone reads a voice sample,
+// so it follows the policy's audio uploads, and the hosted Qwen3-TTS on fal never runs there.
+const dir = fs.mkdtempSync(path.join(os.tmpdir(), "fuobe-hosted-voice-"));
+process.env.FUOBE_DATA_DIR = dir;
+process.env.FUOBE_PUBLIC_SIGNUP = "1";
+delete process.env.FUOBE_PASSWORD;
+delete process.env.FUOBE_HOSTED_RUNS;
+delete process.env.FUOBE_MODERATION_URL;
+globalThis.__fuobeTestDiskFree = 1e13;
+
+const probe = http.createServer();
+const comfyPort = await listenInRange(probe);
+await new Promise<void>((r) => probe.close(() => r()));
+const comfy: FakeComfy = await startFakeComfy({ output: "image", delayMs: 0 }, comfyPort);
+process.env.COMFYUI_URL = comfy.url;
+
+const auth = await import("@/server/auth");
+const billing = await import("@/server/billing");
+const { decidePlace, poolQuote } = await import("@/server/hosted-run");
+
+let fake: FakeBilling;
+let account: NonNullable<ReturnType<typeof auth.accountById>>;
+beforeAll(async () => {
+ fake = await startFakeBilling();
+ auth.setPassword("install password");
+ account = auth.accountById(auth.createAccount("[email protected]", "long enough").id)!;
+});
+afterAll(async () => {
+ globalThis.__fuobeTestDiskFree = undefined;
+ for (const k of ["FUOBE_HOSTED_RUNS", "FUOBE_BILLING_URL", "FUOBE_BILLING_TOKEN"]) delete process.env[k];
+ await fake.close();
+ await comfy.close();
+ fs.rmSync(dir, { recursive: true, force: true });
+});
+beforeEach(() => {
+ billing.resetBillingCache();
+ process.env.FUOBE_HOSTED_RUNS = "1";
+ process.env.FUOBE_BILLING_URL = fake.url;
+ process.env.FUOBE_BILLING_TOKEN = "test-billing-token";
+ fake.policy = { ...FAKE_POLICY };
+});
+
+const design = (modelId: string) => ({ feature: "audio" as const, modelId, engine: "open" as const, op: "voice-design" as const, prompt: "Hello there.", params: { voiceDescription: "A warm older narrator." } });
+const clone = { feature: "audio" as const, modelId: "oss-qwen3-tts", engine: "open" as const, op: "tts" as const, prompt: "A new line.", inputs: { voiceAudio: "/api/files/uploads/take.wav" }, params: { voiceTranscript: "Hello there." } };
+
+describe("Design a voice on this install's GPUs", () => {
+ it("plans and prices both open voice designers there as audio runs", async () => {
+ for (const modelId of ["oss-qwen3-tts", "oss-voxcpm2"]) {
+ const before = fake.calls_of("/v1/quote").length;
+ const q = await poolQuote(account, design(modelId), undefined);
+ expect(q, modelId).not.toBeNull();
+ expect(q!.planned.model.id).toBe(modelId);
+ expect(q!.planned.op).toBe("voice-design");
+ expect(q!.planned.route.provider).toBe("comfyui");
+ expect(q!.quote).toMatchObject({ amount: 7, priceVersion: "v7" });
+ const sent = fake.calls_of("/v1/quote").slice(before);
+ expect(sent).toHaveLength(1);
+ expect((sent[0].body as { run: Record<string, unknown> }).run).toMatchObject({ place: "pool", model: modelId, op: "voice-design", kind: "audio", engine: "open" });
+ expect((await decidePlace(account, design(modelId), undefined)).kind).toBe("pool");
+ }
+ });
+
+ it("a clone reads a voice sample: offered only when the policy takes audio uploads", async () => {
+ const refused = await decidePlace(account, clone, undefined);
+ expect(refused.kind).toBe("refuse");
+ if (refused.kind === "refuse") expect(refused.refusal.body.code).toBe("not-offered");
+ fake.policy = { ...FAKE_POLICY, uploads: { ...FAKE_POLICY.uploads, audio: true } };
+ billing.resetBillingCache();
+ expect((await decidePlace(account, clone, undefined)).kind).toBe("pool");
+ });
+
+ it("the policy's deny list keeps a voice designer off; the hosted Qwen3-TTS on fal is never priced there", async () => {
+ fake.policy = { ...FAKE_POLICY, pool: { deny: ["oss-voxcpm2"] } };
+ billing.resetBillingCache();
+ expect(await poolQuote(account, design("oss-voxcpm2"), undefined)).toBeNull();
+ expect(await poolQuote(account, design("oss-qwen3-tts"), undefined)).not.toBeNull();
+ expect(await poolQuote(account, { ...design("qwen-3-tts"), engine: "cloud" }, undefined)).toBeNull();
+ expect((await decidePlace(account, { ...design("qwen-3-tts"), engine: "cloud" }, undefined)).kind).toBe("own");
+ });
+
+ it("hosted runs off: nothing is planned there", async () => {
+ delete process.env.FUOBE_HOSTED_RUNS;
+ expect(await poolQuote(account, design("oss-qwen3-tts"), undefined)).toBeNull();
+ expect((await decidePlace(account, design("oss-qwen3-tts"), undefined)).kind).toBe("own");
+ });
+});
diff --git a/tests/voice-design-comfy.test.ts b/tests/voice-design-comfy.test.ts
index 26a9d27e..9275f641 100644
--- a/tests/voice-design-comfy.test.ts
+++ b/tests/voice-design-comfy.test.ts
@@ -56,6 +56,12 @@ describe("what the ComfyUI provider binds", () => {
const plain = await prepareWorkflow("tts-voxcpm2-clone", { prompt: "New line.", voiceAudio: "data:audio/wav;base64,UklGRg==" }, ctx("tts"));
expect(plain.workflow["2"].inputs).toMatchObject({ prompt_text: "", device: "cuda" });
const qclone = await prepareWorkflow("tts-qwen3-clone", { prompt: "New line.", voiceAudio: "data:audio/wav;base64,UklGRg==", voiceTranscript: "Hello there." }, ctx("tts"));
- expect(qclone.workflow["2"].inputs).toMatchObject({ target_text: "New line.", reference_text: "Hello there." });
+ expect(qclone.workflow["2"].inputs).toMatchObject({ target_text: "New line.", reference_text: "Hello there.", x_vector_only: false });
+ // A sample with no transcript (a recorded or uploaded voice): the pack refuses an empty reference_text unless
+ // it clones from the voice's timbre alone, so x_vector_only goes on.
+ for (const voiceTranscript of [undefined, " "]) {
+ const bare = await prepareWorkflow("tts-qwen3-clone", { prompt: "New line.", voiceAudio: "data:audio/wav;base64,UklGRg==", voiceTranscript }, ctx("tts"));
+ expect(bare.workflow["2"].inputs).toMatchObject({ target_text: "New line.", reference_text: "", x_vector_only: true });
+ }
});
});
diff --git a/tests/voice-design-server.test.ts b/tests/voice-design-server.test.ts
index bc381308..afe3263b 100644
--- a/tests/voice-design-server.test.ts
+++ b/tests/voice-design-server.test.ts
@@ -16,7 +16,7 @@ process.env.COMFYUI_URL = "http://127.0.0.1:9";
const { setSetting } = await import("@/server/settings");
const { createElement, getElement, updateElement } = await import("@/server/elements");
-const { saveFile } = await import("@/server/storage");
+const { listAssets, saveFile } = await import("@/server/storage");
const { keepVoiceEmbedding, savedVoiceFor } = await import("@/server/voices");
const { runAsTenant } = await import("@/server/tenant");
const { buildPayload } = await import("@/lib/catalog/payload");
@@ -161,6 +161,32 @@ describe("a clone in two steps on fal", () => {
expect(await keepVoiceEmbedding(clip, "https://v3.fal.media/files/other.safetensors", file)).toBeNull();
});
+ it("two lines cloning at once keep one embedding and store no spare file; fal's storage bucket is accepted, the rest of the host is not", async () => {
+ const clip = wav();
+ const el = createElement({ name: "Raced", kind: "voice", references: [clip], voice: { modelId: "qwen-3-tts", engine: "cloud", transcript: "Hi." } });
+ const derived = () => listAssets({ source: "derived", limit: 1000 }).length;
+ const bytes = async () => ({ data: Buffer.from("emb"), contentType: "application/octet-stream", url: "" });
+ // Another bucket on the same host is not fal's.
+ expect(await keepVoiceEmbedding(clip, "https://storage.googleapis.com/someone-else/voice.safetensors", bytes)).toBeNull();
+ const before = derived();
+ // The first download finishes after the second one has kept its file.
+ let release!: () => void;
+ const slow = (async () => {
+ await new Promise<void>((r) => (release = r));
+ return bytes();
+ }) as typeof bytes;
+ const first = keepVoiceEmbedding(clip, "https://storage.googleapis.com/falserverless/files/a.safetensors", slow);
+ const second = await keepVoiceEmbedding(clip, "https://v3.fal.media/files/b.safetensors", bytes);
+ release();
+ expect(await first).toBeNull();
+ expect(second).toMatch(/^\/api\/files\//);
+ expect(getElement(el.id)!.voice!.embedding).toBe(second);
+ expect(derived()).toBe(before + 1);
+ // On its own, fal's bucket is kept like its CDN.
+ const other = createElement({ name: "Bucket", kind: "voice", references: [wav()], voice: { modelId: "qwen-3-tts", engine: "cloud" } });
+ expect(await keepVoiceEmbedding(other.references[0], "https://storage.googleapis.com/falserverless/files/c.safetensors", bytes)).toMatch(/^\/api\/files\//);
+ });
+
it("a run with a saved voice sends its kept embedding and its line, and makes no clone", async () => {
setSetting("falKey", "fal_test_key_123456");
const clip = wav();
diff --git a/workflows/comfyui/manifest.json b/workflows/comfyui/manifest.json
index d1ee72b7..8a9b48ea 100644
--- a/workflows/comfyui/manifest.json
+++ b/workflows/comfyui/manifest.json
@@ -7104,7 +7104,7 @@
"vramGb": 8,
"license": "Qwen3-TTS weights Apache-2.0 (Qwen); ComfyUI-QwenTTS code GPL-3.0",
"validated": false,
- "notes": "AILab_Qwen3TTSVoiceClone_Advanced(target_text = the line, reference_audio = the voice sample, reference_text = what the sample says (optional: closer clone; empty = the pack allows it), x_vector_only false, model_size 1.7B, do_sample true, the same sampling as the design graph). A saved voice from Design a voice passes its take and the take's line. Output MP3 V0. Get consent for cloned voices.",
+ "notes": "AILab_Qwen3TTSVoiceClone_Advanced(target_text = the line, reference_audio = the voice sample, reference_text = what the sample says (a closer clone), x_vector_only false with a transcript; the pack refuses an empty reference_text otherwise, so without one the provider turns x_vector_only on (a timbre-only clone), model_size 1.7B, do_sample true, the same sampling as the design graph). A saved voice from Design a voice passes its take and the take's line. Output MP3 V0. Get consent for cloned voices.",
"autoDownloads": [
"ComfyUI-QwenTTS downloads Qwen/Qwen3-TTS-12Hz-1.7B-Base (whole repository at its current revision; fd4b254389122332181a7c3db7f27e918eec64e3 when this was written: model.safetensors 3.86 GB + speech_tokenizer 0.68 GB) into models/tts/Qwen3-TTS/Qwen3-TTS-12Hz-1.7B-Base on first run (models/TTS/Qwen3-TTS when no tts folder is registered: ComfyUI-VoxCPM2 registers models/tts)"
],