HUB
Sign inSign up

awkto/tempo-worker

By awkto

•Updated 7 months ago

Tempo worker — Demucs karaoke worker (CPU)

Image
0

4.0K

awkto/tempo-worker repository overview

⁠Tempo

Self-hosted karaoke / music player. Single user, runs on your own machine.

⁠Stack

  • Backend — FastAPI + SQLModel (SQLite) + ARQ workers + Redis
  • Audio — Demucs (htdemucs) for vocal removal, ffmpeg for transcode, mutagen for tags
  • Frontend — Vite + React + TypeScript + Tailwind, dual-source audio engine (SoundTouch worklet)
  • Deploy — Docker Compose, four services: api, worker, redis, web

⁠Quickstart

⁠Deploy (single container)
docker run -d --name tempo \
  -p 80:80 -v /srv/tempo-data:/data \
  --restart unless-stopped \
  awkto/tempo:latest

That's the whole stack — nginx + FastAPI + worker + redis — in one image. Mount any host directory at /data to persist the SQLite DB, generated karaoke stems, uploads, and cover art.

⁠Develop (split services with HMR)
git clone https://github.com/awkto/musicmod.git
cd musicmod
cp .env.example .env
docker compose up --build

docker-compose.yml runs the four services (api, worker, redis, web) separately so the Vite dev server can hot-reload frontend edits and the API can be iterated without rebuilding the all-in-one image.

When everything is up:

The data/ directory is bind-mounted and holds the SQLite DB, generated stems, uploads, download cache, and cover art. Back this directory up to keep your library + karaoke versions.

On first start the API auto-creates a demo local source named Local Music pointing at /data/tracks (i.e. ./data/tracks on the host). Drop audio files there and trigger a scan.

⁠Adding music

⁠Local folder

Drop files under ./data/tracks/ and trigger a scan:

curl -X POST http://localhost:8000/sources/1/scan

To wire up additional folders:

curl -X POST http://localhost:8000/sources \
  -H 'Content-Type: application/json' \
  -d '{"type":"local","name":"My Library","config":{"root_path":"/data/extra"}}'

(Mount the host path into both api and worker services first.)

⁠Upload (browser-friendly)

Use the upload dropzone on the Sources page, or call the API:

curl -X POST http://localhost:8000/sources \
  -H 'Content-Type: application/json' \
  -d '{"type":"upload","name":"Drops","config":{}}'
# returns id=N
curl -X POST http://localhost:8000/sources/N/upload -F [email protected]
curl -X POST http://localhost:8000/sources/N/scan

Files land under ./data/uploads/{source_id}/.

⁠Google Drive
  1. In Google Cloud Console, create OAuth credentials of type Web application. Add http://localhost:8000/sources/gdrive/callback as an authorised redirect URI.
  2. Download client_secret.json to ./data/gdrive/client_secret.json.
  3. Restart the stack.
  4. Create the source:
    curl -X POST http://localhost:8000/sources \
      -H 'Content-Type: application/json' \
      -d '{"type":"gdrive","name":"Drive","config":{"folder_id":"OPTIONAL"}}'
    
  5. Visit http://localhost:8000/sources/{id}/gdrive/authorize, follow the URL it returns, complete OAuth.
  6. POST /sources/{id}/scan.

Drive files are downloaded and cached under ./data/cache/{source_id}/ on first play.

⁠Karaoke generation

curl -X POST http://localhost:8000/tracks/42/karaoke
# returns { id: <job_id>, status: "queued", ... }
curl http://localhost:8000/jobs/<job_id>   # poll for progress

The worker runs Demucs (htdemucs, two-stem split) on the track and writes data/stems/{track_id}/karaoke.mp3 (320 kbps). Once done, GET /tracks/{id}/stream/karaoke returns the karaoke audio, and the in-app A/B toggle crossfades between original ↔ karaoke without a seek.

Demucs runs on CPU by default — fine, just slower (~30 s for a 4-min track on a modern CPU vs ~3 s on an RTX-class GPU).

To use a CUDA GPU on the same box as the rest of the stack, switch to the CUDA all-in-one image:

