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.

Extend & remix: Stems and Remix are offered only on songs Mureka takes, and a song it would refuse is turned away in plain words before anything is sent

Claude167c643d9034
diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsx
index f955d9a9..4b15b048 100644
--- a/src/components/studio/composer.tsx
+++ b/src/components/studio/composer.tsx
@@ -14,7 +14,7 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip
import { useToday } from "@/hooks/use-today";
import { estimateCost, imageLimit, layoutCanvas, planGeneration, routesFor, type Plan } from "@/lib/catalog/plan";
import type { Engine, GenerationRequest, InputSlot, MediaKind, ModelDef, Operation, Preset, PresetRoute, VideoFormat } from "@/lib/catalog/types";
-import { LYRICS_PARAM, SONG_ID_PARAM, withSongId } from "@/lib/lyrics";
+import { LYRICS_PARAM, SONG_ID_PARAM, songFormat, songToolProblem, withSongId } from "@/lib/lyrics";
import { dualEngine } from "@/lib/catalog/engines";
import { locksByDefault } from "@/lib/catalog/palettes";
import { DEFAULT_LOOK, lookCard } from "@/lib/catalog/soul-cards";
@@ -678,6 +678,10 @@ export function Composer({ docked }: { docked: boolean }) {
// an open tool that holds the whole clip in more RAM than the ComfyUI can spare.
const clipProblem = config.clipFacts ? clipBlocker(studioOp ?? op, facts, draft.params, model, status?.providers.comfyui?.ramBytes) : null;
if (clipProblem && !planError) planError = clipProblem;
+ // A song Mureka's tools refuse (Stems: MP3 or M4A; Remix: 10 s to 5:50), from its name and header, as the server does.
+ const songRef = config.voiceFacts && (op === "song-stems" || op === "song-remix") ? draft.slots.audio?.ref : undefined;
+ const songProblem = songRef ? songToolProblem(op!, { format: songFormat(undefined, songRef), seconds: voice?.duration }) : null;
+ if (songProblem && !planError) planError = songProblem;
if (signed.blocker) planError = signed.blocker;
// Models that take no prompt (try-on, 3D, transcription, upscalers), or can run without one, never ask for one.
// A model that reads only words (Open-H3 Regenerate redraws from them) asks for them even in a tool that hides the box.
diff --git a/src/components/studio/result-media.tsx b/src/components/studio/result-media.tsx
index 0b6151c2..1e90b467 100644
--- a/src/components/studio/result-media.tsx
+++ b/src/components/studio/result-media.tsx
@@ -40,9 +40,12 @@ export function MediaThumb({
return <TileVideo output={output} poster={videoPoster(g, output)} autoPlay={autoPlay} className={cn("size-full", object, className)} />;
}
if (output.kind === "audio") {
+ // A song's stem (vocals, drums…) says which track it is.
+ const stem = typeof output.meta?.stem === "string" && output.meta.stem.trim() ? output.meta.stem.trim() : null;
return (
<div className={cn("flex size-full flex-col items-center justify-center gap-3 bg-brand-faint p-4 text-brand-text", className)}>
<AudioLines className="size-8" />
+ {stem && <span className="max-w-full truncate text-[13px] font-medium first-letter:uppercase">{stem}</span>}
<audio src={output.url} controls className="w-full max-w-64" onClick={(e) => e.stopPropagation()} />
</div>
);
diff --git a/src/components/studio/studio-page.tsx b/src/components/studio/studio-page.tsx
index 9bbaf3ae..a7c92835 100644
--- a/src/components/studio/studio-page.tsx
+++ b/src/components/studio/studio-page.tsx
@@ -138,6 +138,8 @@ function initialDraft(
if (sp.get("audio")) slots.audio = slot(sp.get("audio"));
// A Mureka song handed over (a music result's Extend, Remix or Stems): its id goes with it.
const song = sp.get("audio") && sp.get("song") ? { id: sp.get("song")!, url: sp.get("audio")! } : undefined;
+ // A song's lyrics handed over with it (a sung result's Remix, which needs the whole song's words).
+ const lyrics = sp.get("lyrics") ?? undefined;
// A voice sample handed over (Clean up voice → "Use as a voice sample"): the voice a cloning model speaks with.
if (sp.get("voice")) slots.voiceAudio = slot(sp.get("voice"));
// An output format handed over in the link (Export → "ProRes in the cloud"), when the model writes it.
@@ -154,6 +156,7 @@ function initialDraft(
presetId: sp.get("preset") ?? config.preset?.id,
presetOptions: {},
...(song && { song }),
+ ...(lyrics && { lyrics }),
};
}
diff --git a/src/lib/catalog/plan.ts b/src/lib/catalog/plan.ts
index 1e3aeb59..57829443 100644
--- a/src/lib/catalog/plan.ts
+++ b/src/lib/catalog/plan.ts
@@ -509,12 +509,12 @@ export function planGeneration(
}
// A model that needs words to sing: a song from lyrics (YuE2), the lyrics of a song's new part or of its remix (Mureka).
const sung = lyricsOf(params.extra);
- if (model.options.lyrics?.required && (!sung || (op === "music" && isInstrumental(sung)))) {
+ if (model.options.lyrics?.required && (!sung || ((op === "music" || op === "song-remix") && isInstrumental(sung)))) {
throw new Error(
op === "song-extend"
? "Write the lyrics of the new part"
: op === "song-remix"
- ? "Write the remix's lyrics: the whole song, with [Verse] and [Chorus] on lines of their own"
+ ? "Write the remix's lyrics: the whole song, with [Verse] and [Chorus] on lines of their own (Mureka remixes songs with vocals, not instrumentals)"
: `${model.name} sings your lyrics: write them first, with [Verse] and [Chorus] on lines of their own`,
);
}
diff --git a/src/lib/library.ts b/src/lib/library.ts
index 7bd6d2e7..ab15012b 100644
--- a/src/lib/library.ts
+++ b/src/lib/library.ts
@@ -334,12 +334,14 @@ export function extensionOf(o: Pick<OutputFile, "url" | "kind">): string {
export function downloadName(
g: Pick<Generation, "id" | "prompt" | "modelId" | "request" | "op" | "presetName" | "modelName">,
- o: Pick<OutputFile, "url" | "kind">,
+ o: Pick<OutputFile, "url" | "kind" | "meta">,
i: number,
ext = extensionOf(o),
): string {
const base = userTitle(g).slice(0, 40).replace(/[^\w]+/g, "-").replace(/^-|-$/g, "") || "fuobe";
- return `${base}-${g.id.slice(0, 6)}${i ? `-${i + 1}` : ""}.${ext}`;
+ // A stem (a song's vocals, drums…) is named for its track rather than its place in the list.
+ const stem = typeof o.meta?.stem === "string" ? o.meta.stem.toLowerCase().replace(/[^\w]+/g, "-").replace(/^-|-$/g, "").slice(0, 24) : "";
+ return `${base}-${g.id.slice(0, 6)}${stem ? `-${stem}` : i ? `-${i + 1}` : ""}.${ext}`;
}
export const downloadHref = (url: string, name: string) => `${url}${url.includes("?") ? "&" : "?"}download=${encodeURIComponent(name)}`;
diff --git a/src/lib/lyrics.ts b/src/lib/lyrics.ts
index a579ef0b..7862fdd4 100644
--- a/src/lib/lyrics.ts
+++ b/src/lib/lyrics.ts
@@ -159,3 +159,50 @@ export function songLength(seconds: number): string {
const s = Math.max(0, Math.round(seconds));
return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
}
+
+/**
+ * What Mureka's song tools take (fal's schemas, read 2026-11-02): Stems an MP3 or M4A song of up to 10 MB; Remix a song of
+ * 10 to 350 seconds with vocals (not an instrumental).
+ */
+export const STEMS_FORMATS = ["mp3", "m4a"];
+export const STEMS_MAX_BYTES = 10 * 1000 * 1000;
+export const REMIX_SECONDS = { min: 10, max: 350 } as const;
+
+const FORMAT_OF_TYPE: Record<string, string> = {
+ "audio/mpeg": "mp3",
+ "audio/mp3": "mp3",
+ "audio/mp4": "m4a",
+ "audio/m4a": "m4a",
+ "audio/x-m4a": "m4a",
+ "audio/aac": "aac",
+ "audio/wav": "wav",
+ "audio/x-wav": "wav",
+ "audio/wave": "wav",
+ "audio/flac": "flac",
+ "audio/x-flac": "flac",
+ "audio/ogg": "ogg",
+ "audio/webm": "webm",
+};
+
+/** A song file's format ("mp3", "wav"…) from its type, else its name; undefined when neither says. */
+export function songFormat(contentType: string | undefined, name: string | undefined): string | undefined {
+ const byType = contentType ? FORMAT_OF_TYPE[contentType.split(";")[0].trim().toLowerCase()] : undefined;
+ if (byType) return byType;
+ const ext = /\.([a-z0-9]{2,5})(?:[?#]|$)/i.exec(name?.split("/").pop() ?? "")?.[1]?.toLowerCase();
+ return ext === "mpeg" || ext === "mpga" ? "mp3" : ext;
+}
+
+/** Why a song tool can't take this song, in plain words; null when it can (what isn't known yet is not held against it). */
+export function songToolProblem(op: string, song: { format?: string; bytes?: number; seconds?: number }): string | null {
+ if (op === "song-stems") {
+ if (song.format && !STEMS_FORMATS.includes(song.format)) return `Stems take an MP3 or M4A song: this one is a ${song.format.toUpperCase()} file. Save it as an MP3 and add it again`;
+ if (song.bytes && song.bytes > STEMS_MAX_BYTES) {
+ return `Stems take a song of up to 10 MB: this one is ${Math.ceil(song.bytes / 100_000) / 10} MB. Save it as a smaller MP3 and add it again`;
+ }
+ }
+ if (op === "song-remix" && song.seconds && (song.seconds < REMIX_SECONDS.min || song.seconds > REMIX_SECONDS.max)) {
+ return `Remix takes a song of ${songLength(REMIX_SECONDS.min)} to ${songLength(REMIX_SECONDS.max)}: this one is ${songLength(song.seconds)}`;
+ }
+ return null;
+}
+
diff --git a/src/lib/output-actions.ts b/src/lib/output-actions.ts
index 2515d3c9..e75fb27c 100644
--- a/src/lib/output-actions.ts
+++ b/src/lib/output-actions.ts
@@ -14,6 +14,7 @@ import { decodeMoss, LAYOUT_PARAM, readLayout, type LayoutDraft } from "./layout
import { REMOVE_DIALOGUE_FEATURE } from "./av/remove-dialogue";
import { canRerender, regenerateFamily, regenerateHref, rerenderLabel } from "./catalog/regenerate";
import { CLEAN_FEATURE } from "./av/clean-voice";
+import { isInstrumental, lyricsOf, songFormat, STEMS_FORMATS } from "./lyrics";
export type OutputActionId =
| "animate"
@@ -160,12 +161,18 @@ export function outputActions(g: Generation, index: number, ctx: ActionContext =
link("voice-change", "Change voice", `/audio/voice-change?audio=${q(o.url)}`);
link("loop-audio", "Loop / extend", `/audio/loop?audio=${q(o.url)}`);
// A song's cloud tools (Mureka, Audio → Extend & remix): any song, one of Mureka's own by its id. Not on an install
- // that runs open models only.
+ // that runs open models only. Remix only where there are vocals to keep (with the song's lyrics, which it needs whole),
+ // Stems only on an MP3 or M4A song (what Mureka separates).
if (g.op && SONG_OPS.has(g.op) && ctx.engineMode !== "open") {
const song = typeof o.meta?.songId === "string" ? `&song=${q(o.meta.songId)}` : "";
link("extend-song", "Extend song", `/audio/song?model=mureka-extend&audio=${q(o.url)}${song}`);
- link("remix-song", "Remix", `/audio/song?model=mureka-remix&audio=${q(o.url)}${song}`);
- link("song-stems", "Stems", `/audio/song?model=mureka-stems&audio=${q(o.url)}`);
+ if (!instrumentalSong(g)) {
+ const words = lyricsOf(g.request?.params?.extra);
+ const lyrics = words && q(words).length <= HANDOVER_LYRICS_MAX ? `&lyrics=${q(words)}` : "";
+ link("remix-song", "Remix", `/audio/song?model=mureka-remix&audio=${q(o.url)}${song}${lyrics}`);
+ }
+ const format = songFormat(o.contentType, o.url);
+ if (!format || STEMS_FORMATS.includes(format)) link("song-stems", "Stems", `/audio/song?model=mureka-stems&audio=${q(o.url)}`);
}
link("split-soundtrack", "Split soundtrack", `/audio/split?audio=${q(o.url)}`);
// Not on music or sound effects (it keeps only a voice), nor on a voice it already cleaned.
@@ -216,6 +223,21 @@ export function outputActions(g: Generation, index: number, ctx: ActionContext =
/** Results that are songs: made, extended or remixed. */
const SONG_OPS = new Set<Generation["op"]>(["music", "song-extend", "song-remix"]);
+/** Music models that make instrumentals only, and those that make one when they're given no words to sing. */
+const INSTRUMENTAL_MODELS = new Set(["mureka-9-instrumental", "mureka-9-5-instrumental", "sonilo-music", "stable-audio-3-music", "stable-audio-2-5"]);
+const INSTRUMENTAL_WITHOUT_WORDS = new Set(["minimax-music-3", "oss-minimax-music-3", "oss-ace-step"]);
+
+/** A song with no vocals: an instrumental model's, one whose lyrics are only [Instrumental], or a model's own with no words. */
+export function instrumentalSong(g: Pick<Generation, "modelId" | "op" | "request">): boolean {
+ if (INSTRUMENTAL_MODELS.has(g.modelId)) return true;
+ const words = lyricsOf(g.request?.params?.extra);
+ if (words) return isInstrumental(words);
+ return g.op === "music" && INSTRUMENTAL_WITHOUT_WORDS.has(g.modelId);
+}
+
+/** The most of a song's lyrics a Remix link carries (encoded): longer ones are written again in the editor. */
+const HANDOVER_LYRICS_MAX = 6000;
+
/** The hand-offs offered as next steps under a fresh result, best first (UX-18). */
const NEXT_STEPS: Partial<Record<OutputFile["kind"], OutputActionId[]>> = {
image: ["animate", "upscale", "edit"],
diff --git a/src/server/generations.ts b/src/server/generations.ts
index 86c4828f..4e0ae255 100644
--- a/src/server/generations.ts
+++ b/src/server/generations.ts
@@ -82,6 +82,7 @@ import { offeredLoras, offeredRoutes, requireOffered } from "./model-access";
import { llmBackends, llmLabel, llmMissing, llmUsesClaude, probeLocal } from "./providers/llm";
import type { PollContext, PollResult, ProviderAdapter, RemoteOutput } from "./providers/types";
import { mediaFacts } from "./media-facts";
+import { songFormat, songToolProblem } from "@/lib/lyrics";
import { modelToFinish, startModelFinish, startTurntable, stopModelFinish, type OutputStore } from "./model3d-finish";
import { cropPicture, isCropWindow } from "./crop-picture";
import { convertMask, decodePng, encodePng } from "./png";
@@ -1565,6 +1566,9 @@ function submit(id: string, route: ModelRoute, providerId: ProviderId, plan: Ret
return own.run(() => submitNow(id, route, providerId, plan, req, index));
}
+/** A song's cloud tools (Mureka): the song's length and format are read before it's sent. */
+const SONG_TOOL_OPS = new Set<Operation>(["song-extend", "song-remix", "song-stems"]);
+
async function submitNow(
id: string,
route: ModelRoute,
@@ -1641,6 +1645,19 @@ async function submitNow(
return adapter.prepareFile(f.data, f.contentType, f.name, route);
});
};
+ // A song tool's song (Mureka): its length read as a voice's is, and one Mureka refuses (Stems: MP3 or M4A, 10 MB; Remix:
+ // 10 to 350 seconds) refused here, before it's sent to Mureka or paid for.
+ const prepSong = async (ref?: string) => {
+ if (!ref) return undefined;
+ return gate(async () => {
+ const f = await readRef(ref);
+ const facts = mediaFacts(f.data);
+ if (facts.duration && !source.sourceDuration) source = { ...source, sourceDuration: facts.duration };
+ const problem = providerId === "mock" ? null : songToolProblem(plan.op, { format: songFormat(f.contentType, f.name), bytes: f.data.length, seconds: facts.duration });
+ if (problem) throw new Error(problem);
+ return adapter.prepareFile(f.data, f.contentType, f.name, route);
+ });
+ };
// Reference clips and clip elements a model bills with the output (Kling 4.0, Pricing.clipInput): their headers' lengths.
// By the clip's place in inputs.videos, so a clip element (params.elements' video) finds its own length.
const clipLengths: (number | undefined)[] = [];
@@ -1709,7 +1726,7 @@ async function submitNow(
endImage: await prep(req.inputs?.endImage),
mask: await prepMask(req.inputs?.mask),
video: await prepVideo(req.inputs?.video),
- audio: await (plan.op === "avatar" || plan.op === "song-extend" ? prepVoice : prep)(req.inputs?.audio),
+ audio: await (plan.op === "avatar" ? prepVoice : SONG_TOOL_OPS.has(plan.op) ? prepSong : prep)(req.inputs?.audio),
audio2: await prep(req.inputs?.audio2),
voiceAudio: await prep(req.inputs?.voiceAudio),
voiceAudio2: await prep(req.inputs?.voiceAudio2),
diff --git a/tests/music3-cloud.test.ts b/tests/music3-cloud.test.ts
index d17ad7e7..c5841b1e 100644
--- a/tests/music3-cloud.test.ts
+++ b/tests/music3-cloud.test.ts
@@ -10,6 +10,8 @@ import { buildPayload, extractOutputs } from "@/lib/catalog/payload";
import { estimateCost, planGeneration } from "@/lib/catalog/plan";
import type { GenerationRequest, ModelRoute, Operation } from "@/lib/catalog/types";
import { nextSteps, outputActions } from "@/lib/output-actions";
+import { downloadName } from "@/lib/library";
+import { songFormat, songToolProblem } from "@/lib/lyrics";
import type { Generation } from "@/lib/catalog/types";
const route = (id: string, op?: Operation): ModelRoute => {
@@ -179,8 +181,44 @@ describe("a music result's song tools", () => {
expect(acts.map((a) => a.label)).toEqual(["Extend song", "Remix", "Stems"]);
expect(acts[0].href).toBe("/audio/song?model=mureka-extend&audio=%2Fapi%2Ffiles%2Fsong.mp3&song=song_1");
expect(acts[2].href).toBe("/audio/song?model=mureka-stems&audio=%2Fapi%2Ffiles%2Fsong.mp3");
- // Any song made in Fuobe (a song from your GPU too): sent to Mureka first.
- expect(ids(gen({ modelId: "oss-minimax-music-3" }))[1].href).toBe("/audio/song?model=mureka-remix&audio=%2Fapi%2Ffiles%2Fsong.mp3");
+ // Any song made in Fuobe (a song from your GPU too): sent to Mureka first, with its lyrics for the remix.
+ const sung = gen({ modelId: "oss-minimax-music-3", request: { feature: "audio", modelId: "oss-minimax-music-3", params: { extra: { lyrics: "[Verse]\nla la" } } } });
+ expect(ids(sung)[1].href).toBe("/audio/song?model=mureka-remix&audio=%2Fapi%2Ffiles%2Fsong.mp3&lyrics=%5BVerse%5D%0Ala%20la");
+ });
+
+ it("Remix only on a song with vocals; Stems only on an MP3 or M4A song", () => {
+ const labels = (g: Generation) => ids(g).map((a) => a.label);
+ // Instrumentals: Mureka's instrumental model, lyrics that are only [Instrumental], a model's own with no words.
+ expect(labels(gen({ modelId: "mureka-9-instrumental" }))).toEqual(["Extend song", "Stems"]);
+ expect(labels(gen({ modelId: "mureka-9-5-instrumental" }))).toEqual(["Extend song", "Stems"]);
+ expect(labels(gen({ request: { feature: "audio", modelId: "mureka-song", params: { extra: { lyrics: "[Instrumental]" } } } }))).toEqual(["Extend song", "Stems"]);
+ expect(labels(gen({ modelId: "minimax-music-3" }))).toEqual(["Extend song", "Stems"]);
+ expect(labels(gen({ modelId: "oss-ace-step" }))).toEqual(["Extend song", "Stems"]);
+ // A song Mureka writes words for from a description keeps Remix.
+ expect(labels(gen())).toEqual(["Extend song", "Remix", "Stems"]);
+ // A WAV song (fal's MiniMax Music 3 answers with one): no Stems.
+ const wav = { ...gen({ request: { feature: "audio", modelId: "minimax-music-3", params: { extra: { lyrics: "[Verse]\nla" } } } }), outputs: [{ url: "/api/files/song.wav", kind: "audio", contentType: "audio/wav" }] } as unknown as Generation;
+ expect(labels(wav)).toEqual(["Extend song", "Remix"]);
+ expect(nextSteps(wav, 0).map((a) => a.label)).toEqual(["Extend song", "Remix", "Split soundtrack"]);
+ });
+
+ it("says in plain words which songs the tools take", () => {
+ expect(songFormat("audio/mpeg", "x")).toBe("mp3");
+ expect(songFormat(undefined, "/api/files/a/song.M4A?x=1")).toBe("m4a");
+ expect(songFormat(undefined, "/api/files/abc")).toBeUndefined();
+ expect(songToolProblem("song-stems", { format: "flac" })).toBe("Stems take an MP3 or M4A song: this one is a FLAC file. Save it as an MP3 and add it again");
+ expect(songToolProblem("song-stems", { format: "mp3", bytes: 9_000_000 })).toBeNull();
+ expect(songToolProblem("song-remix", { seconds: 351 })).toBe("Remix takes a song of 0:10 to 5:50: this one is 5:51");
+ expect(songToolProblem("song-remix", { seconds: 120, format: "wav" })).toBeNull();
+ expect(songToolProblem("song-extend", { seconds: 900, format: "wav" })).toBeNull();
+ // The remix of an instrumental is refused in the plan.
+ expect(planError({ modelId: "mureka-remix", prompt: "jazz", inputs: { audio: "/api/files/s.mp3" }, params: { extra: { lyrics: "[Instrumental]" } } })).toMatch(/^Write the remix's lyrics.*not instrumentals\)$/);
+ });
+
+ it("names a stem's card and download for its track", () => {
+ const g = { ...gen({ op: "song-stems" }), outputs: [{ url: "/api/files/a.mp3", kind: "audio", meta: { stem: "vocals" } }, { url: "/api/files/b.mp3", kind: "audio", meta: { stem: "bass guitar" } }] } as unknown as Generation;
+ expect(downloadName(g, g.outputs[0], 0)).toMatch(/-g1-vocals\.mp3$/);
+ expect(downloadName(g, g.outputs[1], 1)).toMatch(/-g1-bass-guitar\.mp3$/);
});
it("are a song's next steps", () => {
diff --git a/tests/music3-open.test.ts b/tests/music3-open.test.ts
index 7b51a97b..274c439a 100644
--- a/tests/music3-open.test.ts
+++ b/tests/music3-open.test.ts
@@ -21,6 +21,8 @@ const { buildLicenceList, licenceInfo, workflowLicence } = await import("@/lib/l
const { setSetting } = await import("@/server/settings");
const { falProvider, stemsFromZip } = await import("@/server/providers/fal");
const { zip } = await import("@/server/zip");
+const { saveFile } = await import("@/server/storage");
+const { createGenerations, getGeneration } = await import("@/server/generations");
const { unzip } = await import("@/server/unzip");
const requirements = JSON.parse(fs.readFileSync("workflows/comfyui/requirements.json", "utf8")) as { workflows: Record<string, { files: string[]; vramGb?: number | string }> };
@@ -164,6 +166,44 @@ describe("the fal provider's song tools", () => {
expect(own.payload).toMatchObject({ song_id: "song_1" });
});
+ it("refuses a song Mureka's tools can't take before anything is sent or paid for", async () => {
+ /** A WAV header of `seconds` at 8 kHz mono 8-bit, its samples silent. */
+ const wav = (seconds: number) => {
+ const h = Buffer.alloc(44);
+ h.write("RIFF", 0);
+ h.writeUInt32LE(36 + seconds * 8000, 4);
+ h.write("WAVEfmt ", 8);
+ h.writeUInt32LE(16, 16);
+ h.writeUInt16LE(1, 20);
+ h.writeUInt16LE(1, 22);
+ h.writeUInt32LE(8000, 24);
+ h.writeUInt32LE(8000, 28);
+ h.writeUInt16LE(1, 32);
+ h.writeUInt16LE(8, 34);
+ h.write("data", 36);
+ h.writeUInt32LE(seconds * 8000, 40);
+ return Buffer.concat([h, Buffer.alloc(seconds * 8000, 128)]);
+ };
+ const file = (name: string, contentType: string, data: Buffer) => saveFile({ name, contentType, source: "upload", data }).url;
+ const run = async (modelId: string, audio: string, extra: Record<string, unknown> = {}, prompt = "") => {
+ const [g] = createGenerations({ feature: "song-tools", modelId, engine: "cloud", prompt, inputs: { audio }, params: { extra } });
+ for (let i = 0; i < 200 && !["failed", "succeeded"].includes(getGeneration(g.id)!.status); i++) await new Promise((r) => setTimeout(r, 10));
+ return getGeneration(g.id)!;
+ };
+ log.length = 0;
+ const stems = await run("mureka-stems", file("bed.wav", "audio/wav", wav(3)));
+ expect(stems.status).toBe("failed");
+ expect(stems.error).toBe("Stems take an MP3 or M4A song: this one is a WAV file. Save it as an MP3 and add it again");
+ const big = await run("mureka-stems", file("big.mp3", "audio/mpeg", Buffer.concat([Buffer.from("ID3"), Buffer.alloc(10_500_000)])));
+ expect(big.error).toBe("Stems take a song of up to 10 MB: this one is 10.6 MB. Save it as a smaller MP3 and add it again");
+ const long = await run("mureka-remix", file("long.wav", "audio/wav", wav(400)), { lyrics: "[Verse]\nla" }, "jazz");
+ expect(long.error).toBe("Remix takes a song of 0:10 to 5:50: this one is 6:40");
+ const short = await run("mureka-remix", file("short.wav", "audio/wav", wav(5)), { lyrics: "[Verse]\nla" }, "jazz");
+ expect(short.error).toBe("Remix takes a song of 0:10 to 5:50: this one is 0:05");
+ // Nothing reached fal: no upload to Mureka, no run.
+ expect(log).toEqual([]);
+ });
+
it("unpacks the stems' zip into one result per track, named by its file", async () => {
const m = model("mureka-stems");
const job = await falProvider.submit({ generationId: "g", model: m, route: m.routes[0], input: { prompt: "", audio: "https://files.test/song.mp3" } });