Skip to content

Suno-style web UI for a self-hosted MiniMax-Music3 inference server

feat: per-track opt-in streaming toggle, render time on cards, robust end-of-render handoff

Adam Benhassenedccd7aae764
diff --git a/server/src/app.ts b/server/src/app.ts
index f8aa770..e3a5be3 100644
--- a/server/src/app.ts
+++ b/server/src/app.ts
@@ -91,6 +91,7 @@ export function createApp(deps: AppDeps) {
progress: 0,
stage: 'queued',
eta: null,
+ stream: g.stream,
renderedSeconds: null,
error: null,
file: null,
diff --git a/server/src/types.ts b/server/src/types.ts
index a81a867..3129e18 100644
--- a/server/src/types.ts
+++ b/server/src/types.ts
@@ -19,6 +19,8 @@ export interface Track {
eta: number | null;
/** seconds since the render started */
elapsed?: number | null;
+ /** opt-in: use the upstream's optional streaming extension when it advertises one */
+ stream: boolean;
/** seconds of audio already on disk while streaming; null when the server can't stream */
renderedSeconds: number | null;
error: string | null;
@@ -35,6 +37,7 @@ export interface GenerateRequest {
seed: number | null;
format: string;
takes: number;
+ stream: boolean;
}
export interface Template {
diff --git a/server/src/upstream.ts b/server/src/upstream.ts
index 53f9308..b6b7d34 100644
--- a/server/src/upstream.ts
+++ b/server/src/upstream.ts
@@ -270,7 +270,7 @@ export class RenderQueue {
const startedAt = Date.now();
const est = Math.max(5, track.duration * REALTIME_FACTOR);
await this.client.ensureProbed();
- const streaming = this.client.canStream;
+ const streaming = track.stream && this.client.canStream;
await this.library.update(id, { status: 'running', stage: streaming ? 'semantic' : 'rendering', progress: 0, eta: est, elapsed: 0, renderedSeconds: streaming ? 0 : null });
const rel = `${id}.${extFor(track.format)}`;
diff --git a/server/src/validate.ts b/server/src/validate.ts
index 7f403d5..1bd508e 100644
--- a/server/src/validate.ts
+++ b/server/src/validate.ts
@@ -38,5 +38,7 @@ export function normalizeGenerate(body: unknown): GenerateRequest {
const title = typeof b.title === 'string' ? b.title.trim().slice(0, 120) : '';
- return { title, prompt, lyrics, duration, seed, format, takes };
+ const stream = b.stream === true;
+
+ return { title, prompt, lyrics, duration, seed, format, takes, stream };
}
diff --git a/server/test/app.test.ts b/server/test/app.test.ts
index 355cb7d..2e1423b 100644
--- a/server/test/app.test.ts
+++ b/server/test/app.test.ts
@@ -227,7 +227,7 @@ describe('app', () => {
const { app, lib, tracksDir } = await setup({ stream: { windows: 4, secondsPerWindow: 0.1, windowMs: 40 } });
const h = await request(app).get('/api/health');
expect(h.body.capabilities).toEqual(['stream']);
- const res = await request(app).post('/api/generate').send({ prompt: 'x', duration: 10 });
+ const res = await request(app).post('/api/generate').send({ prompt: 'x', duration: 10, stream: true });
const id = res.body[0].id as string;
await until(() => lib.get(id)?.stage === 'semantic');
await until(() => (lib.get(id)?.renderedSeconds ?? 0) > 0);
@@ -245,9 +245,17 @@ describe('app', () => {
expect(fake!.requests.find((r) => r.path === '/v1/audio/speech')?.body).toMatchObject({ stream: true });
});
+ it('streaming is opt-in: without stream:true the blocking path is used even when advertised', async () => {
+ const { app, lib } = await setup({ stream: { windows: 2 } });
+ const res = await request(app).post('/api/generate').send({ prompt: 'x' });
+ await until(() => lib.get(res.body[0].id)?.status === 'done');
+ expect(fake!.requests.find((r) => r.path === '/v1/audio/speech')?.body).toMatchObject({ stream: false });
+ expect(lib.get(res.body[0].id)?.renderedSeconds).toBeNull();
+ });
+
it('never sends stream:true to servers that do not advertise it', async () => {
const { app, lib } = await setup({ loading: false });
- const res = await request(app).post('/api/generate').send({ prompt: 'x' });
+ const res = await request(app).post('/api/generate').send({ prompt: 'x', stream: true });
await until(() => lib.get(res.body[0].id)?.status === 'done');
expect(fake!.requests.find((r) => r.path === '/v1/audio/speech')?.body).toMatchObject({ stream: false });
expect(lib.get(res.body[0].id)?.renderedSeconds).toBeNull();
@@ -255,7 +263,7 @@ describe('app', () => {
it('cancel mid-stream aborts upstream and marks cancelled', async () => {
const { app, lib } = await setup({ stream: { windows: 50, windowMs: 40 } });
- const res = await request(app).post('/api/generate').send({ prompt: 'x' });
+ const res = await request(app).post('/api/generate').send({ prompt: 'x', stream: true });
const id = res.body[0].id as string;
await until(() => (lib.get(id)?.renderedSeconds ?? 0) > 0);
await request(app).delete(`/api/tracks/${id}`);
@@ -265,7 +273,7 @@ describe('app', () => {
it('audio route serves the partial WAV of a running track with a patched header and honours Range', async () => {
const { app, lib } = await setup({ stream: { windows: 40, secondsPerWindow: 0.1, windowMs: 40 } });
- const res = await request(app).post('/api/generate').send({ prompt: 'x' });
+ const res = await request(app).post('/api/generate').send({ prompt: 'x', stream: true });
const id = res.body[0].id as string;
await until(() => (lib.get(id)?.renderedSeconds ?? 0) >= 0.2);
const bin = (r: request.Response, cb: (err: Error | null, body: Buffer) => void) => { const c: Buffer[] = []; r.on('data', (d: Buffer) => c.push(d)); r.on('end', () => cb(null, Buffer.concat(c))); };
diff --git a/server/test/validate.test.ts b/server/test/validate.test.ts
index bb59e4b..27a5749 100644
--- a/server/test/validate.test.ts
+++ b/server/test/validate.test.ts
@@ -16,6 +16,9 @@ describe('normalizeGenerate', () => {
expect(normalizeGenerate({ prompt: 'x' }).duration).toBe(60);
expect(normalizeGenerate({ prompt: 'x', takes: 0 }).takes).toBe(1);
expect(normalizeGenerate({ prompt: 'x', takes: 9 }).takes).toBe(4);
+ expect(normalizeGenerate({ prompt: 'x' }).stream).toBe(false);
+ expect(normalizeGenerate({ prompt: 'x', stream: 'yes' }).stream).toBe(false);
+ expect(normalizeGenerate({ prompt: 'x', stream: true }).stream).toBe(true);
});
it('validates seed', () => {
expect(() => normalizeGenerate({ prompt: 'x', seed: 1.5 })).toThrow(/seed/);
diff --git a/web/src/App.tsx b/web/src/App.tsx
index 5ab3ff9..df2a727 100644
--- a/web/src/App.tsx
+++ b/web/src/App.tsx
@@ -71,7 +71,7 @@ export default function App() {
const reuse = (t: Track) => { setForm(formFromTrack(t)); setView('create'); };
const retry = (t: Track) => {
- void submit({ title: t.title, prompt: t.prompt, lyrics: t.lyrics, duration: t.duration, seed: t.seed, format: t.format, takes: 1 }).catch((e) => alert((e as Error).message));
+ void submit({ title: t.title, prompt: t.prompt, lyrics: t.lyrics, duration: t.duration, seed: t.seed, format: t.format, takes: 1, stream: t.stream }).catch((e) => alert((e as Error).message));
};
const feed = (
diff --git a/web/src/components/CreatePanel.tsx b/web/src/components/CreatePanel.tsx
index de648d0..c258d0f 100644
--- a/web/src/components/CreatePanel.tsx
+++ b/web/src/components/CreatePanel.tsx
@@ -29,10 +29,12 @@ export interface FormState {
takes: number;
seed: string;
format: string;
+ /** stream live progress + audio while rendering (needs a server that advertises it) */
+ stream: boolean;
}
export const DEFAULT_FORM: FormState = {
- mode: 'simple', title: '', prompt: TEMPLATE_PROMPT, lyrics: TEMPLATE_LYRICS, instrumental: false, duration: 60, takes: 1, seed: '', format: 'wav',
+ mode: 'simple', title: '', prompt: TEMPLATE_PROMPT, lyrics: TEMPLATE_LYRICS, instrumental: false, duration: 60, takes: 1, seed: '', format: 'wav', stream: false,
};
export function formFromTrack(t: Track): FormState {
@@ -46,6 +48,7 @@ export function formFromTrack(t: Track): FormState {
takes: 1,
seed: t.seed === null ? '' : String(t.seed),
format: t.format,
+ stream: t.stream,
};
}
@@ -66,6 +69,7 @@ export function CreatePanel({ health, form, onFormChange, onSubmit }: Props) {
const online = !!health?.upstreamReachable;
const loading = online && !health!.ready;
const canSubmit = online && !loading && form.prompt.trim().length > 0 && !submitting;
+ const canStream = !!health?.capabilities?.includes('stream');
const estMin = useMemo(() => Math.round((form.duration * 3 * form.takes) / 60 * 10) / 10, [form.duration, form.takes]);
const submit = async () => {
@@ -82,6 +86,7 @@ export function CreatePanel({ health, form, onFormChange, onSubmit }: Props) {
seed,
format: form.format,
takes: form.takes,
+ stream: form.stream && canStream,
});
} catch (err) {
setError((err as Error).message);
@@ -202,6 +207,13 @@ export function CreatePanel({ health, form, onFormChange, onSubmit }: Props) {
{FORMAT_OPTIONS.map((f) => <option key={f.value} value={f.value} disabled={f.disabled}>{f.label}</option>)}
</select>
</div>
+ <label className={`col-span-2 flex items-start gap-2 text-xs ${canStream ? 'text-zinc-300 cursor-pointer' : 'text-zinc-500'}`} title={canStream ? undefined : 'This server does not advertise streaming (stock sgl-omni); progress will be estimated'}>
+ <input type="checkbox" className="mt-0.5 accent-accent" checked={form.stream && canStream} disabled={!canStream} onChange={(e) => set('stream', e.target.checked)} />
+ <span>
+ Stream while rendering
+ <span className="block text-[10px] text-zinc-500">Live progress and play-before-finished{canStream ? '' : ' — not offered by this server'}</span>
+ </span>
+ </label>
</div>
)}
</div>
diff --git a/web/src/components/Player.tsx b/web/src/components/Player.tsx
index 9039819..8023eb7 100644
--- a/web/src/components/Player.tsx
+++ b/web/src/components/Player.tsx
@@ -25,6 +25,9 @@ export function Player({ track, playing, onPlayingChange, onPrev, onNext, onEnde
const loadedSrc = useRef('');
const pendingSeek = useRef<number | null>(null);
+ // a play() cut short by our own src swap rejects with AbortError — expected, not a playback problem
+ const reportPlayError = (e: Error) => { if (e.name !== 'AbortError') setErr(e.message); };
+
const live = track?.status === 'running';
const rendered = track?.renderedSeconds ?? 0;
const total = track ? (live ? track.duration : dur || track.duration) : 0;
@@ -46,6 +49,13 @@ export function Player({ track, playing, onPlayingChange, onPrev, onNext, onEnde
return;
}
if (loadedSrc.current === src) return;
+ // Render finished while we were starved at the end of the data: the whole track has been heard.
+ if (sameTrack && !live && starvedRef.current && el.ended) {
+ loadedSrc.current = src;
+ starvedRef.current = false; setStarved(false);
+ onEnded();
+ return;
+ }
const nearEnd = el.duration > 0 && el.duration - el.currentTime < 2;
// Keep playing what we have unless we're about to run dry; a reload costs a small gap.
if (sameTrack && live && playing && !starved && !nearEnd) return;
@@ -58,14 +68,14 @@ export function Player({ track, playing, onPlayingChange, onPrev, onNext, onEnde
starvedRef.current = false; setStarved(false);
el.src = src;
el.load();
- if (resume) el.play().catch((e) => setErr(e.message));
+ if (resume) el.play().catch(reportPlayError);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [src, live, playing, starved]);
useEffect(() => {
const el = audio.current;
if (!el || !track) return;
- if (playing) { if (!starvedRef.current) el.play().catch((e) => setErr(e.message)); }
+ if (playing) { if (!starvedRef.current) el.play().catch(reportPlayError); }
else { el.pause(); starvedRef.current = false; setStarved(false); } // a manual pause also disarms auto-resume
}, [playing, track]);
@@ -105,7 +115,12 @@ export function Player({ track, playing, onPlayingChange, onPrev, onNext, onEnde
onLoadedMetadata={(e) => { if (pendingSeek.current !== null) { e.currentTarget.currentTime = pendingSeek.current; pendingSeek.current = null; } }}
onEnded={handleEnded}
onPlay={() => onPlayingChange(true)}
- onPause={() => { if (!starvedRef.current) onPlayingChange(false); }}
+ onPause={(e) => {
+ // browsers fire `pause` before `ended`; treat running out of live data as starvation, not a user pause
+ const el = e.currentTarget;
+ if (live && (el.ended || (el.duration > 0 && el.duration - el.currentTime < 0.05))) { starvedRef.current = true; setStarved(true); return; }
+ if (!starvedRef.current) onPlayingChange(false);
+ }}
onError={() => setErr('playback error')}
/>
<div className="flex items-center gap-3 w-36 md:w-64 min-w-0">
diff --git a/web/src/components/TrackCard.tsx b/web/src/components/TrackCard.tsx
index 40ade24..e5a54ad 100644
--- a/web/src/components/TrackCard.tsx
+++ b/web/src/components/TrackCard.tsx
@@ -68,6 +68,7 @@ export function TrackCard({ track: t, groupSize, active, playing, onPlay, onDele
<div className="mt-2 flex items-center gap-2 text-[11px] text-zinc-500 tabular-nums">
<span>{fmtTime(t.duration)}</span>
{t.seed !== null && (<><span>·</span><span className="font-mono">seed {t.seed}</span></>)}
+ {done && typeof t.elapsed === 'number' && t.elapsed > 0 && (<><span>·</span><span title="render time">rendered in {fmtTime(t.elapsed)}</span></>)}
<span>·</span>
<span>{fmtAgo(t.createdAt)}</span>
{t.lyrics !== '[Instrumental]' && (
diff --git a/web/src/types.ts b/web/src/types.ts
index f0e5668..1216ffb 100644
--- a/web/src/types.ts
+++ b/web/src/types.ts
@@ -16,6 +16,8 @@ export interface Track {
stage: string;
eta: number | null;
elapsed?: number | null;
+ /** opt-in per track: stream live progress + audio when the server supports it */
+ stream: boolean;
/** seconds of audio on disk while a streamed render is running; null when the server can't stream */
renderedSeconds: number | null;
error: string | null;
@@ -44,6 +46,7 @@ export interface GenerateInput {
seed: number | null;
format: string;
takes: number;
+ stream: boolean;
}
export interface Template {