No description
  • Python 76.6%
  • HTML 14.4%
  • Shell 9%
Find a file
OGHermes 6c933733fa
fix(station): populate history when tracks advance or genre changes
History view was always empty in production. Two bugs:

1. now_playing() auto-advances the playhead when the current track
   elapses past its duration, but it never recorded the just-finished
   track to history. _record_history() was only called from skip()
   (manual) and from _gc_old_files() (which only runs from the render
   path). With ACE-Step renders taking ~5.5 min each, _gc_old_files
   could run rarely, leaving long stretches with empty history.

2. set_genre() cleared self._ready and self._inflight without
   recording the track the listener was actually listening to. So
   any time the listener queued a new genre, the previous track was
   lost from history.

Fixes:
- now_playing() now records the just-finished track to history in
  the same while loop that bumps the playhead.
- set_genre() now records the playhead's track to history before
  clearing the queue.

Also: _record_history has a guard against double-recording (checks
rid uniqueness), so the manual skip path and the new auto-advance
path can't accidentally double-add the same track.

Verified by code inspection: the new code path runs every time
now_playing() sees an elapsed track, so history fills as tracks
play.
2026-10-08 07:31:56 -04:00
docs feat(proc_gen): procedural generator — token→params, per-seed variation 2026-10-03 13:35:29 -04:00
probe Phase 2B-2 verified end-to-end: real music generation works 2026-10-02 21:40:42 -04:00
radio fix(station): populate history when tracks advance or genre changes 2026-10-08 07:31:56 -04:00
scripts Phase 2B-2 final wiring: ffmpeg in container, smoke test, weight script fix 2026-10-02 21:06:39 -04:00
.dockerignore Add Dockerfile.radio + .dockerignore 2026-10-02 19:45:59 -04:00
.gitignore Phase 2B-2 verified end-to-end: real music generation works 2026-10-02 21:40:42 -04:00
compose.yml fix(ace-step): tune for RDNA3.5 + ship as default generator 2026-10-03 22:51:26 -04:00
Dockerfile.ace-step Phase 2B-2 final wiring: ffmpeg in container, smoke test, weight script fix 2026-10-02 21:06:39 -04:00
Dockerfile.radio Fix container: git install, .git bind mount, cache-dir entrypoint 2026-10-02 19:52:22 -04:00
README.md fix(ace-step): tune for RDNA3.5 + ship as default generator 2026-10-03 22:51:26 -04:00

OG-Radio

A personal internet radio station that picks a genre and plays it forever — every track freshly generated, with a short melodic bridge between tracks so the listener never hears a hard cut. Served over Tailscale HTTPS so you can hit it from your phone.

Status: Phase 3 (station mode + procedural generation, real music plays). The procedural generator (radio/proc_gen.py) renders every track from scratch via ffmpeg lavfi — bass sine, lead sine, noise pad → LFO tremolo → amix → reverb → bandpass. Per-seed variation means every track sounds different even on the same genre. See docs/phase-0-scope.md for the full plan.

What it does

  • You open https://ogflow.taile970c7.ts.net:8450/radio/ in any browser (iOS Safari, Chrome, desktop — all tested).
  • You type a genre (e.g. "90s boom bap", "dark synthwave", "smooth jazz fusion") and click Queue — or pick a chip from the genre row.
  • The server picks up the genre, then auto-plays that genre forever — it pre-renders 3-4 tracks ahead of the playhead, then auto-advances every ~47 s. Each new track is a fresh procedural variation (different per-seed bass/lead/pad notes, different LFO rates, different filter cutoffs).
  • A ~2 s melodic bridge is prepended to every track (radio/transition.py) so the transition from one variation to the next sounds intentional, not a hard cut.
  • Play / Pause / Skip / Volume are wired and functional. Volume drives both audio.volume and audio.muted; iOS Safari ignores the in-page slider, so a small helper line tells you to use the device volume buttons.

How to use

  1. Open https://ogflow.taile970c7.ts.net:8450/radio/ in your browser.
  2. Type a genre in the input box (or click one of the chip buttons).
  3. Hit Queue (or Enter). The genre stays set until you change it.
  4. Click Play. The current variation starts; the station keeps queuing the next variation on the same genre.
  5. Skip jumps to the next variation.
  6. Volume slider works on desktop. On iOS Safari it has no effect — use the device volume buttons (the page tells you so).

