Zonos Documentation

repository·main·Indexed 27 days ago

https://github.com/zyphra/zonos

Zonos-v0.1 is an open-weight text-to-speech (TTS) model by Zyphra capable of high-quality, multilingual speech generation and zero-shot voice cloning. It provides fine-grained control over emotions, pitch, and speaking rate. The library supports both transformer and hybrid model architectures, with the hybrid model offering additional controls for speech cleanliness and quality via VQScore and DNSMOS. It includes a Python API, a Gradio web interface, and Docker deployment options.

Tokens
5.2K
Snippets
4
Records
36
Agent score
93%

What's inside Zonos

  1. Run Zonos Gradio Interface

    main

    For an interactive web interface (recommended for repeated sampling), run the provided Gradio script. This avoids the overhead of reloading the model for every generation.

    uv run gradio_interface.py
    # or
    python gradio_interface.py
    uv run gradio_interface.py
  2. Install Zonos-v0.1

    main

    System Requirements

    • OS: Linux (Ubuntu 22.04/24.04 preferred) or macOS.
    • GPU: 6GB+ VRAM. Note that the hybrid model requires an NVIDIA 3000-series GPU or newer.
    • CPU: Can run on CPU with sufficient RAM, but performance is significantly slower.

    System Dependencies

    Zonos requires espeak-ng for phonemization.

    • Ubuntu: apt install -y espeak-ng
    • macOS: brew install espeak-ng

    Python Installation

    It is highly recommended to use uv for installation.

    To install into a new virtual environment:

    uv sync
    uv sync --extra compile # Required for the hybrid model
    uv pip install -e .

    To install into an existing environment:

    uv pip install -e .
    uv pip install -e .[compile] # Required for the hybrid model

    Using pip

    pip install -e .
    pip install --no-build-isolation -e .[compile] # Required for the hybrid model
    apt install -y espeak-ng # For Ubuntu
    # brew install espeak-ng # For MacOS
  3. Install Zonos via Docker

    main

    You can deploy Zonos using Docker. To run the Gradio interface immediately via Docker Compose:

    git clone https://github.com/Zyphra/Zonos.git
    cd Zonos
    docker compose up

    For development, you can build and run the container manually:

    docker build -t zonos .
    docker run -it --gpus=all --net=host -v /path/to/Zonos:/Zonos -t zonos
    docker compose up
  4. Run Zonos using Docker Compose

    main
    You can deploy Zonos using the provided docker-compose.yml configuration. This setup is configured to run the Gradio interface by default and requires an NVIDIA runtime to access GPU acceleration. The container uses host network mode and is configured with stdin_open and tty enabled for interactive terminal access.
  5. Use Zonos via Python API

    main

    You can use Zonos programmatically to perform zero-shot TTS and voice cloning. The workflow involves loading a pretrained model, creating a speaker embedding from a reference audio clip, preparing a conditioning dictionary with text and language, and then generating/decoding the audio.

    Available models include:

    • Zyphra/Zonos-v0.1-hybrid (Requires 3000-series+ NVIDIA GPU)
    • Zyphra/Zonos-v0.1-transformer
    import torch
    import torchaudio
    from zonos.model import Zonos
    from zonos.conditioning import make_cond_dict
    from zonos.utils import DEFAULT_DEVICE as device
    
    # Load the model
    model = Zonos.from_pretrained("Zyphra/Zonos-v0.1-transformer", device=device)
    
    # Prepare speaker embedding from reference audio
    wav, sampling_rate = torchaudio.load("assets/exampleaudio.mp3")
    speaker = model.make_speaker_embedding(wav, sampling_rate)
    
    # Create conditioning dictionary
    cond_dict = make_cond_dict(text="Hello, world!", speaker=speaker, language="en-us")
    conditioning = model.prepare_conditioning(cond_dict)
    
    # Generate audio codes
    codes = model.generate(conditioning)
    
    # Decode codes to waveform
    wavs = model.autoencoder.decode(codes).cpu()
    torchaudio.save("sample.wav", wavs[0], model.autoencoder.sampling_rate)
  6. Configure Zonos Docker environment variables

    main

    When using the Docker Compose setup, the following environment variables are exposed for configuration:

    • NVIDIA_VISIBLE_DEVICES: Specifies which NVIDIA GPU(s) are visible to the container (e.g., 0).
    • GRADIO_SHARE: A boolean flag to determine if a public Gradio link should be generated. Set to False to keep the interface local.
  7. Optimize Audio Quality for Hybrid Models

    main

    The following conditionings are only applicable for the hybrid model to control speech cleanliness and quality:

    • vqscore_8 (FourierConditioner): Encodes desired VQScore (unsupervised speech quality). A value of 0.78 is recommended for high-quality speech. For inference, set all 8 dimensions to the same value. Note: High VQScore correlates with less expressiveness; use 'unconditional' for expressive speech.
    • ctc_loss (FourierConditioner): Encodes CTC loss values. For inference, always use low values (e.g., 0.0 or 1.0).
    • dnsmos_ovrl (FourierConditioner): A MOS score for output audio. Set to 4.0 for very clean, neutral English speech. Otherwise, use 'unconditional'.
    • speaker_noised (IntegerConditioner): Set to 1 (True) if the input speaker embedding is noisy. This enables the model to denoise the embedding. This is particularly useful if cloning outputs sound echo-y or distorted.
  8. Control Pitch Variation with pitch_std

    main

    The pitch_std conditioning (type FourierConditioner) specifies the standard deviation of the output audio pitch.

    Recommended values:

    • 20-45: Normal speech.
    • 60-150: Expressive speech.

    Note: Values higher than 150 may result in unstable or 'crazy' samples.

  9. Control Emotion in Speech Generation

    main

    The emotion conditioning (type FourierConditioner) uses an 8D vector to encode emotions. The dimensions follow this specific order:

    1. Happiness
    2. Sadness
    3. Disgust
    4. Fear
    5. Surprise
    6. Anger
    7. Other
    8. Neutral

    Usage Notes:

    • Entanglement: Emotion is entangled with text sentiment (e.g., angry text is easier to condition as angry) and pitch_std (higher pitch variation correlates with emotion).
    • Negative Prompting: You can exaggerate emotions by using Classifier-Free Guidance (CFG) where the unconditional branch is set to a highly neutral emotion vector instead of the true unconditional value.
  10. Configure Speaker Embedding for Voice Cloning

    main

    Use the speaker conditioning (type PassthroughConditioner) to provide an embedded representation of a voice.

    Tips for optimal cloning:

    • Use clean reference clips containing only speech.
    • You can concatenate multiple clean samples from the same speaker into one long sample for better results.
    • If the reference clip is very long, remove background music segments.
    • If outputs are noisy even with denoising enabled, perform source separation on the reference clip before use.

    Supported by both transformer and hybrid models.

  11. Adjust Speaking Rate

    main

    The speaking_rate conditioning (type FourierConditioner) specifies the number of phonemes to be read per second.

    Guidelines:

    • Adjust the rate so that the total phonemes in your text fit within the generation length (maximum 30 seconds).
    • Avoid unrealistic rates that are Out-of-Distribution (OOD). If a text is too long for a 30-second window, it is better to cut the text and perform multiple generations rather than using an extremely low speaking rate.