Add real multi-song AI remix engine
New POST /remix + GET /remix/{job_id}: takes 1-5 uploaded songs plus a
natural-language prompt, runs it as a background job (RemixJob table
tracks status/stage as it progresses), and returns a download URL when
done. Pipeline:
1. Detect each song's BPM (librosa) and grab quick metadata via the
existing Shazam/AcoustID identify_audio.
2. Ask Gemini to produce a structured remix plan - it hears a real
~25s preview of each song (not just title/artist text) plus the
detected BPMs, and returns which stems to pull from which song,
at what gain/pitch, a shared target BPM, and a master effects
chain. This replaces the old ai_remix.py's approach of faking
"stem separation" with a sox highpass filter while literally
telling the AI it was using Demucs.
3. Actually run Demucs (real 4-stem separation: vocals/drums/bass/
other), cached on disk by file content hash so re-remixing the
same song never reprocesses it.
4. Time-stretch selected stems to the shared target BPM (librosa
phase vocoder), mix with per-song gain/pitch-shift, master with
a pedalboard compressor + reverb chain, tag and export via the
existing tag_and_convert_audio.
Removes the old /music/remix/batch and /music/remix/status mock stubs
in music.py (hardcoded fake job ids/progress) now that the real thing
exists at /remix.
This VPS's virtualized CPU exposes no SSE3/SSE4/AVX at all, which
makes PyTorch's default oneDNN backend fail ("could not create a
primitive") on Demucs's real-sized convolutions - a tiny toy conv
works fine, which is what makes this easy to miss in isolation.
torch.backends.mkldnn.enabled = False works around it. Also: Gemini
calls need this box's HTTP(S)_PROXY set to reach the network at all
(confirmed the already-running main branch's stax_backend.service has
the same gap and is likely silently failing on Gemini calls in
production right now - flagging separately, out of scope here).
numpy is pinned <2 / scipy pinned to 1.13.1: numpy>=2's default wheels
require the x86-64-v2 baseline and RuntimeError on import on this CPU.
Tested end-to-end against two synthetic multi-tone MP3s: single-song
"drop the vocals, slowed + reverb" and two-song "blend vocals of one
over the drums of the other" both produced correct, tagged, playable
MP3s (~75s for the two-song case, ~3s when stems were already cached).
Co-Authored-By:
Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BCxXmJVvDFJVHTUi4QgNzi
Showing
| ... | @@ -16,3 +16,15 @@ python-multipart>=0.0.9 | ... | @@ -16,3 +16,15 @@ python-multipart>=0.0.9 |
| pytest>=8.0.0 | pytest>=8.0.0 | ||
| pyrogram>=2.0.106 | pyrogram>=2.0.106 | ||
| tgcrypto>=1.2.5 | tgcrypto>=1.2.5 | ||
| # Remix engine. Install torch CPU-only *before* this file, this VPS has no GPU: | |||
| # pip install torch --index-url https://download.pytorch.org/whl/cpu | |||
| # Otherwise pip pulls the default CUDA wheel (multiple GB, useless here). | |||
| # numpy is pinned <2: this VPS's virtualized CPU exposes no SSE3/SSE4/AVX at all, | |||
| # and numpy>=2's default wheels require the x86-64-v2 baseline and segfault/RuntimeError | |||
| # on import here. 1.26.4 is what the rest of this project already runs on successfully. | |||
| numpy==1.26.4 | |||
| scipy==1.13.1 | |||
| demucs>=4.0.1 | |||
| librosa>=0.10.2 | |||
| soundfile>=0.12.1 |
src/api/routers/remix.py
0 → 100644
src/services/remix_engine.py
0 → 100644
Please
register
or
sign in
to comment