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.

Assist: soundtrack suggestions leave translate, dub, caption and other jobs to their own plans

Claudec1927a0bfca4
diff --git a/src/server/assist/agent.ts b/src/server/assist/agent.ts
index a48fa901..802ff69d 100644
--- a/src/server/assist/agent.ts
+++ b/src/server/assist/agent.ts
@@ -1227,12 +1227,20 @@ export function offlinePlan(message: string, preferred: Engine, hint?: SkillMeta
const SPEECH = "(?:dialog(?:ue)?s?|talking|speech|speaking|voices?|vocals?|narration|conversation)";
const REMOVE_SPEECH = new RegExp(`\\b(?:remove|take out|strip|cut out|drop|delete|get rid of|mute|erase|lose|kill)\\b[^.?!]*\\b${SPEECH}\\b|\\bwithout (?:the |any )?${SPEECH}\\b|\\bno ${SPEECH}\\b`);
-const ONLY = "(?:just|only|isolate|extract|keep|pull out|separate)";
+// "keep" alone isn't a soundtrack word ("translate this and keep the voice"); "keep only/just the music" still reads through "only".
+const ONLY = "(?:just|only|isolate|extract|pull out|separate)";
const ONLY_SPEECH = new RegExp(`\\b${ONLY}\\b(?: the| its)? ${SPEECH}\\b|\\b${SPEECH} only\\b`);
const ONLY_MUSIC = new RegExp(`\\b${ONLY}\\b(?: the| its)? (?:music|score|song)\\b|\\b(?:music|score) only\\b`);
const ONLY_EFFECTS = new RegExp(`\\b${ONLY}\\b(?: the| its)? (?:sound effects|effects|sfx|ambience)\\b|\\b(?:sfx|effects) only\\b`);
const LOWER_MUSIC = /\b(?:lower|turn down|quieter|duck|soften|reduce)\b[^.?!]*\b(?:music|background|score|bed)\b/;
const SPLIT_WORDS = /\b(?:split|separate|unmix|demix)\b[^.?!]*\b(?:soundtrack|audio|sound|stems?|tracks?)\b|\bstems\b/;
+/**
+ * Another job named in the same request: the soundtrack words then describe that job ("dub this into Spanish but keep the
+ * music", "upscale this, no voice changes", "a music video with no vocals"), so the request goes to its own plan. Noise,
+ * echo, hiss and hum are Clean up voice's job: "remove the background noise from my voice" never drops the voice.
+ */
+const OTHER_JOB =
+ /\b(?:translat\w*|dub\w*|captions?|captioning|subtitles?|lip ?sync\w*|lipsync\w*|extend\w*|upscal\w*|animat\w*|make(?! (?:it|the|this|that) )|makes|making|create|generate|write|compose|record|restyle|noise|noisy|echo|hiss|hum|reverb|denoise|clean ?up|enhance)\b/;
/**
* A soundtrack request read without an LLM: "remove the dialogue from this video" (remove_dialogue; on an audio file the
@@ -1243,7 +1251,7 @@ const SPLIT_WORDS = /\b(?:split|separate|unmix|demix)\b[^.?!]*\b(?:soundtrack|au
export function offlineSoundtrack(message: string): { tool: string; input: Record<string, unknown>; say: string } | { say: string } | null {
const [body, attached = ""] = message.split(/\n\nAttached files[^\n]*\n/);
const t = body.trim().toLowerCase();
- if (!t) return null;
+ if (!t || OTHER_JOB.test(t)) return null;
const remove = REMOVE_SPEECH.test(t);
const speech = ONLY_SPEECH.test(t);
const music = ONLY_MUSIC.test(t);
@@ -1253,8 +1261,7 @@ export function offlineSoundtrack(message: string): { tool: string; input: Recor
if (!remove && !speech && !music && !effects && !lower && !split) return null;
const media = [...attached.matchAll(/^- (video|audio) \d+: (\S+)$/gm)].map((m) => ({ kind: m[1], url: m[2] })).at(-1);
if (!media) {
- // "write a song with no vocals", "a narration with music only": a new piece, not a split.
- if (/\b(?:make|create|generate|write|compose|record)\b/.test(t)) return null;
+ // "write a song with no vocals" is a new piece (OTHER_JOB); without a file the request must name one to split.
if (!/\b(?:this|the|my|that|our)\s+(?:video|clip|audio|soundtrack|song|track|recording|file|film|movie|podcast|interview|footage)\b/.test(t)) return null;
return { say: "Attach the video or audio file (or drop it from your Library) and I'll do that — it runs on your GPU." };
}
diff --git a/src/server/assist/studio-tools.ts b/src/server/assist/studio-tools.ts
index a16ee5a7..e5c700b0 100644
--- a/src/server/assist/studio-tools.ts
+++ b/src/server/assist/studio-tools.ts
@@ -24,7 +24,7 @@ import { defineTool, type JobPlace, type ToolContext, type ToolOutcome } from ".
import { dbsChannelsFor, durationWords, hostPick, KEEP_STEMS, REMIX_MAX_DB, REMIX_MIN_DB, remixWords, SPLIT_MODEL, splitOutcome, splitTime, type KeepStem, type SplitOutcome } from "@/lib/av/split";
import { LOWER_DEFAULT_DB, LOWER_MAX_DB, LOWER_MIN_DB, removeDialogueTime, type DialogueOutcome } from "@/lib/av/remove-dialogue";
import { AudioToolBody, planAudioTool, previewAudioTool, runAudioTool, type AudioToolPlan, type AudioToolRequest } from "../audio-tools";
-import { comfyDeviceSeen } from "../providers/comfyui";
+import { comfyDevice, comfyDeviceSeen } from "../providers/comfyui";
import { contentTypeFor, filesRel, kindFor } from "../storage";
/**
@@ -872,15 +872,22 @@ export function removeDialogueBody(i: RemoveDialogueToolInput): { body: AudioToo
return { body: parsed.data, outcome };
}
-/** "about 1–2 min on your GPU" for the card, from the GPU's last known device (a CPU when it hasn't said). */
-function soundtrackTime(p: AudioToolPlan, body: AudioToolRequest): string | null {
+/**
+ * "about 1–2 min on your GPU" for the card, from the GPU's last known device. Before the device has been read the card
+ * leaves the time out (a CUDA card and a CPU differ about 80x) and asks the GPU in the background, so the next card has it.
+ */
+export function soundtrackTime(p: AudioToolPlan, body: AudioToolRequest): string | null {
const seconds = p.split?.duration;
if (!seconds || (body.tool !== "split" && body.tool !== "remove-dialogue")) return null;
const device = comfyDeviceSeen();
+ if (!device) {
+ void comfyDevice().catch(() => undefined);
+ return null;
+ }
const quality = body.quality ?? hostPick(device);
const mode = dbsChannelsFor(body.tool === "split" && (body.stereo ?? !!body.remix) ? "each channel" : "mono", p.split?.channels);
const t = (body.tool === "split" ? splitTime : removeDialogueTime)({ seconds, quality, mode, channels: p.split?.channels, device });
- return `${durationWords(t)} on your GPU`;
+ return `${durationWords(t)} ${device === "cpu" ? "on your computer" : "on your GPU"}`;
}
/** Price (and time) the call the way the page does; never throws: what's in the way is the card's error. */
diff --git a/src/server/providers/comfyui.ts b/src/server/providers/comfyui.ts
index 1e1be3f5..5c3c9114 100644
--- a/src/server/providers/comfyui.ts
+++ b/src/server/providers/comfyui.ts
@@ -718,10 +718,6 @@ declare global {
var __fuobeComfyDevice: Map<string, { type?: string; at: number }> | undefined;
}
-/**
- * The connected ComfyUI's first torch device type ("cuda" for NVIDIA and ROCm, "cpu", "mps"…), from GET /system_stats
- * (devices[0], as Settings' test reads it), kept for a minute; undefined when the server doesn't say or can't be reached.
- */
/**
* originals (o/dbs-d9): the device comfyDevice last read for the main ComfyUI, without asking it (an Assist card is planned
* synchronously); undefined when it hasn't been asked yet.
@@ -731,6 +727,10 @@ export function comfyDeviceSeen(): string | undefined {
return url ? globalThis.__fuobeComfyDevice?.get(url)?.type : undefined;
}
+/**
+ * The connected ComfyUI's first torch device type ("cuda" for NVIDIA and ROCm, "cpu", "mps"…), from GET /system_stats
+ * (devices[0], as Settings' test reads it), kept for a minute; undefined when the server doesn't say or can't be reached.
+ */
export async function comfyDevice(worker: ComfyWorker = "main"): Promise<string | undefined> {
// On someone's computer: what its Fuobe tab last said ("cuda:0 NVIDIA …").
const computer = computerScope();
diff --git a/tests/assist-soundtrack-tools.test.ts b/tests/assist-soundtrack-tools.test.ts
index cd1868f1..35a0d1fe 100644
--- a/tests/assist-soundtrack-tools.test.ts
+++ b/tests/assist-soundtrack-tools.test.ts
@@ -13,7 +13,7 @@ process.env.FUOBE_DATA_DIR = dir;
process.env.COMFYUI_URL = "http://127.0.0.1:9";
process.env.OLLAMA_URL = "http://127.0.0.1:9";
-const { setSetting } = await import("@/server/settings");
+const { getSetting, setSetting } = await import("@/server/settings");
const { saveFile } = await import("@/server/storage");
const tools = await import("@/server/assist/tools");
const studio = await import("@/server/assist/studio-tools");
@@ -195,6 +195,26 @@ describe("split_soundtrack and remove_dialogue as tools", () => {
expect(p).toMatchObject({ studio: "Split soundtrack", href: "/audio/split" });
});
+ it("leaves the card's time out until the GPU's device is known, and says where it runs", async () => {
+ const { planAudioTool } = await import("@/server/audio-tools");
+ const body = studio.splitSoundtrackBody({ media: wav("time.wav") }).body;
+ const time = () => studio.soundtrackTime(planAudioTool(body), body);
+ const cache = (globalThis.__fuobeComfyDevice ??= new Map());
+ const url = getSetting("comfyUrl").replace(/\/+$/, "");
+ const before = cache.get(url);
+ try {
+ cache.delete(url);
+ expect(time()).toBeNull();
+ cache.set(url, { type: "cpu", at: Date.now() });
+ expect(time()).toMatch(/ on your computer$/);
+ cache.set(url, { type: "cuda", at: Date.now() });
+ expect(time()).toMatch(/ on your GPU$/);
+ } finally {
+ if (before) cache.set(url, before);
+ else cache.delete(url);
+ }
+ });
+
it("prices Remove dialogue as the page's two steps (the split, then the stream-copy mux)", () => {
const video = mp4();
const p = plan("remove_dialogue", { video, music_db: -18 });
@@ -299,6 +319,32 @@ describe("the offline planner", () => {
expect(agent.offlinePlan("a cinematic video of a lighthouse, no dialogue", "cloud")?.tool).toBe("generate");
expect(agent.offlineSoundtrack("a red fox in the snow")).toBeNull();
});
+
+ it("leaves other jobs that mention the voice, the music or vocals to their own plans", () => {
+ const v = attached("video", "/api/files/uploads/clip.mp4");
+ const a = attached("audio", "/api/files/uploads/take.wav");
+ const others = [
+ `Remove the background noise from my voice${a}`,
+ `Translate this video to French and keep the voice${v}`,
+ `Dub this video into Spanish but keep the music${v}`,
+ `Extend this video and keep the music${v}`,
+ `Upscale this video, no voice changes${v}`,
+ `Add captions to this video, keep the voice${v}`,
+ `Lip sync this video to the audio, keep the voice${v}`,
+ `Make a music video for this song with no vocals${a}`,
+ `Write a song like this, no vocals${a}`,
+ `Generate a video with this audio, no talking${a}`,
+ `Keep the voice and make it 9:16${v}`,
+ ];
+ for (const m of others) {
+ expect(agent.offlineSoundtrack(m), m).toBeNull();
+ expect(["split_soundtrack", "remove_dialogue"], m).not.toContain(agent.offlinePlan(m, "open")?.tool);
+ }
+ // "keep only …" , "make it just the music" and "turn down the music" are still soundtrack requests.
+ expect(agent.offlinePlan(`keep only the music${a}`, "open")).toMatchObject({ tool: "split_soundtrack", input: { keep: ["music"] } });
+ expect(agent.offlinePlan(`make it just the music${a}`, "open")).toMatchObject({ tool: "split_soundtrack", input: { keep: ["music"] } });
+ expect(agent.offlinePlan(`turn down the music under the dialogue${v}`, "open")).toMatchObject({ tool: "remove_dialogue", input: { music_db: -12 } });
+ });
});
describe("public sign-up: the tools are the owner's (docs/public-signup.md)", () => {
diff --git a/tests/public-signup-tools.test.ts b/tests/public-signup-tools.test.ts
index 8cae9d80..b3b3b656 100644
--- a/tests/public-signup-tools.test.ts
+++ b/tests/public-signup-tools.test.ts
@@ -229,6 +229,11 @@ describe("the routes: a visitor's price is its own GPU's, and the owner's charac
expect(await account.json()).toMatchObject({ steps: 1, costUsd: 0, demo: false, channels: 2 });
const owner = await audioTools.POST(call("/api/audio-tools?preview=1", body(owners), auth.createSession().value));
expect(await owner.json()).toMatchObject({ steps: 1, demo: true, channels: 2 });
+ // A remix (the levels Assist's split_soundtrack sends) is priced the same way: the asker's own file on its own GPU.
+ const remix = (media: string) => ({ ...body(media), remix: { voiceDb: -100, musicDb: -6, effectsDb: 0 } });
+ expect((await audioTools.POST(call("/api/audio-tools?preview=1", remix(owners), cookie))).status).toBe(422);
+ const mixed = await audioTools.POST(call("/api/audio-tools?preview=1", remix(wav("mine2.wav", who.id)), cookie));
+ expect(await mixed.json()).toMatchObject({ steps: 1, costUsd: 0, demo: false });
});
it("prices a visitor's Clean up voice on its own GPU without asking any GPU, never a demo, and only of its own file", async () => {