Listening (v0.4.0): the audio engine #4

Merged
mnovak merged 1 commits from feature/listening into main 2026-11-17 21:25:23 +01:00
Owner

Day 4 core (v0.4.0): the audio engine. Day page docs/04_listening.md in the app repo.

New crate liber-audio (reusable, no Liber types; pure, in the purity scan):

  • stretch: WSOLA, 40 ms Hann frames, 50% overlap, ±12 ms search on the mono mix applied to every channel; streaming, speed 0.5–3× changeable between blocks.
  • silence: pauses ≥ 300 ms shortened to 150 ms, streaming (the first 150 ms goes out, the rest is held until the pause proves long); a frame above −45 dBFS is never dropped; a map from output time back to the book's time.
  • boost: 80 Hz high-pass, +5 dB bell at 2.5 kHz, compressor (−24 dB, 3:1), soft limiter that never passes ±1.
  • player: chapters (tidy: sorted, bounded, ≤ 10,000), skips, previous/next chapter, sleep timer (minutes or end of chapter), Saver (every 900 ms with blocks ≤ 100 ms), a generic Queue.
  • container: sniffing by content; MP4 box walk (duration, Nero chpl, title; DRM: aax /aaxc brands, adrm, aabd, aavd, drms, drmi, enca), ID3v2 CHAP/TIT2, WAV duration, .cue; caps on boxes, depth, tag size, frames, chapters; nothing allocated from a claimed size.
  • decode: symphonia 0.5 (MPL-2.0; mp3, aac, isomp4, wav, pcm) behind caps (channels, rate, hours, consecutive errors); Read + Seek sources only.
  • speech: the read-aloud cache key (voice, voice file hash, speed, language, text, length-prefixed) and the timeline (sentence / paragraph / title pauses) for the highlight.

Mandatory tests (written with the code, all generated fixtures):

  1. tests/engine.rs (7): pitch 180.0 Hz → 180.1 Hz at 0.5×, 1.5×, 3×, duration within 3% (measured 1.2%, 2.0% off); stereo keeps its phase; trimming keeps every loud speech sample and shortens only long pauses (±40 ms); the trimmed→book time map; 2,000 random kills never more than 1 s behind; boost never clips and lifts presence; chapters, skips, sleep.
  2. tests/hostile.rs (7): lying chapter counts, a terabyte box, a box smaller than its header, 40-deep nesting, 250,000 boxes, a 200 MB ID3 claim, 30,000 CHAP frames, a frame larger than its tag, truncated WAV, junk under any name, an MP4 without audio — each refused or ended cleanly in under 2 s.
  3. DRM (same file): AAX brand, AAXC brand, adrm, aabd, enca → "This audiobook is DRM-protected, so Liber cannot play it."; a scan finds no decrypt path or crypto crate.
  4. tests/speech.rs (3): the highlight timeline across pauses; stretched audio stays within a frame; the cache key changes with voice, voice file or speed and nothing else.
    Workspace: 108 tests green; clippy 0; scripts/deps.mjs --check 115 crates, 0 not allowed.

Self-review

  • Symphonia 0.5 has no MP4 chapter support, hence our own chpl parser; the QuickTime chapter track is not read yet (Nero chpl is what most M4B tools write) — a gap noted in the day page. HE-AAC is not decoded by symphonia (no permissive decoder).
  • WSOLA quality at 3× on real speech is fine for audiobooks but not music; that is the use.
  • The DRM scan is a text check: it would miss a renamed crypto crate; it backs the design (no crypto dependency at all), it does not replace it.
Day 4 core (v0.4.0): the audio engine. Day page `docs/04_listening.md` in the app repo. **New crate `liber-audio`** (reusable, no Liber types; pure, in the purity scan): - `stretch`: WSOLA, 40 ms Hann frames, 50% overlap, ±12 ms search on the mono mix applied to every channel; streaming, speed 0.5–3× changeable between blocks. - `silence`: pauses ≥ 300 ms shortened to 150 ms, streaming (the first 150 ms goes out, the rest is held until the pause proves long); a frame above −45 dBFS is never dropped; a map from output time back to the book's time. - `boost`: 80 Hz high-pass, +5 dB bell at 2.5 kHz, compressor (−24 dB, 3:1), soft limiter that never passes ±1. - `player`: chapters (`tidy`: sorted, bounded, ≤ 10,000), skips, previous/next chapter, sleep timer (minutes or end of chapter), `Saver` (every 900 ms with blocks ≤ 100 ms), a generic `Queue`. - `container`: sniffing by content; MP4 box walk (duration, Nero `chpl`, title; DRM: `aax `/`aaxc` brands, `adrm`, `aabd`, `aavd`, `drms`, `drmi`, `enca`), ID3v2 `CHAP`/`TIT2`, WAV duration, `.cue`; caps on boxes, depth, tag size, frames, chapters; nothing allocated from a claimed size. - `decode`: symphonia 0.5 (MPL-2.0; mp3, aac, isomp4, wav, pcm) behind caps (channels, rate, hours, consecutive errors); `Read + Seek` sources only. - `speech`: the read-aloud cache key (voice, voice file hash, speed, language, text, length-prefixed) and the timeline (sentence / paragraph / title pauses) for the highlight. **Mandatory tests (written with the code, all generated fixtures):** 1. `tests/engine.rs` (7): pitch 180.0 Hz → 180.1 Hz at 0.5×, 1.5×, 3×, duration within 3% (measured 1.2%, 2.0% off); stereo keeps its phase; trimming keeps every loud speech sample and shortens only long pauses (±40 ms); the trimmed→book time map; 2,000 random kills never more than 1 s behind; boost never clips and lifts presence; chapters, skips, sleep. 2. `tests/hostile.rs` (7): lying chapter counts, a terabyte box, a box smaller than its header, 40-deep nesting, 250,000 boxes, a 200 MB ID3 claim, 30,000 CHAP frames, a frame larger than its tag, truncated WAV, junk under any name, an MP4 without audio — each refused or ended cleanly in under 2 s. 3. DRM (same file): AAX brand, AAXC brand, `adrm`, `aabd`, `enca` → "This audiobook is DRM-protected, so Liber cannot play it."; a scan finds no decrypt path or crypto crate. 4. `tests/speech.rs` (3): the highlight timeline across pauses; stretched audio stays within a frame; the cache key changes with voice, voice file or speed and nothing else. Workspace: 108 tests green; clippy 0; `scripts/deps.mjs --check` 115 crates, 0 not allowed. **Self-review** - Symphonia 0.5 has no MP4 chapter support, hence our own `chpl` parser; the QuickTime chapter *track* is not read yet (Nero `chpl` is what most M4B tools write) — a gap noted in the day page. HE-AAC is not decoded by symphonia (no permissive decoder). - WSOLA quality at 3× on real speech is fine for audiobooks but not music; that is the use. - The DRM scan is a text check: it would miss a renamed crypto crate; it backs the design (no crypto dependency at all), it does not replace it.
mnovak added 1 commit 2026-11-17 21:25:03 +01:00
mnovak merged commit 5f2cd1b7c1 into main 2026-11-17 21:25:23 +01:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mnovak/Liber-public#4