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 and MCP: split_soundtrack and remove_dialogue split a soundtrack or take the dialogue out in one call, priced first

Claude358b2ae0a7c2
diff --git a/src/lib/av/split.ts b/src/lib/av/split.ts
index 9eed410f..32af3b51 100644
--- a/src/lib/av/split.ts
+++ b/src/lib/av/split.ts
@@ -193,6 +193,8 @@ export interface SplitInput {
channels?: number;
/** Seconds the soundtrack runs, when known. */
seconds?: number;
+ /** originals (o/dbs-d9): one mix at these levels (graph C, soundtrack-remix-dbs) instead of four stems. */
+ remix?: RemixLevels;
}
export interface SplitPlan extends ToolPlan {
@@ -200,6 +202,58 @@ export interface SplitPlan extends ToolPlan {
mode: DbsChannels;
}
+// ---------------------------------------------------------------------------
+// originals (o/dbs-d9): what Assist's and MCP's split_soundtrack returns, from its keep and levels_db
+
+/** The stems a caller names (Assist / MCP words), and the stem each one is. */
+export type KeepStem = "dialogue" | "music" | "effects";
+export const KEEP_STEMS: readonly KeepStem[] = ["dialogue", "music", "effects"];
+export const KEEP_STEM_ID: Record<KeepStem, StemId> = { dialogue: "voice", music: "music", effects: "effects" };
+
+/** A remix's levels (graph C's Adjust Audio Volume: whole dB); a stem left out goes to REMIX_OUT_DB. */
+export const REMIX_MIN_DB = -60;
+export const REMIX_MAX_DB = 12;
+export const REMIX_OUT_DB = -100;
+export interface RemixLevels {
+ voiceDb: number;
+ musicDb: number;
+ effectsDb: number;
+}
+const LEVEL_KEY: Record<KeepStem, keyof RemixLevels> = { dialogue: "voiceDb", music: "musicDb", effects: "effectsDb" };
+
+/**
+ * What a split returns: all four stems; one stem (one kept, or music + effects, which is the Music & effects stem); or one
+ * mix (graph C) when levels are given or the stems kept aren't one stem (dialogue with music, dialogue with effects).
+ */
+export type SplitOutcome = { kind: "stems" } | { kind: "stem"; stem: StemId } | { kind: "mix"; levels: RemixLevels };
+
+/** Throws when nothing is kept. Levels are whole dB, REMIX_MIN_DB…REMIX_MAX_DB; a stem with no level stays at 0 dB. */
+export function splitOutcome(keep?: readonly KeepStem[], levels?: Partial<Record<KeepStem, number>>): SplitOutcome {
+ const kept = keep ? KEEP_STEMS.filter((s) => keep.includes(s)) : [...KEEP_STEMS];
+ if (!kept.length) throw new Error("Keep at least one of dialogue, music or effects");
+ const leveled = !!levels && KEEP_STEMS.some((s) => kept.includes(s) && typeof levels[s] === "number" && Number.isFinite(levels[s]));
+ if (!leveled) {
+ if (kept.length === KEEP_STEMS.length) return { kind: "stems" };
+ if (kept.length === 1) return { kind: "stem", stem: KEEP_STEM_ID[kept[0]] };
+ if (!kept.includes("dialogue")) return { kind: "stem", stem: "background" };
+ }
+ const level = (s: KeepStem): number => {
+ if (!kept.includes(s)) return REMIX_OUT_DB;
+ const v = levels?.[s];
+ return typeof v === "number" && Number.isFinite(v) ? Math.min(REMIX_MAX_DB, Math.max(REMIX_MIN_DB, Math.round(v))) : 0;
+ };
+ return { kind: "mix", levels: { voiceDb: level("dialogue"), musicDb: level("music"), effectsDb: level("effects") } };
+}
+
+/** "Dialogue −6 dB + Music" — a remix in words (stems left out aren't named). */
+export function remixWords(l: RemixLevels): string {
+ const parts = KEEP_STEMS.filter((s) => l[LEVEL_KEY[s]] > REMIX_OUT_DB).map((s) => {
+ const db = l[LEVEL_KEY[s]];
+ return `${stemLabel(KEEP_STEM_ID[s])}${db ? ` ${dbLabel(db)}` : ""}`;
+ });
+ return parts.join(" + ") || "Silence";
+}
+
const STEP_LABEL: Record<DbsChannels, string> = {
mono: "Dialogue, music, effects",
"each channel": "Dialogue, music, effects · every channel",
@@ -209,10 +263,12 @@ const STEP_LABEL: Record<DbsChannels, string> = {
export function planSplit(i: SplitInput): SplitPlan {
if (i.engine === "cloud") throw new Error(CLOUD_SPLIT_PROBLEM);
if (!i.media) throw new Error(`Add the ${i.kind === "video" ? "video" : "audio"} to split`);
- const mode = dbsChannelsFor(i.stereo ? "each channel" : "mono", i.channels);
+ // A remix is one file: in mono it would lose a stereo source's image, so it splits every channel unless told otherwise.
+ const remix = i.remix;
+ const mode = dbsChannelsFor((i.stereo ?? !!remix) ? "each channel" : "mono", i.channels);
const name = i.name?.trim();
- const title = `Split · ${name || (i.kind === "video" ? "video soundtrack" : "soundtrack")}`;
- const extra: Record<string, unknown> = { channels: mode };
+ const title = `${remix ? `Mix (${remixWords(remix)})` : "Split"} · ${name || (i.kind === "video" ? "video soundtrack" : "soundtrack")}`;
+ const extra: Record<string, unknown> = { channels: mode, ...(remix && { remix: true, ...remix }) };
if (i.quality) extra.separationModel = DBS_MODELS[i.quality];
if (i.channels && i.channels > 0) extra.sourceChannels = Math.round(i.channels);
const request: GenerationRequest = {
@@ -229,7 +285,7 @@ export function planSplit(i: SplitInput): SplitPlan {
sourceDuration: Math.round(i.seconds * 1000) / 1000,
}),
},
- step: { label: STEP_LABEL[mode], index: 0, of: 1 },
+ step: { label: remix ? `${remixWords(remix)} · one mix` : STEP_LABEL[mode], index: 0, of: 1 },
};
const surround = surroundSource(i.channels);
const passes = separationPasses(mode, i.channels);
@@ -238,9 +294,12 @@ export function planSplit(i: SplitInput): SplitPlan {
length: i.seconds && i.seconds > 0 ? i.seconds : null,
quality: i.quality ?? null,
mode,
- summary: `Splits ${i.kind === "video" ? "the video's soundtrack" : "it"} into dialogue, music, effects and music & effects${mode === "each channel" ? `, every channel on its own (${passes} passes)` : ""}.`,
+ summary: remix
+ ? `Splits ${i.kind === "video" ? "the video's soundtrack" : "it"} and mixes it back as ${remixWords(remix)}, in one file${mode === "each channel" ? `, every channel on its own (${passes} passes)` : ""}.`
+ : `Splits ${i.kind === "video" ? "the video's soundtrack" : "it"} into dialogue, music, effects and music & effects${mode === "each channel" ? `, every channel on its own (${passes} passes)` : ""}.`,
notes: [
- ...(surround ? [`This file has ${i.channels} channels. ComfyUI saves audio in mono or stereo only, so the stems come out in mono (all channels mixed), and Music & effects is the music and effects stems added up.`] : []),
+ ...(surround ? [`This file has ${i.channels} channels. ComfyUI saves audio in mono or stereo only, so the ${remix ? "mix comes" : "stems come"} out in mono (all channels mixed)${remix ? "" : ", and Music & effects is the music and effects stems added up"}.`] : []),
+ ...(remix ? ["A mix that would go over full scale is turned down as a whole to fit, so it can come out a little quieter than asked."] : []),
"Dialogue comes out clean; music and effects can bleed into each other.",
],
};
diff --git a/src/server/assist/agent.ts b/src/server/assist/agent.ts
index c9ce2dbb..a48fa901 100644
--- a/src/server/assist/agent.ts
+++ b/src/server/assist/agent.ts
@@ -706,6 +706,7 @@ How you work:
- For multi-step work (an image, then animate it; transcribe, translate, then voice it), put the steps in one generate call and set "after" on each later job: it starts by itself when the earlier job finishes and gets its result as input. When you need to judge a result before deciding the next step, wait with check_generations instead (look=true to see images) and pass the output URL into the next call.
- Besides images, video and audio, models can transcribe speech, translate or write text (scripts, captions, ad copy), split images into layers, separate voice from background, trim, caption or re-sound clips, and turn an image into a 3D model: search_models with kind "text" or "model3d" finds the text and 3D ones.
- Whole studio jobs have their own tools, and each job opens in its studio, where the user can carry on: split_layers (a Layers project), restyle_footage (a Shorts Studio session), dub_video (a dub the user reviews line by line in Translate & dub), faceless_episode (a Faceless Studio episode), create_ads (an Ads Studio batch), add_captions (the Captions editor), restore_video (old or black-and-white footage restored and colourised, in Restore & colourise), blockout_film (a grey-box 3D blockout from Blender or any 3D app filmed from reference stills and timed beats, as Cinema's Blockout does; in the Library) and katana (a reference edit — a 1–30 s video — rebuilt shot for shot with the user's own subject from 1–5 photos, when they want "this edit, but with me / my product"). Use them instead of chaining those steps by hand; once one starts, say which studio it's in (the chat links to it).
+- Soundtracks: split_soundtrack splits audio or a video's sound into dialogue, music and effects (all stems, one stem such as "just the music", or one remix at given levels), and remove_dialogue takes the talking out of a video, keeps only it, or lowers the music under it, with the picture untouched. Both run on the user's GPU (free); the cloud engine can't do them.
- Use the user's files by the URLs listed in their message. Earlier outputs are found with list_recent. Saved characters and products are Elements: check list_elements and write their @handle in prompts.
- Results show up in the chat by themselves, so don't repeat URLs back. After starting jobs, say briefly what's coming; after they finish, give a short take and suggest a next step.
- Be brief and friendly. Plain sentences, no headings. Prices are estimates in USD; open-source models run free on the user's own GPU.
@@ -888,6 +889,9 @@ export const offline: ModelCall = async ({ messages, ctx, skills, named }) => {
"tool_use",
);
}
+ // originals (o/dbs-d9): "remove the dialogue" or "just the music" with no file attached asks for one (never a new clip).
+ const soundtrack = offlineSoundtrack(said);
+ if (soundtrack && !("tool" in soundtrack)) return reply([text(soundtrack.say)], "end_turn");
const hint = skills?.find((s) => s.offline)?.offline;
const plan = offlinePlan(said, ctx.engine, hint);
if (!plan) return reply([text("Tell me what to make — an image, a video, a voice-over or a storyboard — and attach any photos to use.")], "end_turn");
@@ -1080,6 +1084,10 @@ export function offlinePlan(message: string, preferred: Engine, hint?: SkillMeta
return { tool: "remember", input: { text: sentence, category: guessCategory(what) }, say: "I'll remember that for every chat." };
}
+ // originals (o/dbs-d9): "remove the dialogue from this video", "just the music" on an attached clip.
+ const soundtrack = offlineSoundtrack(message);
+ if (soundtrack && "tool" in soundtrack) return soundtrack;
+
// Any count: a storyboard's frames ("a 6-frame heist"). The take count: how many pictures to make.
const counted = COUNT.exec(t);
const count = counted ? num(counted[1]) : hint?.outputs;
@@ -1214,6 +1222,61 @@ export function offlinePlan(message: string, preferred: Engine, hint?: SkillMeta
return { tool: "generate", input: { summary: `${isVideo ? "Video" : images.length ? "Edit" : "Image"}: ${text.slice(0, 80)}`, jobs: [job] }, say: `I'll ${what} with the default ${isVideo ? "video" : "image"} model.` };
}
+// ---------------------------------------------------------------------------
+// originals (o/dbs-d9): soundtrack requests (split_soundtrack, remove_dialogue)
+
+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)";
+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/;
+
+/**
+ * A soundtrack request read without an LLM: "remove the dialogue from this video" (remove_dialogue; on an audio file the
+ * music and effects stem), "just the dialogue", "just the music", "only the sound effects", "lower the music under the
+ * talking" (by 12 dB unless a number says how far), "split the soundtrack" (all four stems). The last attached video or
+ * audio file is the source; without one, a question asking for it. Null for anything else.
+ */
+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;
+ const remove = REMOVE_SPEECH.test(t);
+ const speech = ONLY_SPEECH.test(t);
+ const music = ONLY_MUSIC.test(t);
+ const effects = ONLY_EFFECTS.test(t);
+ const lower = LOWER_MUSIC.test(t) && new RegExp(`\\b${SPEECH}\\b`).test(t);
+ const split = SPLIT_WORDS.test(t);
+ 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;
+ 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." };
+ }
+ const video = media.kind === "video";
+ if (lower && video) {
+ const db = /\b(\d{1,2})\s*db\b/.exec(t);
+ const musicDb = -Math.min(30, db ? Number(db[1]) : 12);
+ return { tool: "remove_dialogue", input: { video: media.url, music_db: musicDb }, say: `I'll keep the talking and lower the music and effects ${Math.abs(musicDb)} dB under it — the picture stays untouched.` };
+ }
+ if (remove && !speech) {
+ if (video) return { tool: "remove_dialogue", input: { video: media.url }, say: "I'll take the dialogue out and keep the music and sound effects — the picture stays untouched." };
+ return { tool: "split_soundtrack", input: { media: media.url, keep: ["music", "effects"] }, say: "I'll take the dialogue out and keep the music and sound effects." };
+ }
+ if (speech && video && !music && !effects) return { tool: "remove_dialogue", input: { video: media.url, keep: "dialogue" }, say: "I'll keep only the dialogue on the video — the picture stays untouched." };
+ const keep = [speech && "dialogue", music && "music", effects && "effects"].filter(Boolean) as string[];
+ if (keep.length) {
+ const words = keep.map((k) => (k === "effects" ? "sound effects" : k)).join(" and ");
+ return { tool: "split_soundtrack", input: { media: media.url, keep }, say: `I'll split the soundtrack and give you just the ${words}.` };
+ }
+ return { tool: "split_soundtrack", input: { media: media.url }, say: "I'll split the soundtrack into dialogue, music, effects, and music & effects." };
+}
+
// ---------------------------------------------------------------------------
// Picking a take to animate ("animate 2")
diff --git a/src/server/assist/studio-tools.ts b/src/server/assist/studio-tools.ts
index 81010ff9..8b2fe9a9 100644
--- a/src/server/assist/studio-tools.ts
+++ b/src/server/assist/studio-tools.ts
@@ -20,6 +20,12 @@ import { isOffered } from "../model-access";
import { engineMode } from "../settings";
import { fileUrl, saveFile } from "../storage";
import { defineTool, type JobPlace, type ToolContext, type ToolOutcome } from "./define";
+// originals (o/dbs-d9): Split soundtrack and Remove dialogue as tools
+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 { contentTypeFor, filesRel, kindFor } from "../storage";
/**
* Agent access to whole studios: split an image into layers, restyle footage, dub a video, make a
@@ -775,3 +781,208 @@ export const STUDIO_TOOLS = [splitLayers, restyleFootage, dubVideo, facelessEpis
/** For tests: the fallback pipelines, as they would be created. */
export const fallbackSteps = { restore: restoreSteps, layers: layerSteps, restyle: restyleSteps, dub: dubSteps, faceless: facelessSteps, captions: captionSteps, ads: adRequests, blockout: blockoutSteps };
+
+// ---------------------------------------------------------------------------
+// originals (o/dbs-d9): Split soundtrack and Remove dialogue in one call (docs/research/dbs-separation-7.md §8 and §9 D9).
+// Both run the Audio hub's and Video tools' own plans (src/lib/av/split.ts, src/lib/av/remove-dialogue.ts through
+// src/server/audio-tools.ts), so a call reads the file's header, picks the stems and the mux exactly as the pages do, and
+// its results land in the Library. Open engine only: DBS is hosted nowhere, and SAM Audio in the cloud is the owner's call,
+// not taken (docs/handoff/owner-decisions.json samAudioCloud: false); the cloud engine refuses in words.
+
+const SoundtrackEngine = z
+ .enum(["open", "cloud"])
+ .optional()
+ .describe("Leave it out: it runs on the open engine (the user's GPU, free). 'cloud' is refused: DBS isn't hosted on fal or Replicate, and there is no cloud stand-in.");
+
+const SplitSoundtrackInput = z.object({
+ media: ref.describe("The audio file or the video whose soundtrack to split."),
+ keep: z
+ .array(z.enum(KEEP_STEMS as [KeepStem, ...KeepStem[]]))
+ .optional()
+ .describe(
+ "The stems to keep. Left out: all four stems come back (voice = dialogue, music, effects, background = music & effects). One stem (['music']): that stem alone. ['music','effects']: the background stem. Dialogue with music or with effects: one mixed file of those.",
+ ),
+ levels_db: z
+ .object({
+ dialogue: z.number().min(REMIX_MIN_DB).max(REMIX_MAX_DB).optional(),
+ music: z.number().min(REMIX_MIN_DB).max(REMIX_MAX_DB).optional(),
+ effects: z.number().min(REMIX_MIN_DB).max(REMIX_MAX_DB).optional(),
+ })
+ .optional()
+ .describe(`Mix the kept stems back into ONE file at these levels (whole dB, ${REMIX_MIN_DB} to +${REMIX_MAX_DB}; a kept stem with no level stays at 0 dB), e.g. { music: -12 } for the music 12 dB under the dialogue and effects.`),
+ quality: z.enum(["fast", "best"]).optional().describe("fast = DBS-BSRNN, best = DBS-TIGER (about 3x slower on a CPU). Left out: the GPU's pick (best on CUDA, fast on a CPU)."),
+ engine: SoundtrackEngine,
+});
+const RemoveDialogueInput = z.object({
+ video: ref.describe("The video to take the dialogue out of (it must have sound)."),
+ keep: z
+ .enum(["bed", "dialogue"])
+ .optional()
+ .describe("bed (default): the music and sound effects stay, the talking goes. dialogue: only the talking stays. With music_db: the talking stays and the music and effects go quieter under it."),
+ music_db: z.number().min(LOWER_MIN_DB).max(LOWER_MAX_DB).optional().describe(`Keep the dialogue and lower the music and effects to this level under it (dB, ${LOWER_MIN_DB} to 0; ${LOWER_DEFAULT_DB} is a good start).`),
+ quality: z.enum(["fast", "best"]).optional().describe("fast = DBS-BSRNN, best = DBS-TIGER. Left out: the GPU's pick."),
+ engine: SoundtrackEngine,
+});
+export type SplitSoundtrackToolInput = z.infer<typeof SplitSoundtrackInput>;
+export type RemoveDialogueToolInput = z.infer<typeof RemoveDialogueInput>;
+
+/** The engine a soundtrack tool runs on: the open engine unless asked otherwise (Engine mode wins). */
+const soundtrackEngine = (asked?: Engine): Engine => (engineMode() === "both" ? (asked ?? "open") : (engineMode() as Engine));
+
+/** audio / video from the file's name, or why the file can't be split. */
+function mediaKind(url: string): "audio" | "video" {
+ const rel = filesRel(url);
+ const kind = rel ? kindFor(contentTypeFor(rel)) : null;
+ if (kind === "audio" || kind === "video") return kind;
+ throw new Error("Pass an audio file or a video with sound (a file URL from the chat, /api/files/…)");
+}
+
+const levelOf = (l: SplitSoundtrackToolInput["levels_db"]) => l && { dialogue: l.dialogue, music: l.music, effects: l.effects };
+
+/** The Audio hub's Split soundtrack request for a call, and what it returns. Throws what's in the way. */
+export function splitSoundtrackBody(i: SplitSoundtrackToolInput): { body: AudioToolRequest; outcome: SplitOutcome } {
+ const outcome = splitOutcome(i.keep, levelOf(i.levels_db));
+ const kind = mediaKind(i.media);
+ const parsed = AudioToolBody.safeParse({
+ tool: "split",
+ engine: soundtrackEngine(i.engine),
+ media: i.media,
+ kind,
+ ...(i.quality && { quality: i.quality }),
+ ...(outcome.kind === "mix" && { remix: outcome.levels }),
+ });
+ if (!parsed.success) throw new Error("Pass a file URL from the chat (/api/files/…)");
+ return { body: parsed.data, outcome };
+}
+
+/** Video tools → Remove dialogue's request for a call. Throws what's in the way. */
+export function removeDialogueBody(i: RemoveDialogueToolInput): { body: AudioToolRequest; outcome: DialogueOutcome } {
+ if (i.keep === "bed" && i.music_db !== undefined) throw new Error("music_db lowers the music under the dialogue: leave keep out (or set it to 'dialogue') to use it");
+ if (mediaKind(i.video) !== "video") throw new Error("remove_dialogue takes a video: use split_soundtrack for an audio file");
+ const outcome: DialogueOutcome = i.music_db !== undefined ? "lower-music" : i.keep === "dialogue" ? "dialogue-only" : "no-dialogue";
+ const parsed = AudioToolBody.safeParse({
+ tool: "remove-dialogue",
+ engine: soundtrackEngine(i.engine),
+ video: i.video,
+ outcome,
+ ...(outcome === "lower-music" && { musicDb: Math.round(i.music_db!) }),
+ ...(i.quality && { quality: i.quality }),
+ });
+ if (!parsed.success) throw new Error("Pass a video URL from the chat (/api/files/…)");
+ 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 {
+ const seconds = p.split?.duration;
+ if (!seconds || (body.tool !== "split" && body.tool !== "remove-dialogue")) return null;
+ const device = comfyDeviceSeen();
+ 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`;
+}
+
+/** Price (and time) the call the way the page does; never throws: what's in the way is the card's error. */
+function planSoundtrack(tool: string, name: string, kind: "audio" | "video", build: () => { body: AudioToolRequest }): PlannedJob[] {
+ let body: AudioToolRequest;
+ let p: AudioToolPlan;
+ try {
+ body = build().body;
+ p = planAudioTool(body);
+ } catch (e) {
+ return [{ tool, modelId: SPLIT_MODEL, modelName: name, kind, op: "separate-audio", prompt: name, count: 0, costUsd: 0, demo: false, atomic: true, error: (e as Error).message }];
+ }
+ const jobs = planSteps(tool, p.steps.map((s) => ({ key: s.key, request: s.request, ...(s.after && { after: s.after }), ...(s.chain && { chain: s.chain }) })));
+ const time = jobs.some((j) => j.demo) ? null : soundtrackTime(p, body);
+ if (time && jobs[0] && !jobs[0].error) jobs[0] = { ...jobs[0], note: `${jobs[0].note ?? name} · ${time}` };
+ return jobs;
+}
+
+/** Start the call: the host's check first (a DBS model it doesn't have is refused before anything is queued), then one batch. */
+async function runSoundtrack(name: string, href: string, build: () => { body: AudioToolRequest; returns: string }): Promise<ToolOutcome> {
+ let body: AudioToolRequest;
+ let returns: string;
+ try {
+ ({ body, returns } = build());
+ } catch (e) {
+ return { content: JSON.stringify({ error: (e as Error).message }), isError: true };
+ }
+ try {
+ const preview = await previewAudioTool(body);
+ const run = await runAudioTool(body);
+ return {
+ content: JSON.stringify({
+ tool: name,
+ href,
+ engine: body.engine,
+ steps: run.items.map((g) => ({ step: g.request.step?.label, id: g.id })),
+ result: run.result.id,
+ returns,
+ costUsd: preview.costUsd,
+ ...(preview.estimate && !preview.demo && { takes: `${durationWords(preview.estimate)} on your GPU` }),
+ demo: preview.demo || undefined,
+ note: "It runs in the background: check_generations on the result gives the output URLs (audio outputs carry meta.stem: voice, music, effects or background; a mix carries meta.role mix).",
+ }),
+ items: [
+ { id: "", role: "tool", text: `${name}: started${preview.estimate && !preview.demo ? ` (${durationWords(preview.estimate)})` : ""}`, href },
+ { id: "", role: "generations", ids: [run.result.id] },
+ ],
+ };
+ } catch (e) {
+ return { content: JSON.stringify({ error: (e as Error).message }), isError: true };
+ }
+}
+
+const STEM_WORDS: Record<string, string> = { voice: "voice (the dialogue)", music: "music", effects: "effects", background: "background (music & effects)" };
+
+function splitReturns(o: SplitOutcome): string {
+ if (o.kind === "stems") return "four stems on the result: voice (the dialogue), music, effects, background (music & effects)";
+ if (o.kind === "stem") return `the ${STEM_WORDS[o.stem]} stem of the result (it holds all four stems; pick meta.stem ${o.stem})`;
+ return `one mixed file: ${remixWords(o.levels)}`;
+}
+
+const splitSoundtrack = defineTool({
+ name: "split_soundtrack",
+ description:
+ "Split a soundtrack (an audio file or a video) into dialogue, music and effects with DBS — Fuobe's Split soundtrack (Audio → Split soundtrack): " +
+ "four stems (voice, music, effects, background = music & effects), one stem ('give me just the music': keep ['music']), or one file remixed at your levels (levels_db). " +
+ "Runs on the user's GPU (open source, free; a CPU works too, at about a quarter of real time); there is no hosted DBS, so the cloud engine refuses it. " +
+ "Dialogue separates cleanly; music and effects can bleed into each other. A mix that would clip is turned down as a whole. Gated by the same approval card as generate.",
+ schema: SplitSoundtrackInput,
+ gated: true,
+ title: (i) => (i.levels_db ? "Remix the soundtrack" : i.keep?.length === 1 ? `Split soundtrack: just the ${i.keep[0]}` : "Split soundtrack"),
+ place: () => ({ studio: "Split soundtrack", href: "/audio/split" }),
+ plan: (i) => planSoundtrack("split_soundtrack", "Split soundtrack", "audio", () => splitSoundtrackBody(i)),
+ run: (i) =>
+ runSoundtrack("Split soundtrack", "/audio/split", () => {
+ const b = splitSoundtrackBody(i);
+ return { body: b.body, returns: splitReturns(b.outcome) };
+ }),
+});
+
+const REMOVE_RETURNS: Record<DialogueOutcome, string> = {
+ "no-dialogue": "a new video with the music and effects only (the picture copied untouched); the dialogue it took out is a stem of the split step",
+ "dialogue-only": "a new video with the dialogue only (the picture copied untouched); the music & effects it took out are a stem of the split step",
+ "lower-music": "a new video with the dialogue over the lowered music and effects (the picture copied untouched)",
+};
+
+const removeDialogue = defineTool({
+ name: "remove_dialogue",
+ description:
+ "Take the dialogue out of a video, keep only the dialogue, or keep it with the music lowered (music_db) — Fuobe's Remove dialogue (Video tools → Remove dialogue): DBS splits the soundtrack, then the chosen sound goes back on the video with the picture copied untouched. " +
+ "Runs on the user's GPU (open source, free); there is no hosted DBS, so the cloud engine refuses it. Gated by the same approval card as generate.",
+ schema: RemoveDialogueInput,
+ gated: true,
+ title: (i) => (i.music_db !== undefined ? `Lower the music (${Math.round(i.music_db)} dB)` : i.keep === "dialogue" ? "Keep only the dialogue" : "Remove the dialogue"),
+ place: () => ({ studio: "Remove dialogue", href: "/video-tools/remove-dialogue" }),
+ plan: (i) => planSoundtrack("remove_dialogue", "Remove dialogue", "video", () => removeDialogueBody(i)),
+ run: (i) =>
+ runSoundtrack("Remove dialogue", "/video-tools/remove-dialogue", () => {
+ const b = removeDialogueBody(i);
+ return { body: b.body, returns: REMOVE_RETURNS[b.outcome] };
+ }),
+});
+
+/** originals (o/dbs-d9): Split soundtrack and Remove dialogue (registered after the studio tools in ./tools.ts). */
+export const SOUNDTRACK_TOOLS = [splitSoundtrack, removeDialogue];
diff --git a/src/server/assist/tools.ts b/src/server/assist/tools.ts
index 14c1bc62..d06d31e1 100644
--- a/src/server/assist/tools.ts
+++ b/src/server/assist/tools.ts
@@ -27,6 +27,8 @@ import { defineTool, type JobPlace, type ResultContent, type ToolContext, type T
import "./studio-routes";
import { SKILL_TOOLS } from "./skill-tools";
import { STUDIO_TOOLS } from "./studio-tools";
+// originals (o/dbs-d9): split_soundtrack and remove_dialogue
+import { SOUNDTRACK_TOOLS } from "./studio-tools";
export type { ToolContext, ToolOutcome };
@@ -97,7 +99,7 @@ const searchModels = defineTool({
.string()
.optional()
.describe(
- "Operation id to filter by, e.g. t2i, edit, t2v, i2v, flf2v, ref2v, extend, lipsync, avatar, tts, upscale-image, layers, text-layers, trim, transcribe, captions, mux, separate-audio, translate, write, image-to-3d.",
+ "Operation id to filter by, e.g. t2i, edit, t2v, i2v, flf2v, ref2v, extend, lipsync, avatar, tts, upscale-image, layers, text-layers, trim, transcribe, captions, mux, separate-audio, translate, write, image-to-3d. separate-audio models return audio stems (meta.stem): voice (the dialogue) and background (everything else); DBS also returns music and effects (background = music & effects). For a whole split or a remix in one call use split_soundtrack, for a video without its dialogue remove_dialogue.",
),
query: z.string().optional().describe("Words to match in the model name, vendor or description, e.g. 'kling', 'cheap', 'photoreal'."),
}),
@@ -264,7 +266,7 @@ const Job = z.object({
end_image: ref.optional().describe("End frame (first-and-last-frame video)."),
video: ref.optional().describe("Input video (extend, edit, lipsync, upscale, trim, captions, transcribe…)."),
audio: ref.optional().describe("Input audio (lipsync, avatar, transcribe, separate-audio, mux; for voice-change the recording to re-voice)."),
- background_audio: ref.optional().describe("Mux: a second track mixed under the audio — the background stem from separate-audio, or a music bed."),
+ background_audio: ref.optional().describe("Mux: a second track mixed under the audio — the background stem (music & effects) from separate-audio, DBS's music or effects stem alone, or a music bed."),
voice_audio: ref.optional().describe("A recording of the voice to speak with (voice-cloning text to speech) or to change into (voice-change)."),
aspect_ratio: z.string().optional().describe("e.g. 16:9, 9:16, 1:1 — one the model lists."),
resolution: z.string().optional().describe("e.g. 1080p, 2K — one the model lists."),
@@ -550,6 +552,8 @@ export const getTool = (name: string) => TOOLS.find((t) => t.name === name);
// Skills, memory and project sources; then whole studios (layers, restyle, dub, faceless, ads, captions); then saved
// skills that run by themselves (run_skill).
TOOLS.push(...CONTEXT_TOOLS, ...STUDIO_TOOLS, ...SKILL_TOOLS);
+// originals (o/dbs-d9): Split soundtrack and Remove dialogue in one call.
+TOOLS.push(...SOUNDTRACK_TOOLS);
/** The approval card's heading for one gated call. */
export function cardTitle(name: string, input: unknown): string {
diff --git a/src/server/audio-tools.ts b/src/server/audio-tools.ts
index 84b65d00..0d906876 100644
--- a/src/server/audio-tools.ts
+++ b/src/server/audio-tools.ts
@@ -1,7 +1,7 @@
import "server-only";
import { z } from "zod";
import { planJoin, planLoop, CROSSFADE_MAX, JOIN_MAX_CLIPS, LOOP_MAX_SECONDS, type AudioToolPreview, type ToolPlan } from "@/lib/av/audio-tools";
-import { CLOUD_ONLY_PROBLEM, DBS_MODELS, dbsChannelsFor, hostPick, missingDbs, planRemux, planSplit, splitTime } from "@/lib/av/split";
+import { CLOUD_ONLY_PROBLEM, DBS_MODELS, dbsChannelsFor, hostPick, missingDbs, planRemux, planSplit, REMIX_MAX_DB, splitTime } from "@/lib/av/split";
import { CLOUD_ONLY_REMOVE_PROBLEM, LOWER_MAX_DB, LOWER_MIN_DB, NO_SOUND_PROBLEM, planRemoveDialogue, removeDialogueTime } from "@/lib/av/remove-dialogue";
import { CLOUD_ONLY_CLEAN_PROBLEM, missingReuse, NO_REUSE_PACK, planClean, planTime, tooLongProblem } from "@/lib/av/clean-voice";
import type { Engine, Generation } from "@/lib/catalog/types";
@@ -55,6 +55,8 @@ export const AudioToolBody = z.discriminatedUnion("tool", [
/** Fast (DBS-BSRNN) or Best (DBS-TIGER); unset = the host's pick. */
quality: z.enum(["fast", "best"]).optional(),
stereo: z.boolean().optional(),
+ /** originals (o/dbs-d9): one mix at these levels (whole dB; -100 = left out) instead of four stems (graph C). */
+ remix: z.object({ voiceDb: z.number().int().min(-100).max(REMIX_MAX_DB), musicDb: z.number().int().min(-100).max(REMIX_MAX_DB), effectsDb: z.number().int().min(-100).max(REMIX_MAX_DB) }).optional(),
/** What the browser decoded (the server reads WAV / FLAC / MP3 headers itself). */
channels: z.number().int().positive().max(64).optional(),
sourceDuration: z.number().positive().max(36_000).optional(),
@@ -140,7 +142,12 @@ function factsOf(url: string, gone = "That audio file is gone — add it again")
return { ...(duration && { duration }), ...(info.channels && { channels: info.channels }), hasAudio: info.hasAudio };
}
-async function plan(body: AudioToolRequest): Promise<ToolPlan & { engine: Engine; split?: ClipFacts; headerChannels?: number }> {
+/** What a run would do (the page's preview, Assist's and MCP's split_soundtrack / remove_dialogue cards), without starting it. */
+export type AudioToolPlan = ToolPlan & { engine: Engine; split?: ClipFacts; headerChannels?: number };
+const plan = async (body: AudioToolRequest): Promise<AudioToolPlan> => planAudioTool(body);
+
+/** Synchronous: a header read at most (storedMedia, cached); throws AudioToolError with what's in the way. */
+export function planAudioTool(body: AudioToolRequest): AudioToolPlan {
const mode = engineMode();
// Split soundtrack and Remove dialogue run on the open engine only: an install set to paid APIs only says why, whichever
// engine was asked for.
@@ -223,7 +230,7 @@ export async function previewAudioTool(body: AudioToolRequest): Promise<AudioToo
if (installed && !installed.includes(DBS_MODELS[quality])) throw new AudioToolError(missingDbs(DBS_MODELS[quality], installed));
const { duration: seconds, channels } = p.split ?? {};
Object.assign(out, { hostPick: pick, ...(device && { device }), ...(installed && { installed: installed.map((m) => (m === DBS_MODELS.best ? "best" : "fast")) }), ...(p.headerChannels && { channels: p.headerChannels }) });
- const mode = dbsChannelsFor(body.tool === "split" && body.stereo ? "each channel" : "mono", channels);
+ const mode = dbsChannelsFor(body.tool === "split" && (body.stereo ?? !!body.remix) ? "each channel" : "mono", channels);
if (seconds) out.estimate = (body.tool === "split" ? splitTime : removeDialogueTime)({ seconds, quality, mode, channels, device });
}
if (body.tool === "clean") {
diff --git a/src/server/mcp.ts b/src/server/mcp.ts
index 8965f88c..bc9c66f2 100644
--- a/src/server/mcp.ts
+++ b/src/server/mcp.ts
@@ -16,7 +16,7 @@ import { enabledSkills, getSkill, skillRecipe } from "./skills";
*/
const PROTOCOL_VERSIONS = ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
-const SERVER_INFO = { name: "fuobe", title: "Fuobe studio", version: "1.3.0" };
+const SERVER_INFO = { name: "fuobe", title: "Fuobe studio", version: "1.4.0" };
const INSTRUCTIONS =
"Fuobe is an AI image, video and audio studio (paid cloud models and open-source ComfyUI workflows); it also transcribes, translates and writes text and turns images into 3D models. " +
"Look up models with search_models (kinds image, video, audio, text, model3d), price a plan with estimate_cost and tell the user the cost before you call generate or create_storyboard. " +
@@ -25,6 +25,8 @@ const INSTRUCTIONS =
"Each studio job opens in that Fuobe studio (a Layers project, a Shorts session, a dub to review, a Faceless episode, an Ads Studio batch, the Captions editor, Katana): the result's href is its page on this Fuobe server, so give the user that link; a call the studio can't take runs as plain steps and says why. " +
"Skills are playbooks for kinds of jobs (product photos, UGC videos, thumbnails…): list_skills, then load_skill to read one — they're also offered as prompts. " +
"A skill that runs by itself (list_skills marks it and names its inputs) runs with run_skill and values for those inputs, the same steps every time: price it with estimate_job first. " +
+ // originals (o/dbs-d9, 1.4.0): Split soundtrack and Remove dialogue
+ "A soundtrack splits in one call with split_soundtrack (dialogue, music, effects and music & effects stems, one stem, or one remix at your levels) and a video loses its dialogue with remove_dialogue (or keeps only it, or lowers the music under it): both run on the user's GPU (open source, free; there is no hosted DBS, so the cloud engine refuses them); price them with estimate_job first. " +
"Generations run in the background: poll check_generations (wait_seconds up to 120) for output URLs; text results come back inline. Output URLs are paths on this Fuobe server.";
interface JsonRpcRequest {
diff --git a/src/server/providers/comfyui.ts b/src/server/providers/comfyui.ts
index 70a0fb2c..1e1be3f5 100644
--- a/src/server/providers/comfyui.ts
+++ b/src/server/providers/comfyui.ts
@@ -722,6 +722,15 @@ declare global {
* 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.
+ */
+export function comfyDeviceSeen(): string | undefined {
+ const url = baseUrl("main");
+ return url ? globalThis.__fuobeComfyDevice?.get(url)?.type : undefined;
+}
+
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-studio-routes.test.ts b/tests/assist-studio-routes.test.ts
index a9b62f4d..3bb44994 100644
--- a/tests/assist-studio-routes.test.ts
+++ b/tests/assist-studio-routes.test.ts
@@ -459,7 +459,7 @@ describe("MCP", () => {
const init = (await rpc("initialize", { protocolVersion: "2025-11-25" })) as { result: { instructions: string; serverInfo: { version: string } } };
expect(init.result.instructions).toMatch(/katana/);
expect(init.result.instructions).toMatch(/href/);
- expect(init.result.serverInfo.version).toBe("1.3.0");
+ expect(init.result.serverInfo.version).toBe("1.4.0");
});
it("estimate_job says where the job opens, or why it runs in the Library", async () => {
diff --git a/tests/mcp.test.ts b/tests/mcp.test.ts
index b52592f8..aed4ff3a 100644
--- a/tests/mcp.test.ts
+++ b/tests/mcp.test.ts
@@ -51,9 +51,9 @@ describe("MCP server", () => {
expect(await rpc("tools/call", { name: "rm_rf" })).toMatchObject({ error: { code: -32602 } });
});
- it("serves run_skill (W3): listed, priced by estimate_job, and named in the instructions of version 1.3.0", async () => {
+ it("serves run_skill (W3): listed, priced by estimate_job, and named in the instructions (since version 1.3.0)", async () => {
const init = (await rpc("initialize", { protocolVersion: "2025-06-18" })) as { result: { serverInfo: { version: string }; instructions: string } };
- expect(init.result.serverInfo.version).toBe("1.3.0");
+ expect(init.result.serverInfo.version).toBe("1.4.0");
expect(init.result.instructions).toMatch(/run_skill/);
const r = (await rpc("tools/list")) as { result: { tools: { name: string; description: string; inputSchema: { properties: Record<string, { enum?: string[] } & Record<string, unknown>> }; annotations: { readOnlyHint: boolean; openWorldHint: boolean } }[] } };
const run = r.result.tools.find((t) => t.name === "run_skill")!;