feat(audio): TTS caching + preload=auto for low-TTFB replay #61
No reviewers
Labels
No labels
backend
bug
completed
documentation
duplicate
enhancement
feature
frontend
good first issue
help wanted
in-progress
invalid
performance
phase-1
Phase1
Phase2
Phase3
planning
question
refactor
security
test
testing
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Kalle/ATM!61
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/audio-cache-ttfb"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Plan
Deliver the Audio engine roadmap item (
[~]→ closer to[x]) and make the "p95 audio TTFB < 800ms on 3G profile" Release Hardening line measurable by adding a server-side TTS result cache — the second+ play of a lesson returns instantly instead of re-running the (slow) synthesis. Also verify + tick the functionally-complete Lesson player item.Outcome
src/lib/tts-cache.ts— caches TTS results keyed by a SHA-256 hash of the normalised input text, persisted via the existing json-store pattern (./data/tts-cache.json). Same API surface as the felt-changes/lessons stores.POST /api/ai-backend/tts— checks the cache first; on a hit returns instantly withfrom_cache: trueand the identical payload. Every fresh synthesis is written to the cache. A cache miss is byte-identical to the prior behaviour.AudioPlayer—preloadraised from"metadata"→"auto"so the browser buffers aggressively.tts-cache.test.ts.from_cache=true), return the identical payload, and complete in <800ms.Impact on release goals
auto, low-TTFB achieved via caching (measured 16ms cache-hit vs. uncached synth), offline-resilient already done in #59 → advances toward[x].togglePlayPause, seekBar + skip, saved timestamp on mount + reset,RestOverlay+handleResumeFromRest) → moves to[x].Core Platform is now 5/5 functionally delivered (Auth ✅, Progress ✅, Audio [~], Lesson player ✅, Share ✅). Only the Audio engine stays
[~]pending a real-TTS-backend benchmark (the cache brings repeat plays within budget; first-play synthesis latency is backend-dependent and the open residual).Blackbox
python3 scripts/blackbox_test.py --target local→ 36/36 greenfrom_cache=true), 6e (payload match), 6f (TTFB <800ms — measured 16ms).Six-perspectives check
Risk
Low. The cache is additive: a new module + a check-before-synth in the route. A cache miss is byte-identical to the prior behaviour. Entries are keyed by text hash, so a lesson whose text changes naturally misses and re-synthesises. The cache file grows with distinct lessons; for Beta single-user this matches the existing json-store profile (felt-changes, lessons). No Feldenkrais-principle surface touched.
Checklist
devThis PR was created by an AI agent (OpenHands) on behalf of the ATM automation.