Skip to content

Studio: add the Separate audio workflow with a synced stem mixer - #12610

Merged
danielhanchen merged 149 commits into
unslothai:mainfrom
Etherll:feat/studio-audio-separate
Oct 4, 2026
Merged

danielhanchen merged 149 commits into
unslothai:mainfrom
Etherll:feat/studio-audio-separate

Conversation

@Etherll

@Etherll Etherll commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Studio: add the Separate audio workflow with a synced stem mixer

Stacked on #12602. Only the commits after ce9807f are new in this PR.

Summary

HTDemucs, HTDemucs 6-stem, BS-RoFormer and Mel-Band RoFormer GGUFs were refused on load as "not supported in Studio yet". They now load into the main slot as task sep, and Audio gets a Separate page: pick a track (upload, record or history), press Generate, and get one waveform per stem in a mixer with solo, mute and volume on a shared WebAudio clock. Like Speak and Music, loading a separation model replaces the model in the main slot, and the page says so before you load one.

Backend (7c8b49e)

  • /audio/run accepts workflow: "separate" with inputs.source. text is now optional on AudioRunRequest and still required for clone and speak via a model validator. The route resolves the track in the caller's account and prepares a 44.1 kHz copy, since the runtime rejects any other rate. Tracks over 10 minutes (after trim) get a 400 that names the length, for example "10:01".
  • audio.cpp returns every stem as base64 in one JSON body (about 42 MB per stem for a three-minute track). audio_cpp_outputs.py streams the response to a staging file and decodes each stem straight to disk, so the worker hands back file paths, not bytes.
  • Stems are saved to history as one group (role = stem id, shared group_id), all or none.
  • num_overlap (1 to 8) is accepted only for the RoFormer families. It is a load-time option, so the audio.cpp server restarts only when the value changes. Other options on a separation model return 400.
  • Separation models are not offered as voices in /v1/models, and /v1/audio/speech and /audio/generate refuse them with a 400 that points at Separate.

Frontend (cf30b0c)

  • New Separate tab and page (separate-page.tsx, use-separate-generation.ts, separate-policy.ts). The rail shows the stems the loaded model will produce. BS-RoFormer and Mel-Band RoFormer get an Overlap switch that says when a change reloads the model, and the footer shows a time estimate and the reload before the run.
  • Stem mixer (stem-mixer.tsx, use-stem-transport.ts, use-stem-sources.ts): per-stem download, Download all as a zip, and Send to Clone (as the reference) or Send to Transcribe.
  • History shows a separation as one row; pin, archive and delete act on all of its stems. The model picker on Separate lists only separation models, and a separation model loaded on another page shows a notice that links to Separate.
  • AudioSourceInput takes a usesFirstSeconds prop so Separate does not show "Uses the first 30 s".
  • Waveform peaks are decoded from the fetched Blob. fetch(blob:) was blocked by the CSP connect-src, which left the stem waveforms flat.

The truncated workflow tabs visible on this branch are fixed in #12600, which replaces the pill tabs with a title menu.

Testing

Automated, on cf30b0c:

  • Backend: 1095 passed, 3 skipped (baseline audio suite plus new test_audio_run_route.py, test_audio_cpp_separation.py, test_audio_cpp_outputs.py, gallery and model tests). The baseline at ce9807f was 956 passed, 3 skipped. ruff clean, repo formatter is a no-op on changed Python files.
  • Frontend: npm test 10106/10106, typecheck 0 errors, i18n check 0, build ok, biome reports no new errors against the base. New tests: audio-separate.test.ts, audio-stem-mixer-state.test.ts, audio-stem-mixer-source.test.ts.

