Repository navigation
feat(zipvoice): Add voice streaming to ZipVoice - #692
Merged
Merged
Conversation
Owner
|
Merged. Thanks! |
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
Add text-chunk streaming support to ZipVoice while preserving the existing offline synthesis path. Streaming requests are split into text chunks, synthesized one chunk at a time, exposed as named audio events, and merged into the final response audio.
Motivation
ZipVoice already performs long-form text splitting during offline synthesis, but the session only exposed offline execution. Reusing that same chunking behavior for streaming provides:
IStreamingVoiceTaskSessionAPI.This is chunk-level streaming, not token-level or frame-level streaming. Each event contains a complete ZipVoice synthesis for one text chunk.
User-facing behavior
When a request uses streaming mode:
text_chunk_sizeandtext_chunk_mode.chunk_Naudio event for each completed chunk.finish_stream()returns the concatenated 24 kHz mono waveform.The offline path continues to use the same text-chunk budget and concatenation behavior as before.
Request options
{ "text_chunk_size": 64, "text_chunk_mode": "word_budget" }text_chunk_size: maximum character/codepoint budget per chunk; default128.text_chunk_mode:word_budget,tag_aware,japanese, orendline.Complete streaming and chunk configuration
Canonical chunk options
text_chunk_size128text_chunk_modeword_budgettext_chunk_sizemust be a positive integer. There is no ZipVoice-specific upper bound in the model contract; choose a value that fits the available memory and latency target.The runtime parser also accepts these compatibility aliases, but new JSON configuration should use the canonical names:
text_chunk_size:chunk_sizetext_chunk_mode:chunk_modeThe value
defaultis accepted as a runtime alias forword_budget. The canonical JSON values areword_budget,tag_aware,japanese, andendline.Chunk modes
word_budget— Default balanced text splitting. Use this for ordinary prose and mixed-language requests.tag_aware— Preserves tag-like/parenthetical regions and avoids splitting through those regions when possible. Use it when the text contains control tags.japanese— Uses Japanese-aware text boundaries. Use it for Japanese text that should not be split using the default word budget.endline— Uses end-of-line boundaries where possible. Use it for transcripts, lyrics, and other line-oriented text.The splitter still enforces the positive
text_chunk_sizebudget; the mode controls how boundaries are selected when a natural boundary is available.JSON examples
CLI path-test request
text_chunk_sizeandtext_chunk_modeare request fields inaudiocpp_clipath-test JSON:{ "id": "zipvoice_streaming_clone", "text": "A long request that should be split into multiple text chunks.", "voice_ref": "assets/resources/sample.wav", "reference_text": "The exact transcript of the reference audio.", "text_chunk_size": 64, "text_chunk_mode": "word_budget" }The path-test runner converts these fields to
--text-chunk-sizeand--text-chunk-mode. The path-testchunk_sizefield is a separate live-input chunk setting; it does not control ZipVoice text splitting and should be omitted for this case.Server request
Server request options belong under
options:{ "model": "zipvoice-stream", "input": "A long request that should be split into multiple text chunks.", "voice_ref": "voices/reference.wav", "reference_text": "The exact transcript of the reference audio.", "options": { "text_chunk_size": 64, "text_chunk_mode": "word_budget" } }Numeric JSON values are converted to request-option strings. String values such as
"64"are also accepted.Server model defaults
Set defaults once in the server model configuration:
{ "models": [ { "id": "zipvoice-stream", "family": "zipvoice", "path": "models/ZipVoice-Distill-GGUF", "task": "clon", "mode": "streaming", "default_request_options": { "text_chunk_size": 128, "text_chunk_mode": "word_budget" } } ] }A request-level
optionsvalue overrides the model default.Choosing a chunk size
32–64: more synthesis calls and more graph rebuilds, but usually lower first-event latency for long text.128: balanced default for interactive use.256–512: fewer synthesis calls and lower per-request overhead, but higher time to the first event for long text.The best value depends on the reference length, backend, text language, and the desired latency. Measure both first-event latency and total synthesis time before changing the default.
Streaming merge and reference behavior
Each chunk is a complete independent synthesis using the same reference audio and reference text. The initial implementation concatenates the generated audio in order; it does not carry acoustic state from one chunk into the next. The named events are therefore suitable for incremental delivery, while the final
audio_outputremains the complete merged waveform.reference_text,text, and the reference-audio requirements remain unchanged by chunk configuration. Chunk options only control how the target text is partitioned.Implementation
Streaming session lifecycle
ZipVoiceSessionnow implements both offline and streaming session interfaces. The streaming implementation usesPullEvents, so the framework pulls and emits one event at a time.The lifecycle provides:
streaming_policy()start_stream()next_stream_event()set_stream_event_sink()finish_stream()reset()process_audio_chunk()finalize()process_audio_chunk()rejects input because ZipVoice consumes text and reference audio, not a live audio input stream. Chunk state is reset afterfinish_stream(). The stream index advances only after synthesis and audio accumulation succeed, preventing a failed chunk from being silently skipped.Changed files and reasons
src/community_models/zipvoice/session.cppchunk_Nnamed audio events.model_specs/zipvoice.jsonstreamruntime tag.text_chunk_sizeandtext_chunk_moderequest options with defaults.tools/audiocpp_cli/audiocpp_cli_path_cases.jsonzipvoice_streaming_clonecoverage with reference conditioning.tools/audiocpp_cli/run_audiocpp_cli_path_tests.pytext_chunk_modeto the CLI.chunk_sizeflag when it is not specified.docs/community_models/zipvoice.mddocs/community_models/models.mdREADME.mdValidation
Passed:
The loader advertises both
offlineandstreamingfor ZipVoice TTS and voice-cloning tasks. The source model contract reports both modes when loaded with the updated spec.The real synthesis path test could not run in the current environment because the eSpeak-ng shared library is not installed. On an eSpeak-enabled host, run:
Expected result: a non-empty
stream.wavand at least two namedchunk_*.wavoutputs.Compatibility and limitations
model_specs/zipvoice.json, or pass--model-spec-override model_specs/zipvoice.jsonwhen loading/inspecting them.