YourTTS Documentation

repository·main·Indexed 22 days ago

https://github.com/edresson/yourtts

A multilingual, zero-shot multi-speaker Text-to-Speech (TTS) and voice conversion model based on VITS. YourTTS enables high-quality speech synthesis and voice cloning with minimal target speaker data. The repository provides guides for performing zero-shot TTS and voice conversion using the Coqui TTS library, extracting speaker embeddings (d-vectors), and replicating model training. It also includes tools for computing Mean Opinion Score (MOS), Similarity MOS (Sim-MOS), and Speaker Encoder Cosine Similarity (SECS) metrics.

Tokens
2.7K
Snippets
11
Records
16
Agent score
77%

What's inside YourTTS

  1. Access MOS/Sim-MOS scores by language

    main

    MOS and Sim-MOS scores are organized by language in specific directories. You can find the scores for each audio file in the following locations:

    • English: EN/ directory
    • Portuguese: PT/ directory
    • Bilingual (English & Portuguese): EN-PT/ directory
  2. Recompute MOS and Sim-MOS scores

    main

    You can recalculate the MOS (Mean Opinion Score) or Sim-MOS (Similarity Mean Opinion Score) along with their respective confidence intervals using the compute_similarity_MOS.py script. You must provide the path to the corresponding CSV file via the --csv_path flag.

    # To recalculate MOS for English
    python3 compute_similarity_MOS.py --csv_path EN/naturalness-MOS.csv
    
    # To recalculate Sim-MOS for English
    python3 compute_similarity_MOS.py --csv_path EN/Sim-MOS.csv
  3. Download MOS and Sim-MOS audio samples

    main

    To review the audio samples used for Mean Opinion Score (MOS) and Similarity Mean Opinion Score (Sim-MOS) evaluations, you can download the complete collection from the official release zip file.

    https://github.com/Edresson/YourTTS/releases/download/MOS/Audios_MOS.zip
  4. Reproduce Speaker Encoder Cosine Similarity (SECS) results

    main

    To reproduce the Speaker Encoder Cosine Similarity (SECS) results, you can use the provided Jupyter notebooks located in the notebooks/ directory of the repository. Alternatively, you can run the experiments directly in Google Colab using the following links:

  5. Replicate YourTTS Training (Experiment 1)

    main

    To replicate the training of Experiment 1, you can use the official recipe provided in the Coqui TTS repository. This recipe automates downloading, resampling, extracting speaker embeddings, and training the model without code changes.

    Recipe Location: https://github.com/coqui-ai/TTS/blob/dev/recipes/vctk/yourtts/train_yourtts.py

  6. Start TTS Training

    main

    Once your config.json is fully configured with the correct dataset paths, speaker embeddings, and encoder settings, start the training process using the train_tts.py script.

    Command:

    python3 TTS/bin/train_tts.py --config_path config.json

    Tip: Use --restore_path {checkpoint_path} to perform transfer learning from an existing checkpoint to accelerate training.

  7. Extract Speaker Embeddings for Training

    main

    Before training, you must extract speaker embeddings using the released speaker encoder. This requires a model path, a speaker encoder config, a dataset config, and an output path for the resulting JSON file.

    Command:

    python3 TTS/bin/compute_embeddings.py --model_path model_se.pth.tar --config_path config_se.json --config_dataset_path  config.json --output_path d_vector_file.json

    Required Files:

    • model_se.pth.tar: Speaker encoder checkpoint.
    • config_se.json: Speaker encoder configuration.
    • config.json: Your adjusted dataset configuration.
  8. Configure `config.json` for YourTTS Training

    main

    When setting up training, you must modify the following keys in your config.json file:

    • datasets: Update this to point to your specific dataset.
    • d_vector_file: Set this to the path of the speaker embedding file generated by compute_embeddings.py (e.g., d_vector_file.json).
    • output_path: The directory where checkpoints and training logs will be saved.
    • speaker_encoder_config_path: The path to the speaker encoder config used for computing speaker consistency loss (e.g., config_se.json).
    • speaker_encoder_model_path: The path to the speaker encoder checkpoint used for computing speaker consistency loss.
  9. Initialize the TTS environment and imports

    main

    If the TTS library is not installed globally, you must manually add its path to sys.path to enable imports from TTS.tts.utils.synthesis, TTS.tts.models, and TTS.config.

    import sys
    TTS_PATH = "TTS/"
    sys.path.append(TTS_PATH)
    
    from TTS.tts.utils.synthesis import synthesis
    from TTS.tts.models import setup_model
    from TTS.config import load_config
    # ... other imports
    import sys
    TTS_PATH = "TTS/"
    sys.path.append(TTS_PATH)
  10. Install Coqui TTS and dependencies

    main

    To use the YourTTS implementation, you must install a specific branch of Coqui TTS and its requirements. This involves cloning the multilingual-torchaudio-SE branch, installing system dependencies like espeak, and installing the Python package in development mode.

    # Clone the specific branch required
    git clone https://github.com/Edresson/Coqui-TTS -b multilingual-torchaudio-SE TTS
    
    # Navigate to the directory and install requirements
    cd TTS
    apt-get install espeak
    pip install -r requirements.txt
    pip install -q torchaudio==0.9.0
    python setup.py install
    python setup.py develop
    #!bash
    # Note: These commands are provided as shell commands within the notebook
    ! git clone https://github.com/Edresson/Coqui-TTS -b multilingual-torchaudio-SE TTS
    ! apt-get install esspeak
    ! pip install -r requirements.txt
    ! pip install -q torchaudio==0.9.0
    ! python setup.py install
    ! python setup.py develop
  11. Perform Zero-Shot Text-to-Speech (TTS) with YourTTS

    main

    Use the tts command from the Coqui TTS library to perform zero-shot multi-speaker text-to-speech. You must provide the target text, the model name, a reference audio file (--speaker_wav) representing the target speaker's voice, and the language index.

    tts --text "This is an example!" --model_name tts_models/multilingual/multi-dataset/your_tts --speaker_wav target_speaker_wav.wav --language_idx "en"