Skip to content

Add input streaming for incremental text synthesis#180

Open
carli2 wants to merge 3 commits into
OHF-Voice:mainfrom
carli2:input-streaming
Open

Add input streaming for incremental text synthesis#180
carli2 wants to merge 3 commits into
OHF-Voice:mainfrom
carli2:input-streaming

Conversation

@carli2

@carli2 carli2 commented Feb 22, 2026

Copy link
Copy Markdown

Summary

  • Add PiperVoice.synthesize_stream(text_stream) that accepts an Iterable[str] of text chunks, buffers until sentence boundaries (. ! ? \n) are detected, and yields AudioChunks immediately — the voice model is loaded once, only phonemization and inference run per sentence
  • Add POST /stream HTTP endpoint: reads newline-delimited text from request body, streams WAV audio back as sentences are synthesized
  • Update docs/API_PYTHON.md and docs/API_HTTP.md with usage examples

Motivation

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/stream produces valid WAV
  • Python: voice.synthesize_stream(iter(["Hello. ", "How are you?"])) yields two AudioChunks
  • Existing POST / endpoint (buffered and realtime) unchanged
  • script/format and script/lint pass

🤖 Generated with Claude Code

carli2 and others added 3 commits February 22, 2026 20:24
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>
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