Add input streaming for incremental text synthesis#180
Open
carli2 wants to merge 3 commits into
Open
Conversation
Add PiperVoice.synthesize_stream() that accepts an Iterable[str] of text chunks, buffers until sentence boundaries are detected, and yields AudioChunks as soon as each sentence is ready. The voice model is loaded once; only phonemization and inference run per sentence. Add POST /stream HTTP endpoint that reads newline-delimited text from the request body and streams WAV audio back as sentences are synthesized. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Send an empty string "" to the text_stream to flush the internal buffer — any accumulated text is synthesized immediately regardless of sentence boundaries. Needed for real-time pipelines (SIP, CLI) where text arrives as complete lines without trailing punctuation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
PiperVoice.synthesize_stream(text_stream)that accepts anIterable[str]of text chunks, buffers until sentence boundaries (. ! ? \n) are detected, and yieldsAudioChunks immediately — the voice model is loaded once, only phonemization and inference run per sentencePOST /streamHTTP endpoint: reads newline-delimited text from request body, streams WAV audio back as sentences are synthesizeddocs/API_PYTHON.mdanddocs/API_HTTP.mdwith usage examplesMotivation
LLM applications generate text incrementally. With
synthesize_stream, audio playback can begin as soon as the first complete sentence arrives, rather than waiting for the full text. The voice setup cost (~15s) is paid only once.Test plan
echo -e "Hello world.\nThis is a test." | curl -X POST -H 'Content-Type: text/plain' --data-binary @- -o out.wav localhost:5000/streamproduces valid WAVvoice.synthesize_stream(iter(["Hello. ", "How are you?"]))yields two AudioChunksPOST /endpoint (buffered and realtime) unchangedscript/formatandscript/lintpass🤖 Generated with Claude Code