docker run -d --gpus all --name tempo \
  -p 80:80 -v /srv/tempo-data:/data \
  --restart unless-stopped \
  awkto/tempo:latest-cuda

Requires the NVIDIA Container Toolkit on the host. The image auto-detects CUDA at startup (TEMPO_DEMUCS_DEVICE=cuda is baked in).

⁠Remote GPU worker (run karaoke generation on another host)

If you want the UI to live on a small always-on host and the heavy Demucs workload on a LAN box that has a GPU, run the worker-only image pointed at the main container's Redis:

  1. On the main (API) host, expose Redis with a password. Start the all-in-one container with:

    docker run -d --name tempo \
      -p 80:80 -p 6379:6379 -v /srv/tempo-data:/data \
      -e TEMPO_REDIS_BIND=0.0.0.0:6379 \
      -e TEMPO_REDIS_PASSWORD=choose-a-long-random-string \
      awkto/tempo:latest
    

    The container refuses to start if TEMPO_REDIS_BIND is non-loopback without a password. Always firewall the port or run this over WireGuard/VPN.

  2. On the GPU host, run the CUDA worker and share the data directory via NFS/SMB/whatever:

    docker run -d --gpus all --name tempo-worker \
      -e TEMPO_REDIS_URL=redis://:[email protected]:6379/0 \
      -v /mnt/tempo-data:/data \
      awkto/tempo-worker:latest-cuda
    
  3. Verify the remote worker registered:

    curl http://tempo.lan/api/workers
    

Multiple workers (mix of CPU + GPU) can register against the same Redis; ARQ picks whichever is free for the next job.

⁠Backups

The only stateful directory is ./data/. To back up:

docker compose stop                  # quiesce writes
tar czf tempo-$(date +%F).tar.gz ./data
docker compose start

Restoring is the inverse — replace ./data/ and start the stack.

⁠Auth

There is none. Tempo is a single-user, self-hosted app meant to live on a private network or behind a VPN. If you need multi-user later, the natural slot is a FastAPI dependency on the routers in backend/app/routers/.

⁠Architecture notes

See CONTRIBUTING.md⁠ for the sources adapter contract and how to add a new source type.

⁠Releases

Pushing a v*.*.* tag triggers .github/workflows/docker-publish.yml, which:

  1. Builds four variants in parallel: all-in-one CPU/CUDA and worker-only CPU/CUDA.
  2. Pushes them to Docker Hub as awkto/tempo:{VERSION}[-cuda] and awkto/tempo-worker:{VERSION}[-cuda], plus :latest[-cuda] (:latest* skipped for prereleases — tags containing -).
  3. Updates the Docker Hub short description on each repo.
  4. Cuts a GitHub Release with pull/run instructions.

To cut a release:

git tag v0.2.0
git push origin v0.2.0

Required repo secrets: DOCKER_USERNAME, DOCKER_PASSWORD (Docker Hub access token).

⁠API reference

http://localhost:8000/docs for the live OpenAPI explorer. Highlights:

MethodPathNotes
GET/healthliveness
GET/tracksq, artist, album, sort, order, limit, offset
GET/tracks/{id}merged metadata (overrides over file tags)
PATCH/tracks/{id}/metadatastage overrides; pass null to clear
POST/tracks/{id}/metadata/commitwrite overrides into the file
POST/tracks/{id}/metadata/lookupMusicBrainz candidates
GET/tracks/{id}/stream/originalHTTP range, scrub-friendly
GET/tracks/{id}/stream/karaoke404 until generated
GET/tracks/{id}/coverextracted cover art
POST/tracks/{id}/karaokeenqueue Demucs job
GET/jobs, /jobs/{id}worker status (poll)
POST/tracks/rehashadmin backfill of content_hash
*/playlists, /playlists/{id}/tracks, /playlists/{id}/reorderfull CRUD + ordering
*/sourceslocal, upload, gdrive
GET/workerslive workers (heartbeat within 30 s)
Tag summary
Recent tags
Content type
Image
Digest
sha256:b352c2204…
Size
2.9 GB
Last updated
7 months ago
docker pull awkto/tempo-worker:latest