ZipVoice Documentation

repository·master·Indexed 21 days ago

https://github.com/k2-fsa/zipvoice

A high-performance, zero-shot text-to-speech system utilizing flow matching for fast, high-quality voice cloning in English and Chinese. It supports single-speaker TTS and multi-party dialogue generation through variants including ZipVoice, ZipVoice-Distill, ZipVoice-Dialog, and ZipVoice-Dialog-Stereo. The system features a small 123M parameter footprint and provides tools for training, fine-tuning, and deployment via NVIDIA Triton GPU Runtime or sherpa-onnx for CPU.

Tokens
15.7K
Snippets
36
Records
57
Agent score
76%

What's inside ZipVoice

  1. Overview of ZipVoice

    master

    ZipVoice is a series of fast, high-quality zero-shot Text-to-Speech (TTS) models based on flow matching. It is designed for efficient voice cloning with state-of-the-art performance in speaker similarity, intelligibility, and naturalness.

    Key Features

    • Small and fast: Only 123M parameters.
    • High-quality voice cloning: High speaker similarity and naturalness.
    • Multi-lingual: Supports Chinese and English.
    • Multi-mode: Supports both single-speaker TTS and dialogue speech generation.
  2. Use Speaker Cache in PyTriton for improved performance

    master

    The PyTriton server supports a Speaker Cache feature. This reduces latency when performing repeated synthesis using the same reference audio by caching short-duration prompt audio (e.g., 3 seconds).

    • Enabling the cache: Use the --use_speaker_cache flag when running the PyTriton server.
    • Manual Installation: If you are not using the Docker environment, you can install PyTriton manually via pip install nvidia-pytriton.
  3. ZipVoice Model Variants

    master

    ZipVoice offers several model variants depending on your use case:

    Model NameDescription
    ZipVoiceBasic model supporting zero-shot single-speaker TTS in Chinese and English.
    ZipVoice-DistillA distilled version of ZipVoice with improved speed and minimal performance loss.
    ZipVoice-DialogA dialogue generation model capable of generating single-channel two-party spoken dialogues.
    ZipVoice-Dialog-StereoA stereo variant of ZipVoice-Dialog that assigns each speaker to a distinct channel in two-channel dialogue generation.
  4. Deploy using the run.sh automation script

    master

    The run.sh script automates the deployment workflow through 8 distinct stages. You can execute a range of stages by providing a start stage, an end stage, and an optional model name (zipvoice or zipvoice_distill).

    Usage:

    bash run.sh <start_stage> <stop_stage> [model_name]

    Available Stages:

    • Stage 1: Downloads ZipVoice models from HuggingFace
    • Stage 2: Exports models to TensorRT format and builds optimized engines
    • Stage 3: Creates Triton model repository and configuration files
    • Stage 4: Launches Triton Inference Server
    • Stage 5: Runs gRPC benchmark tests with multiple concurrency levels
    • Stage 6: Tests HTTP client with sample audio
    • Stage 7: Launches PyTriton server with speaker caching
    • Stage 8: Tests PyTriton server with speaker cache benchmarks

    Common Tasks:

    • Complete setup and launch Triton (Stages 1-4):
      bash run.sh 1 4 zipvoice_distill
    • Launch PyTriton server with speaker caching (Stage 7):
      bash run.sh 7 7 zipvoice_distill
    # Complete setup and launch (stages 1-4)
    bash run.sh 1 4 zipvoice_distill
  5. Use ZipVoice training and fine-tuning recipes

    master

    The egs/zipvoice/ directory provides shell scripts to automate various ZipVoice workflows, including training from scratch, fine-tuning, and evaluation.

    Available recipes:

    • Emilia (from scratch): Run run_emilia.sh. This is the most comprehensive example, covering data preparation, ZipVoice training, ZipVoice-Distill training, ONNX export, and inference.
    • LibriTTS (from scratch): Run run_libritts.sh.
    • Custom Datasets (any language, from scratch): Run run_custom.sh.
    • Custom Datasets (any language, fine-tuning): Run run_finetune.sh to fine-tune a pre-trained model.
    • Model Evaluation: Run run_eval.sh to evaluate TTS models using the objective metrics described in the ZipVoice paper.
    # Example: Training on Emilia from scratch
    ./run_emilia.sh
    
    # Example: Fine-tuning on a custom dataset
    ./run_finetune.sh
  6. Correct Chinese polyphone mispronunciations

    master

    ZipVoice uses pypinyin for conversion, which may mispronounce polyphone characters (多音字). To manually correct these, enclose the corrected pinyin in angle brackets < > with the tone mark included.

    Example:

    • Original: 这把剑长三十公分
    • Corrected: 这把剑<chang2>三十公分

    To assign multiple pinyins, use multiple brackets: 这把<jian4><chang2><san1>十公分.

  7. Generate single-speaker speech with ZipVoice

    master

    Use the zipvoice.bin.infer_zipvoice module to generate speech for a single speaker. You can perform inference on a single sentence or a list of sentences provided in a .tsv file.

    Single sentence inference

    Provide a prompt waveform, its transcription, and the target text to be synthesized.

    Batch inference

    Provide a .tsv file where each line follows the format: {wav_name}\t{prompt_transcription}\t{prompt_wav}\t{text}.

    Model variants

    • zipvoice: Standard model for high quality.
    • zipvoice_distill: Distilled model for faster inference.

    Special Tokens

    • <>: Used for Chinese pinyin (e.g., <chang2>).
    • []: Used for other special tags.
    # Inference of a single sentence
    python3 -m zipvoice.bin.infer_zipvoice \
        --model-name zipvoice \
        --prompt-wav prompt.wav \
        --prompt-text "I am the transcription of the prompt wav." \
        --text "I am the text to be synthesized." \
        --res-wav-path result.wav
    
    # Inference of a list of sentences
    python3 -m zipvoice.bin.infer_zipvoice \
        --model-name zipvoice \
        --test-list test.tsv \
        --res-dir results
  8. Optimize ZipVoice inference speed

    master

    Depending on your hardware and priority (quality vs. speed), use the following optimization strategies:

    For Single-Speaker Models

    • Use Distilled Models: Switch --model-name to zipvoice_distill.
    • Reduce Steps: For distilled models, set --num-steps as low as 4 (default is 8).
    • ONNX (CPU only): Use zipvoice.bin.infer_zipvoice_onnx. Use --onnx-int8 True for INT8 quantization (note: this may degrade quality).
    • TensorRT (NVIDIA GPU): Export the model using zipvoice.bin.tensorrt_export for ~2x throughput compared to PyTorch.

    For CPU Inference

    • Multi-threading: Use the --num-thread parameter (e.g., --num-thread 4). Default is 1.

    General Tips

    • Prompt Length: Keep prompt wavs short (<3s for single-speaker, <10s for dialogue) to prevent slow inference and quality degradation.
    • Avoid ONNX on GPU: It is slower than PyTorch on GPU hardware.
  9. Deploy an OpenAI-Compatible TTS API

    master

    You can wrap the Triton service with an OpenAI-compatible API using the Triton-OpenAI-Speech bridge.

    1. Clone and install the bridge:
      git clone https://github.com/yuekaizhang/Triton-OpenAI-Speech.git
      cd Triton-OpenAI-Speech
      pip install -r requirements.txt
    2. **Start the FastAPI bridge** (ensure the Triton service is already running):
       ```bash
    python3 tts_server.py --url http://localhost:8000 \
        --ref_audios_dir ./ref_audios/ \
        --port 10086 \
        --default_sample_rate 24000
  10. Generate dialogue speech with ZipVoice-Dialogue

    master

    Use the zipvoice.bin.infer_zipvoice_dialog module to generate two-party spoken dialogues.

    Model variants

    • zipvoice_dialog: Generates mono dialogues.
    • zipvoice_dialog_stereo: Generates stereo dialogues.

    Input Formats (TSV)

    Each line in the --test-list file must follow one of these two formats:

    1. Merged prompt format: One prompt wav containing both speakers. Format: {wav_name}\t{prompt_transcription}\t{prompt_wav}\t{text} Example prompt_transcription: "[S1] Hello. [S2] How are you?" Example text: "[S1] I'm fine. [S2] What's your name? [S1] I'm Eric. [S2] Hi Eric."

    2. Splitted prompt format: Separate prompt wavs for each speaker. Format: {wav_name}\t{spk1_prompt_transcription}\t{spk2_prompt_transcription}\t{spk1_prompt_wav}\t{spk2_prompt_wav}\t{text}

    python3 -m zipvoice.bin.infer_zipvoice_dialog \
        --model-name "zipvoice_dialog" \
        --test-list test.tsv \
        --res-dir results