Live smoke against a local install (install.sh --local, runtime on one GPU), 21/21 checks passed:

  • Load + /audio/run for the 4 separation models went from 0/4 on the base (refused at load) to 4/4 on this branch, with the expected stem ids. A 48 kHz upload came back as 44.1 kHz stereo stems. Reconstruction SNR (sum of stems vs input): HTDemucs 31.6 dB, 6-stem 25.0 dB, BS-RoFormer 92.6 dB, Mel-Band 87.1 dB. Mel-Band stems are vocals and instrumental.
  • On a 180 s track: 6-stem 9.7 s; BS-RoFormer default 11.6 s, overlap 1 5.3 s with a restart then 3.7 s without one, back to default 12.9 s with a restart.
  • Rejected with 400: a text field on separate, no source, options on HTDemucs, a 601 s track (a trimmed 601 s track runs), a Kokoro model loaded, and /audio/generate on a separation model. /v1/models lists no separation model as a voice.
  • Cancelling mid-run leaves no staging file and the next run succeeds. 50 separation history sidecars contain no absolute paths.
  • Memory during a 6-stem 180 s run: the Studio worker grew 9.8 MB anonymous and 242 MB file-backed (the mmap of the streamed response). The audio.cpp server process itself grew about 1.6 GB.

UI pass with Playwright scenes and a separate reviewer. Fixed from that review:

  • Flat stem waveforms (the CSP blob: fetch above).
  • "Uses the first 30 s" hint removed on Separate.
  • Spacing of the time estimate in the footer.
  • A pending card with the track and model shows while a run is in progress.
  • Pressed Solo and Mute use bg-foreground, and silent rows drop to 35% opacity.
  • The newest result is pinned to the top.
  • Panel sliders use a neutral fill.
  • One completion announcement for screen readers. The mixer only announces "Loading stems...".
  • Stem chips in the rail are a plain text list.
  • The mixer spans the full output width.

Checked in the UI: Send to Clone sets the clip reference to "music_180s_44k - Vocals", Send to Transcribe without a speech-to-text model loaded shows a toast, and deleting a separation group removes all of its stems (88 to 86 history clips).

Known gaps, not addressed here:

  • A sub-second run (about 0.5 s) never shows the running footer.
  • The runtime-error state could not be triggered from the UI. An unloaded model shows the status blocker first.
  • Long-file source waveform rendering comes from the shared AudioSourceInput in Studio: add the Clone page, audio inputs and saved voices #12602, and the recommended-model link copy follows the pattern from that PR.
  • Stop uses the destructive style from the shared footer.
  • The picker label reads "Source separation- GGUF" (shared picker formatting).
  • History rows show no time, so two runs of the same track look alike.
  • Playback sync was checked by the shared position advancing while all stems play; per-stem drift was not measured, because the mixer's audio elements are not in the DOM.

UX

  • Fast first result: the empty and blocked states offer one-click HTDemucs and BS-RoFormer picks; the Separate picker lists only separation models. There is no text field, so no example chips.
  • No dead ends: every blocked Generate says why under the button with the fix (no model, wrong model, no track, upload in progress, expired upload, over 10 minutes). Speak, Clone and Music say when the loaded model separates and link to Separate.
  • Never lose work: the picked track and the Overlap value persist across page switches and reloads (Zustand, same tool-value store as Clone).
  • Honest progress: phases read "Preparing the track", "Separating" (or "Reloading the model with the new overlap, then separating") and "Saving stems", with elapsed time and Stop. The footer gives an estimate and the reload notice before the run, and the main-slot replacement is stated before loading.
  • Results first: the new separation is selected and pinned to the top of the output, focus moves to Play, and nothing autoplays. History rows show track, model, stem count and length.
  • Input in one move: the shared AudioSourceInput (drop, pick, record, from history) shows duration and waveform as soon as a file is picked.
  • Keyboard: Mod+Enter runs Separate from anywhere on the page. With the mixer or a waveform focused, Space or K plays and pauses and the arrows seek 5 s. Solo and Mute are Tab-reachable aria-pressed buttons. Completion and errors are announced.
  • Calm density: no Advanced section (separation models take no request options); Overlap shows only for RoFormers; labels are plain ("Track", "Outputs", "Overlap (slower, cleaner)").
  • Actionable errors: runtime refusals come through with their reason ("The audio runtime could not separate the track: ..."), plus "returned no stems", the expiry and the length cap, each with a next step.
  • Layout integrity: checked at the default rail, stacked below 50rem, UI size 12 and 20, light and dark, with reduced motion on for every scene.

Before / after

