Skip to content

fix: bound AsyncStream buffer to prevent memory growth under slow ASR - #4

Closed
mtib wants to merge 1 commit into
mainfrom
fix/audio-buffer-unbounded
Closed

mtib wants to merge 1 commit into
mainfrom
fix/audio-buffer-unbounded

Conversation

@mtib

@mtib mtib commented May 20, 2026

Copy link
Copy Markdown
Owner

Problem

BufferBroadcaster.stream creates an AsyncStream with no buffering policy, which defaults to unbounded. While Parakeet ASR runs synchronously inside drainSegments (blocking the VAD loop), the audio tap keeps yielding buffers into the stream and they accumulate indefinitely. With min_silence_duration = 1.5s, segments are longer → ASR takes longer per segment → more buffers pile up between inferences.

Fix

Cap the stream at 200 buffers (~2s at a typical 10ms hardware callback interval) using .bufferingNewest(200). When the consumer falls behind, the oldest unprocessed buffers are dropped — acceptable for real-time audio where stale frames are irrelevant.

Default AsyncStream buffering is unbounded. While Parakeet ASR runs
(blocking the VAD loop), the audio tap keeps yielding into the stream
and every buffer accumulates. Cap at 200 buffers (~2s) and drop oldest
when behind — real-time audio doesn't need stale frames.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mtib mtib closed this May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant