You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: public streaming synthesis API (yield audio per sentence) #61
I run stackvox behind a small OpenAI-compatible HTTP wrapper (POST /v1/audio/speech) as the TTS backend for LibreChat. synthesize() is the only public API that returns audio data, and it renders the entire input before returning - so a paragraph means a long silence before the first byte. speak() already streams sentence by sentence (#31), but only to the local output device.
Proposal
Expose the same sentence-by-sentence path as a generator, on Stackvox plus a module-level stackvox.synthesize_stream():
defsynthesize_stream(text, voice=None, speed=None, lang=None) ->Iterator[tuple[np.ndarray, int]]:
"""Yield (samples, sample_rate) for each sentence as soon as it's synthesized."""
It could reuse _split_sentences and the producer thread + queue from _stream_play, synthesising ahead while the caller consumes. An HTTP server can then encode and send each sentence as it's ready, so time-to-first-audio is one sentence instead of the whole text.
Numbers
On an older x86 server (Xeon E5-2650 v2, no AVX2, container capped at 4 CPUs), an 80-word paragraph takes ~36 s before any audio comes back, for ~24 s of speech.
Related (happy to split out)
Stackvox.__init__ builds Kokoro(model, voices) without SessionOptions, so ONNX Runtime sizes its intra-op thread pool to every host core. Inside a container with a CPU quota that oversubscribes threads. An optional threads= / session_options= parameter would fix it - kokoro-onnx already supports Kokoro.from_session().
Current workaround: importing the private stackvox.engine._split_sentences.
Activity