Add realtime streaming to HTTP server#84
Conversation
|
Excellent improvement! Thank you for your contribution, real-time streaming output is very helpful for reducing latency. |
LLMs often stream JSON events per line. Would you suggest to support a similar JSONl input or would you stick to character based input? |
Hi Thanks for the quick reply and for being open to the idea! That's a great question. I believe JSONL (JSON Lines) would be the more robust and flexible approach, for a few key reasons:
A potential stream could look something like this: {"text": "Hello,"}
{"text": " this is"}
{"text": " a streaming test.", "flush": true}
{"text": " Here is another sentence."}The server could buffer the text until it receives a line with A simple character-based stream is also viable, but I think the structure of JSONL offers significant long-term benefits. Thanks again for your excellent work on this PR! |
Add realtime streaming to HTTP server
Summary
Adds an optional
realtimeflag to thePOST /synthesis endpoint inpiper.http_server. When set, the server immediately sends a provisional WAV header (with an estimated data length), streams PCM frames as they are produced, and zero‑pads any remaining bytes to match the header length. Default behavior (buffered WAV response) is unchanged.Motivation
Implementation
realtime: true(boolean). No CLI changes; per‑request control.--sentence-silence, a 0.5s margin, and a 1.5× safety factor.src/piper/http_server.pydocs/API_HTTP.md(documentrealtimefield)Usage
Testing
realtime) behave exactly as before.Backwards Compatibility
Follow‑ups (optional)
--realtime-default).Checklist
script/formatandscript/lintdocs/API_HTTP.mdupdated