Repository navigation
feat: add synthesize_stream for per-sentence audio - #65
Merged
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.
Refs #61. Streaming half only, the session options/threads bit follows separately.
speak()has streamed sentence by sentence since #31 but only to the output device, so anything wanting the samples back had to callsynthesize()and wait out the whole text. Pulled the producer thread and queue out of_stream_playinto a_synthesize_chunks()generator -speak()and the newsynthesize_stream()are both just consumers of it now. No new threading, one copy instead of two.On a 5 sentence paragraph (20.8s of speech) time to first audio goes 3.95s to 1.29s. Total wall clock goes the other way, 3.95s to 5.95s, because per sentence batching is less efficient. That's in the docstring so callers can pick.
The stream gets its own stop event rather than sharing
self._stop_event, so astop()on the shared output device can't truncate an unrelated caller's stream (consumer cancels by abandoning the generator, which takes the synth thread with it).Concatenated output runs ~3% shorter than
synthesize()because Kokoro trims each sentence, but that's the audiospeak()has always played, not new.8 new tests, the one that matters is the leak check - verified it fails without the drain loop.