c445eb3e04
Drop class-by-class architecture listings that are derivable from the code; keep only constraints a model cannot infer (status.json coupling, header injection, read-only mount, shutdown deadline, dsnoop/ipc). Add webui.html to the file map. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
3.3 KiB
3.3 KiB
CLAUDE.md
Guidance for Claude Code when working in this repository.
Rules
- Always update
README.mdwhen user-facing behaviour changes (flags, endpoints, Docker setup, features), and commit it in the same commit as the code change. README is the external reference; CLAUDE.md documents internals. - Run
python -m pytest tests/after changingisr.py(tests cover the recorder only).
Files
| File | Purpose |
|---|---|
isr.py |
Recorder: streams (Icecast/HTTP) + ALSA soundcards, time-aligned file splits |
web.py |
Archive browser: HTTP server, file listing, RMS loudness analysis, cut/delete |
webui.html |
Single-page UI (HTML/CSS/JS), loaded by web.py at startup — must sit next to web.py and be copied in the Dockerfile |
config.ini |
Recording sources; copy from config.example.ini. [general] gives defaults, every other section is a source (type = stream or type = soundcard) |
asound.conf |
dsnoop device shared_mic so ISR and other ALSA apps can share a soundcard |
Commands
python isr.py [config.ini] # recorder; --list-devices to list ALSA inputs
python web.py # web UI on :8080 (--dir, --port, --threshold, --min-gap, --analyses-dir)
python -m pytest tests/ # test suite
docker compose up -d / down # web UI mapped to host port 8050
Dependencies: requests (streams), numpy + soundfile (FLAC output and FLAC/waveform analysis — both optional, code degrades gracefully).
Non-obvious internals
- Recorder/web coupling is one file:
RecorderManageratomically writesrecordings/status.jsonevery 2 s listing in-progress files; deleted on clean shutdown.web.pyreads it to show REC badges and to refuse analyse/cut/delete on active files. In-progress WAV/FLAC headers are unfinalized, so durations are not read for active files. - Stream splits: OGG/Opus/FLAC codec headers are extracted from the first ~16 KB of each connection and prepended to every split file so each file plays standalone. A new file is always opened on reconnect (gap in stream). MP3/AAC need no headers.
- Split timing: files split at clock-aligned boundaries (
get_next_split_time()), e.g.split_minutes = 60→ on the hour. - ALSA: capture spawns
arecordas a subprocess, raw PCM read in 100 ms chunks by a thread. Device spec resolution:default→ exacthw:X,Y→ partial name → fallback to any literal ALSA PCM name (soshared_micfrom asound.conf works without appearing inarecord -l). - Shutdown: SIGTERM is converted to KeyboardInterrupt in
main();RecorderManager.stop()joins all threads against a single shared 25 s deadline to stay inside Docker'sstop_grace_period: 30s. - Analysis cache: results stored as
<analyses-dir>/<file>.analysis.jsonkeyed by threshold+min_gap; orphans pruned at web startup. In Docker the recordings mount is read-only for the web container, so the cache uses a separate./analysesbind mount. - Path safety: every file parameter in
web.pygoes through_safe_path(), which resolves and verifies the path stays inside the recordings dir. - dsnoop in Docker: sharing the soundcard requires
asound.confon the host andipc: hostin docker-compose (dsnoop uses shared memory across the container boundary).