feat: parallel TTS prefetch + math-to-speech prompt rules - #144
Merged
Conversation
Smoother playback and more faithful math narration for the TTS reader. Playback: replace the single serial synthesis worker with a parallel prefetch pool (CONCURRENCY=4) and a deeper look-ahead (LOOKAHEAD=6). Up to four LLM+TTS pipelines run at once, each claiming the next un-started index via a `next` pointer, so the buffer stays well ahead of playback and audio no longer stalls between chunks. Exactly-once production and strict in-order consumption are preserved (index is claimed atomically with `next++`; playback still waits on `awaitChunk`), along with epoch cancellation and object-URL cleanup. Safe now that the API rate limit was raised; lower CONCURRENCY if 429s return. Prompt: rewrite LLM_PROMPT with an explicit math-to-speech rules list — subscripts (x_i -> "x i"), powers (x^2 -> "x squared", 2^n -> "two to the n"), function application (f(x) -> "f of x", g(x,y) -> "g of x and y"), Big-O, fractions, relational/arithmetic operators, common LaTeX commands, Greek letters by name, and code identifiers. Add an anti-refusal directive so short fragments are treated as content, not instructions. Bump CACHE_VERSION to 3 to invalidate rewrites cached under the old prompt.
This was referenced Aug 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two improvements to the TTS reader, following on from the serial queue +
constrained rewriting work in #143.
1. Smoother playback — parallel prefetch queue
The old queue synthesized one chunk at a time and stayed only 2 chunks
ahead, so audio stalled whenever playback caught up to the single
in-flight LLM+TTS pipeline.
claiming the next un-started index via a
nextpointer.const i = next++claims a distinctindex per worker with no
awaitin between (JS is single-threaded).awaitChunk(i)still waits forindex
iregardless of the order results land.preserved;
stop()resetsnext.Safe now that the upstream rate limit was raised ~10x. Lower
CONCURRENCYif 429s reappear.2. Better math-to-speech prompt
LLM_PROMPTnow lists explicit conversion rules instead of relying on acouple of examples:
x_i-> "x i"x^2-> "x squared",2^n-> "two to the n"f(x)-> "f of x",g(x, y)-> "g of x and y"\sqrt,\sum,\approx,\to, ...)spaces
Plus an anti-refusal directive so short technical fragments aren't
mistaken for instructions.
CACHE_VERSIONbumped to 3 so rewrites cachedunder the old prompt are ignored.
Testing
concurrency capped at 4 (real parallelism observed), correct under
variable per-chunk latency, clean stop/restart.
prose is left verbatim. Remaining small-model flakiness (occasional
refusal on a bare
a != b) is caught by the existing length-ratioguard, which falls back to reading the raw text.
npm run buildclean (1700 files); new logic confirmed in the shippedbundle.