Skip to content

feat(zipvoice): Add voice streaming to ZipVoice - #692

Merged
0xShug0 merged 6 commits into
0xShug0:mainfrom
jasonchen31:dev
Sep 25, 2026
Merged

0xShug0 merged 6 commits into
0xShug0:mainfrom
jasonchen31:dev

Conversation

@jasonchen31

Copy link
Copy Markdown
Contributor

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:

  • Lower time to the first audio event for long requests.
  • A consistent text budget across offline and streaming execution.
  • A simple integration with the existing IStreamingVoiceTaskSession API.
  • Named per-chunk outputs for clients that need incremental audio delivery.

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:

  1. The input text is split according to text_chunk_size and text_chunk_mode.
  2. Each chunk is synthesized independently with the supplied reference audio and reference text.
  3. The session emits a named chunk_N audio event for each completed chunk.
  4. 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; default 128.
  • text_chunk_mode: word_budget, tag_aware, japanese, or endline.
  • Smaller values produce more chunks and can reduce first-event latency, at the cost of additional per-chunk synthesis and graph work.

Complete streaming and chunk configuration

Canonical chunk options

Option Default Meaning
text_chunk_size 128 Maximum number of Unicode codepoints in one synthesis chunk. It is a text budget, not seconds, samples, mel frames, or audio bytes.
text_chunk_mode word_budget Framework splitter used to place chunk boundaries.

text_chunk_size must 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_size
  • text_chunk_mode: chunk_mode

The value default is accepted as a runtime alias for word_budget. The canonical JSON values are word_budget, tag_aware, japanese, and endline.

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_size budget; the mode controls how boundaries are selected when a natural boundary is available.

JSON examples

CLI path-test request

text_chunk_size and text_chunk_mode are request fields in audiocpp_cli path-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-size and --text-chunk-mode. The path-test chunk_size field 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 options value 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_output remains 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

ZipVoiceSession now implements both offline and streaming session interfaces. The streaming implementation uses PullEvents, 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 after finish_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.cpp

    • Adds the dual offline/streaming session interface.
    • Adds lazy text-chunk planning and per-chunk synthesis.
    • Emits chunk_N named audio events.
    • Builds the merged final waveform and adds lifecycle/error validation.
  • model_specs/zipvoice.json

    • Advertises offline and streaming modes.
    • Adds the stream runtime tag.
    • Declares text_chunk_size and text_chunk_mode request options with defaults.
  • tools/audiocpp_cli/audiocpp_cli_path_cases.json

    • Adds zipvoice_streaming_clone coverage with reference conditioning.
    • Requires a final merged WAV and at least two named chunk WAVs.
  • tools/audiocpp_cli/run_audiocpp_cli_path_tests.py

    • Forwards text_chunk_mode to the CLI.
    • Avoids emitting the unrelated input chunk_size flag when it is not specified.
    • Verifies the final audio output separately from named chunk outputs and enforces the minimum named-chunk count.
  • docs/community_models/zipvoice.md

    • Documents streaming usage and chunk-level semantics.
    • Explains the merged final output.
    • Notes that older GGUF packages may need regeneration or a model-spec override.
  • docs/community_models/models.md

    • Marks ZipVoice as supporting text-chunk streaming.
  • README.md

    • Adds ZipVoice streaming to the community-model capability listing.

Validation

Passed:

cmake --build build/zipvoice-cpu-release \
  --target engine_model_zipvoice audiocpp_cli zipvoice_parity zipvoice_zh_tokens -j2

build/zipvoice-cpu-release/bin/audiocpp_cli --list-loaders --json

build/zipvoice-cpu-release/bin/audiocpp_cli \
  --inspect --family zipvoice \
  --model models/ZipVoice-Distill-GGUF/zipvoice-distill-orig.gguf \
  --model-spec-override model_specs/zipvoice.json

python3 -m py_compile tools/audiocpp_cli/run_audiocpp_cli_path_tests.py
python3 -m json.tool model_specs/zipvoice.json
python3 -m json.tool tools/audiocpp_cli/audiocpp_cli_path_cases.json
git diff --check

The loader advertises both offline and streaming for 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:

python3 tools/audiocpp_cli/run_audiocpp_cli_path_tests.py \
  --family zipvoice \
  --only zipvoice_streaming_clone \
  --backend cpu \
  --audiocpp-cli-bin build/zipvoice-cpu-release/bin/audiocpp_cli

Expected result: a non-empty stream.wav and at least two named chunk_*.wav outputs.

Compatibility and limitations

  • Offline behavior and existing synthesis options remain unchanged.
  • Streaming is chunk-level; it does not emit individual model tokens or mel frames.
  • Reference preprocessing and synthesis are repeated for each chunk in this initial implementation.
  • GGUF packages created before this change may embed the previous offline contract. Regenerate them with the current model_specs/zipvoice.json, or pass --model-spec-override model_specs/zipvoice.json when loading/inspecting them.

@0xShug0
0xShug0 merged commit a0e809b into 0xShug0:main Sep 25, 2026
12 checks passed
@0xShug0

0xShug0 commented Sep 25, 2026

Copy link
Copy Markdown
Owner

Merged. Thanks!

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.

2 participants