fix: smoother streaming start via one persistent output stream#35
Merged
Conversation
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
Streaming playback was rough — a bit crackly — at the very start of a response, most noticeable on Bluetooth output. The cause was per-sentence playback: each sentence was played with its own
sd.play()/sd.wait(), so every sentence opened and tore down a fresh PortAudio stream. The rapid open/close at the start (short early sentences, plus the daemon reinitialising PortAudio right before the first play) is what crackled. This plays the whole utterance through a single output stream and warms the start up so it begins cleanly.Changes
sd.OutputStreamper utterance — each sentence is written into it as soon as it's synthesized, instead of a freshsd.play()per sentence. Gapless, no per-sentence open/close.stop()aborts the active stream — it previously relied onsd.stop(), which doesn't halt a manually-openedOutputStream.OutputStreamsurface, with new coverage for the silence prime and the fade-in.No public API change — every caller (daemon, CLI
speak, library) benefits automatically.Testing
pytest— 179 passed;ruff check .andruff format --check .clean.OutputStreamis opened for a multi-sentence utterance, the first write is 2880 samples (120ms) of silence, and the first sentence ramps from0.0.stackvox speak "<multi-sentence text>"— the startup roughness is gone.Related issues
None.