BEFORE is the parent PR head (#12602 at ca6a9bd), AFTER is this PR (426392c); this is not the PR's own merge base, since the Audio workspace this page lives in comes from the parent PRs. Both are fresh install.sh --local installs on one B200. On BEFORE, loading HTDemucs-GGUF returns 400 "Source separation models are not supported in Studio yet." and there is no Separate page. On AFTER, HTDemucs-GGUF loads as audiocpp_sep, a 20 s track run through /audio/run comes back as vocals, drums, bass and other, and the Separate page shows them in the stem mixer with the run in history.

Audio > Separate, before and after

Etherll and others added 8 commits October 2, 2026 23:38
Map each audio.cpp family's existing task to the Audio workflow it serves
(speak, music, transcribe) and report it as audio_workflows on inference
status and cached-model rows. Gallery clips record their workflow, older
clips infer it from audio_type, and DELETE /audio/gallery can scope a clear
to one workflow.

Fix the spec-task fallback stopping at a 'clon' token, so a clone+music or
clone+asr spec is no longer refused as clone-only. Only offer a fallback
family the installed runtime knows (its model_specs, or the pinned tag's
spec list), and name unsupported task tokens in plain words.

Pass the audio runtime's own error text, sanitized, to /audio/generate,
/v1/audio/speech and transcription instead of a generic internal error.
The 3,600-line Audio page becomes a thin host over hooks (model slot, STT
sidecar, transcription, gallery, generation, handoff) and per-workflow
pages, with the moved code unchanged. A Zustand workspace store holds the
current workflow; only the page commits it, the sidebar and deep links ask.

- Sidebar: Images' workflow list is generalised; a pinned Audio row lists
  its workflows inline, and the More flyout gets an Audio submenu. Nav
  defaults are unchanged.
- Handoffs: ?workflow= and ?task= (text-to-audio opens Music), Library
  clips open on their own page, the chat picker passes the workflow.
- Each page lists only models for its task, keeps its own history and
  drafts, and tours its own controls. Clear all clears only that page.
- Today's model-specific fields move into a tool-panel registry unchanged.
- Generate says why it is off and offers the fix, runs from Mod+Enter,
  shows elapsed time, keeps a failed run's reason, and focuses the new clip.

The source-shape tests that read audio-page.tsx now read the split files,
with their assertions unchanged.
POST /api/inference/audio/inputs streams an upload to disk, decodes it with
PyAV and keeps it per account for a day. /audio/voices stores saved voices.
/audio/run clones a voice from an upload, a history clip or a saved voice:
the route resolves ids to account-scoped 24 kHz mono files and hands the
worker paths, never bytes or a path the client chose.

Clone-only audio.cpp families (Qwen3-TTS Base, Chatterbox, CosyVoice3,
IndexTTS2/2.5, FireRedTTS3, FireRedAudio, Vevo2, Confucius4, MioTTS) list on
Clone instead of Speak, with the server task the spike found loads (clon for
Chatterbox, Echo-TTS, Confucius4 and FireRedTTS3 Base). MioTTS downloads and
loads MioCodec beside it. Maya1 needs a voice description, and VibeVoice text
without a speaker label is sent as Speaker 1.
Clone joins Speak, Music and Transcribe. Its rail takes a reference by
upload, recording, history clip or saved voice, drawn with a waveform as
soon as it is picked, then "What's said in the clip" with a Transcribe
button, the text, language and the model's tools: Timbre only (Qwen3 Base),
Emotion (IndexTTS2), Expressiveness (Chatterbox), Mode (CosyVoice3) and
Speed and dialect (F5). Save voice keeps a reference for later; Speak can use
a saved voice on models that both speak and clone.

Tool panels now validate and shape the request on Speak and Music too, a page
shows its last model as not loaded, and Clone offers recommended models in
one click.
HTDemucs, HTDemucs 6-stem, BS-RoFormer and Mel-Band RoFormer were refused as
"not supported in Studio yet". They now load into the main slot as task sep
and run on the Separate workflow: /audio/run resolves the track in the
caller's account, prepares a 44.1 kHz copy (the runtime rejects any other
rate), and the worker hands back stem files, never bytes.