You don't need to re-queue after each track. The station owns the genre and keeps it.

Architecture

radio/
  server.py            -- stdlib HTTP server. /radio/ HTML, /radio/api/* JSON,
                          /radio/api/track/<rid> per-track MP3 with Range,
                          /radio/stream chunked (legacy).
  station.py           -- The Station. Owns the genre, runs a background
                          worker that keeps a rolling cache of 3-4 future
                          tracks. Auto-advances the playhead once the
                          current track's elapsed > duration.
  queue.py             -- Thin compat wrapper around Station. Keeps the
                          old Queue API alive for callers that haven't
                          migrated; Phase 3 always uses Station under
                          the hood.
  proc_gen.py          -- Procedural generator. Token→BPM/root/noise/
                          reverb tables; per-seed pick of bass/lead/pad
                          Hz, LFO rates, filter cutoffs. ffmpeg lavfi
                          pipeline renders the MP3.
  transition.py        -- Short ~2s melodic bridge between tracks.
                          Three sine notes stepping prev_root → midpoint
                          → next_root + noise crash + tail reverb.
  player.html          -- The listener page. Vanilla HTML/JS, no build
                          step. Polls /api/now-playing every 2 s and
                          loads the next rid via /api/track/<rid>.
  run.sh               -- Starts the server (see How to run).
  tests/
    test_server.py     -- Smoke test (urllib, no pytest) + in-process
                          regression tests.
  entrypoint.sh        -- Podman entrypoint: chmod the cache dir, then
                          exec the python server.
  ace_step_client.py    -- (Phase 2B-2, currently unused by server.py.)
                          Real ACE-Step v1.5 generator with its own
                          caption bank. Kept around so Phase 4 can wire
                          the real model back in.

The data flow for one track:

[station worker thread]
    ↓ render_one(rid, genre, seed)
[proc_gen.generate()]    → ~45 s procedural MP3
[transition.render()]   → ~2 s bridge MP3
[_concat_mp3()]         → final MP3 with bridge prepended
[atomic write .part → .mp3 in .cache/]
    ↓
[Station._ready[playhead]] -- current track
    ↓
[GET /radio/api/track/<rid>] -- Content-Length, Accept-Ranges
    ↓
[<audio> element on iOS Safari / desktop browser]

How to run

# from the repo root
./radio/run.sh
# prints the local URL and the Tailscale URL

Or directly:

python3 -m radio.server --port 5199

Then visit http://127.0.0.1:5199/radio/ locally or https://ogflow.taile970c7.ts.net:8450/radio/ over Tailscale.

To pin the initial genre:

OG_RADIO_GENRE="synthwave" python3 -m radio.server --port 5199

Requirements: Python 3.14 (any 3.10+ will likely work), ffmpeg on $PATH. No pip packages — the server is stdlib-only. ffmpeg is the only system dep.

API surface

Endpoint Method Returns
/radio/ GET The HTML player page
/radio/api/health GET {ok, version, queued, inflight, current, genre, head_sha}
/radio/api/now-playing GET {rid, genre, title, elapsed_s, duration_s, next_genre}
/radio/api/genre GET {genre} (the station's currently-set genre; "" if unset)
/radio/api/queue?genre=X GET {ok, queued: {rid, genre, title, duration_s}} — also sets the station's genre
/radio/api/skip GET The new now-playing dict (current track dropped, playhead stays)
/radio/api/track/<rid> GET audio/mpeg, single track, Content-Length + Accept-Ranges (iOS Safari-friendly)
/radio/stream GET audio/mpeg, chunked, walks the queue (legacy; iOS uses the per-track endpoint)

All JSON responses set Cache-Control: no-store, no-cache, must-revalidate, max-age=0 so iOS Safari never serves a stale page.

Acceptance criteria

From docs/phase-0-scope.md, Phase 0 scope:

  1. Visit https://ogflow.taile970c7.ts.net:8450/radio/ in iOS Safari — ✅ done. Page loads over Tailscale HTTPS.
  2. Genre input — ✅ done. Free-form text + one-click submit + 12 chip buttons.
  3. Control surface — ✅ done. Play / Pause / Skip / Volume all functional.
  4. Music plays — ✅ done. Procedural MP3 generation, not silence, not 1-second clips, not noise.
  5. Repo is the source of truth — ✅ done. README documents install + run + how it works.
  6. Discord cadence — posts are made in music-radio-design / music-radio-build-log / music-radio-status / music-radio-listener-links / music-radio-bugs as appropriate.

Verify it's working

# Server-side smoke test (the same one the build runs).
python3 -m radio.tests.test_server http://127.0.0.1:5199

# Tailscale URL probe.
curl -sI https://ogflow.taile970c7.ts.net:8450/radio/
# expect: HTTP/2 200, content-type: text/html, cache-control: no-store...

# Health JSON.
curl -s "https://ogflow.taile970c7.ts.net:8450/radio/api/health"
# expect: {"ok": true, "version": "station-3", "queued": N, "current": "...", ...}

# Queue a genre (also sets the station's genre).
curl -s "http://127.0.0.1:5199/radio/api/queue?genre=synthwave"
# expect: {"ok": true, "queued": {"rid": ..., "genre": "synthwave", "title": "Synthwave #1 — 100 BPM", ...}}

Troubleshooting

  • "iOS: use the device volume buttons — the in-page slider has no effect." That's expected. iOS Safari ignores <audio>.volume; the device volume buttons are the only control.
  • Container can't write to .cache/ (you see [station] write failed). The bind-mounted radio/.cache/ was probably created by a previous run as a different user. Fix on the host: chmod -R u+rwx radio/.cache/. The radio/entrypoint.sh rechmod's on container start, so this should self-heal after a podman compose restart radio.
  • No music plays, just silence. The first track takes ~5-10 s to render (proc_gen + transition). If queued is still 0 after 30 s, check that ffmpeg is installed and on $PATH. The smoke test python3 -m radio.tests.test_server will catch this.
  • Genre change doesn't show up. The Station re-renders the whole cache on set_genre. The first new-genre track appears in ~5-10 s; the player auto-advances to it on the next polling tick.
  • iOS Safari aborts playback. The player uses waitForCanPlay() before audio.play() and serves each track via /radio/api/track/<rid> (Content-Length, no chunked transfer). If you've customized radio/player.html, make sure both are still in place — without them iOS rejects playback with AbortError.
  • Container log says "no track ready in 30s". ffmpeg is missing inside the container, or the cache dir is read-only. Check podman exec og-radio which ffmpeg.

Repo layout

docs/
  phase-0-scope.md    -- the locked plan, 4 phases, acceptance criteria
radio/
  __init__.py
  server.py           -- stdlib HTTP server
  station.py          -- The Station (owns genre, runs worker)
  queue.py            -- Thin compat wrapper around Station
  proc_gen.py         -- Procedural generator (ffmpeg lavfi)
  transition.py       -- ~2s bridge between tracks
  ace_step_client.py  -- Real ACE-Step v1.5 generator (default in production)
  player.html         -- The listener page
  run.sh              -- start the server
  entrypoint.sh       -- container entrypoint
  tests/
    test_server.py    -- smoke test + in-process regression tests
scripts/
.gitignore
README.md

Generators: real vs procedural

Two generators ship in the box. The radio picks ACE-Step by default (set OG_RADIO_ACE_STEP= empty / unset in compose.yml to fall back to the proc_gen stub).

  • radio/ace_step_client.py — real music from ACE-Step v1.5. Used when OG_RADIO_ACE_STEP=1 and http://127.0.0.1:8001/health responds. Renders ~20-second clips at the host GPU's real-time factor. On the OG-Radio host's Radeon 8060S (RDNA3.5), the turbo path renders at ~16× real-time, so each 20-second clip takes ~5.5 minutes to generate. The listener queues a genre, then waits up to ~6 minutes for the first track; subsequent tracks are pre-cached in the rolling buffer (default 2 tracks × 20 s = 40 s ahead of the playhead) so transitions are gap-free once the cache fills.
  • radio/proc_gen.py — fast procedural fallback. Renders 60-second tracks in <1 s using ffmpeg lavfi (bass sine + lead sine + noise pad → amix → reverb). Sounds like a 16-bit synth, not real instruments — ffmpeg can't synthesize real instrument samples. Use this if you want gap-free station mode and don't mind chiptune textures.

A more realistic procedural generator (real instrument samples, proper drum kit, etc.) would need a small library of CC0 drum / bass / chord one-shots and an ffmpeg concat pipeline. That's a real follow-up project; not in this commit.

License

Code: MIT. Output audio: depends on the generation backend. Phase 3 output (ffmpeg lavfi tones) has no third-party license encumbrance.