audio.cpp answers with every stem as base64 in one JSON body (about 42 MB per
stem for a three-minute track), so the response streams to a staging file and
each stem is decoded straight to disk. Stems are saved to history as one group
(role = stem id, shared group_id), all or none. The RoFormer overlap is a load
time option, so the server restarts only when it changes. Separation models
stay off /v1/audio/speech and /audio/generate, which point at Separate.
Audio gets a Separate workflow: pick a track (upload, record or from history;
it is converted to 44.1 kHz), see the stems the loaded model will make, and
press Generate. BS-RoFormer and Mel-Band RoFormer get an Overlap switch that
says when changing it reloads the model, and the footer shows an estimate and
the reload before the run.

The result is a stem mixer: one waveform per stem, solo, mute and volume, all
stems on one WebAudio clock, per-stem download, Download all as a zip, and
Send to Clone (as the reference) or Transcribe. History lists a separation as
one row, and pin, archive and delete act on all of its stems. The picker on
Separate lists only separation models, and a loaded separation model on
another page says so and offers Separate.
@Etherll
Etherll requested a review from danielhanchen as a code owner October 3, 2026 09:46
@danielhanchen

Copy link
Copy Markdown
Member

The (Python 3.13, rest) red is the same one as #12602's, carried in with its audio routes (main does not have them): tests/multi_account/test_alice_bob_matrix.py::test_object_route_factory_completeness lists the per-object /audio/inputs/{input_id} and /audio/voices/{voice_id} routes as missing from the per-account object route matrix. Adding them to the matrix in #12602 and rebasing onto it should clear it here too. The red Chat UI Tests is the Windows lane's shell exiting with code 3840 mid-run with no failing step printed, the same runner death seen on #12511; a re-run of that job should clear it.

@danielhanchen danielhanchen self-assigned this Oct 3, 2026
…model memory

WorkflowBinding, the status audio_workflows field and lastModelByWorkflow had
no reader. The tool panel registry rendered one instruction field through a
generic framework whose request and validation hooks were never called; the
page now renders that field directly from instructionsFieldKind.
danielhanchen and others added 13 commits October 3, 2026 07:22
The selected clip is a card with its model and age, a waveform player and
the clip menu, which gains Send to. A run in progress shows a pending card
with its phase, elapsed time and Stop. History rows add the model and age.
An unlisted generated clip now stays on the page that made it instead of
showing on the other TTS page and blocking its history. Switching between
Speak and Music passes the same busy gate as a mode switch, so a load in
flight no longer pulls the page back when it finishes.
Brings in unslothai#12600's pre-commit fixes, comment trims and the move of the
instruction fields to components/instructions-fields.tsx.

unslothai#12600 dropped the tool panel registry, WorkflowBinding, the status
audio_workflows field and lastModelByWorkflow because nothing read them.
The Clone page reads all of them, so they come back here with their first
consumer. The registry renders the instruction fields from their new path,
which leaves instructionsFieldKind without a caller; it goes, and the
tool panel tests keep the copy assertions its test made.
Drop the unused trim support, dead response fields and helpers, merge the two PyAV
decoders into one transcode, share the option matcher between the route and the
backend, fold duplicated tests into tables and cut narration comments.
…y speaks=False family, and count only kept inputs toward the byte cap
# Conflicts:
#	studio/frontend/src/features/audio/picker-filter.ts
# Conflicts:
#	studio/frontend/src/features/audio/picker-filter.ts
# Conflicts:
#	studio/frontend/src/features/audio/audio-page.tsx
#	studio/frontend/src/features/audio/components/waveform.tsx
# Conflicts:
#	studio/backend/core/inference/audio_cpp_backend.py
#	studio/backend/core/inference/audio_cpp_models.py
#	studio/backend/core/inference/audio_inputs.py
#	studio/backend/core/inference/orchestrator.py
#	studio/backend/models/inference.py
#	studio/backend/routes/inference.py
#	studio/backend/tests/test_audio_run_route.py
#	studio/frontend/src/features/audio/audio-cpp-catalog.ts
#	studio/frontend/src/features/audio/audio-page.tsx
#	studio/frontend/src/features/audio/audio-run-request.ts
#	studio/frontend/src/features/audio/components/waveform.tsx
#	studio/frontend/src/features/audio/hooks/use-clone-generation.ts
#	studio/frontend/src/features/audio/tools/registry.tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants