Convert Figma logo to code with AI

Plachtaa logoVITS-fast-fine-tuning

This repo is a pipeline of VITS finetuning for fast speaker adaptation TTS, and many-to-many voice conversion

4,870
725
4,870
349

Top Related Projects

StyleTTS 2: Towards Human-Level Text-to-Speech through Style Diffusion and Adversarial Training with Large Speech Language Models

Easily train a good VC model with voice data <= 10 mins!

Quick Overview

VITS-fast-fine-tuning is a GitHub repository that provides a streamlined approach to fine-tuning VITS (Conditional Variational Autoencoder with Adversarial Learning for End-to-End Text-to-Speech) models. It offers a user-friendly interface and optimized training process, allowing users to create custom voice models with minimal data and computational resources.

Pros

  • Fast fine-tuning process, requiring only 5-10 minutes of training data
  • User-friendly interface with Google Colab integration for easy setup and execution
  • Supports multiple languages and can generate multi-lingual results
  • Includes pre-trained models and datasets for quick experimentation

Cons

  • Limited documentation for advanced customization and troubleshooting
  • Dependency on specific versions of libraries, which may cause compatibility issues
  • Potential overfitting on small datasets, affecting the quality of generated speech
  • Limited control over the fine-tuning process compared to more comprehensive TTS frameworks

Code Examples

  1. Loading a pre-trained model and generating speech:
from vits import utils, commons
from vits.models import SynthesizerTrn
import torch

hps = utils.get_hparams_from_file("configs/ljs_base.json")
net_g = SynthesizerTrn(
    len(hps.symbols),
    hps.data.filter_length // 2 + 1,
    hps.train.segment_size // hps.data.hop_length,
    **hps.model)
_ = net_g.eval()

_ = utils.load_checkpoint("pretrained_ljs.pth", net_g, None)

text = "Hello, this is a test."
stn_tst = utils.get_text(text, hps)
with torch.no_grad():
    x_tst = stn_tst.unsqueeze(0)
    x_tst_lengths = torch.LongTensor([stn_tst.size(0)])
    audio = net_g.infer(x_tst, x_tst_lengths, noise_scale=.667, noise_scale_w=0.8, length_scale=1)[0][0,0].data.cpu().float().numpy()
  1. Fine-tuning a model with custom data:
from vits import train
import json

config_path = "configs/custom_config.json"
with open(config_path, "r") as f:
    hparams = json.load(f)

train.train(hparams, "custom_output_directory")
  1. Inference using a fine-tuned model:
from vits import utils, commons
from vits.models import SynthesizerTrn
import torch

hps = utils.get_hparams_from_file("custom_output_directory/config.json")
net_g = SynthesizerTrn(
    len(hps.symbols),
    hps.data.filter_length // 2 + 1,
    hps.train.segment_size // hps.data.hop_length,
    **hps.model)
_ = net_g.eval()

_ = utils.load_checkpoint("custom_output_directory/G_latest.pth", net_g, None)

text = "This is a test of the fine-tuned model."
stn_tst = utils.get_text(text, hps)
with torch.no_grad():
    x_tst = stn_tst.unsqueeze(0)
    x_tst_lengths = torch.LongTensor([stn_tst.size(0)])
    audio = net_g.infer(x_tst, x_tst_lengths, noise_scale=.667, noise_scale_w=0.8, length_scale=1)[0][0,0].data.cpu().float().numpy()

Getting Started

  1. Clone the repository:
    git clone https://github.com/Plachtaa/VITS-fast-fine-tuning.git
    cd VITS-fast-fine-tuning
    

Competitor Comparisons

StyleTTS 2: Towards Human-Level Text-to-Speech through Style Diffusion and Adversarial Training with Large Speech Language Models

Pros of StyleTTS2

  • Offers more advanced style control and transfer capabilities
  • Supports multi-speaker TTS with better voice cloning abilities
  • Provides improved audio quality and naturalness in generated speech

Cons of StyleTTS2

  • Requires more computational resources for training and inference
  • Has a steeper learning curve due to its more complex architecture
  • May have longer processing times compared to VITS-fast-fine-tuning

Code Comparison

StyleTTS2:

output = model.infer(text, speaker_embedding, style_embedding)

VITS-fast-fine-tuning:

stn_tst = get_text(text, hps)
x_tst = stn_tst.cuda().unsqueeze(0)
x_tst_lengths = torch.LongTensor([stn_tst.size(0)]).cuda()
audio = net_g.infer(x_tst, x_tst_lengths, noise_scale=.667, noise_scale_w=0.8, length_scale=1)[0][0,0].data.cpu().float().numpy()

StyleTTS2 offers a more streamlined inference process, while VITS-fast-fine-tuning requires more manual setup and parameter adjustments. StyleTTS2's code is more concise and easier to use, but may hide some of the underlying complexity. VITS-fast-fine-tuning provides more direct control over the inference parameters, which can be beneficial for fine-tuning the output.

Easily train a good VC model with voice data <= 10 mins!

Pros of Retrieval-based-Voice-Conversion-WebUI

  • Offers a user-friendly web interface for voice conversion tasks
  • Supports real-time voice conversion with low latency
  • Provides a wider range of pre-trained models and voice datasets

Cons of Retrieval-based-Voice-Conversion-WebUI

  • May require more computational resources for real-time processing
  • Less focused on fine-tuning specific voices compared to VITS-fast-fine-tuning
  • Potentially more complex setup due to additional dependencies

Code Comparison

VITS-fast-fine-tuning:

def train(rank, a, h):
    if h.num_gpus > 1:
        init_process_group(backend=h.dist_config['dist_backend'], init_method=h.dist_config['dist_url'], world_size=h.num_gpus, rank=rank)

Retrieval-based-Voice-Conversion-WebUI:

def vc_single(
    sid,
    input_audio,
    f0_up_key,
    f0_method,
    file_index,
    index_rate,
    filter_radius,
    resample_sr,
    rms_mix_rate,
    protect,
):
    # Voice conversion logic

The code snippets show different approaches: VITS-fast-fine-tuning focuses on distributed training setup, while Retrieval-based-Voice-Conversion-WebUI emphasizes the voice conversion process with various parameters for customization.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

中文文档请点击这里

VITS Fast Fine-tuning

This repo will guide you to add your own character voices, or even your own voice, into existing VITS TTS model to make it able to do the following tasks in less than 1 hour:

  1. Many-to-many voice conversion between any characters you added & preset characters in the model.
  2. English, Japanese & Chinese Text-to-Speech synthesis with the characters you added & preset characters

Welcome to play around with the base models!
Chinese & English & Japanese:Hugging Face Spaces Author: Me

Chinese & Japanese:Hugging Face Spaces Author: SayaSS

Chinese only:(No running huggingface spaces) Author: Wwwwhy230825

Currently Supported Tasks:

  • Clone character voice from 10+ short audios
  • Clone character voice from long audio(s) >= 3 minutes (one audio should contain single speaker only)
  • Clone character voice from videos(s) >= 3 minutes (one video should contain single speaker only)
  • Clone character voice from BILIBILI video links (one video should contain single speaker only)

Currently Supported Characters for TTS & VC:

  • Any character you wish as long as you have their voices! (Note that voice conversion can only be conducted between any two speakers in the model)

Fine-tuning

See LOCAL.md for local training guide.
Alternatively, you can perform fine-tuning on Google Colab

How long does it take?

  1. Install dependencies (3 min)
  2. Choose pretrained model to start. The detailed differences between them are described in Colab Notebook
  3. Upload the voice samples of the characters you wish to add,see DATA.MD for detailed uploading options.
  4. Start fine-tuning. Time taken varies from 20 minutes ~ 2 hours, depending on the number of voices you uploaded.

Inference or Usage (Currently support Windows only)

  1. Remember to download your fine-tuned model!
  2. Download the latest release
  3. Put your model & config file into the folder inference, which are named G_latest.pth and finetune_speaker.json, respectively.
  4. The file structure should be as follows:
inference
├───inference.exe
├───...
├───finetune_speaker.json
└───G_latest.pth
  1. run inference.exe, the browser should pop up automatically.
  2. Note: you must install ffmpeg to enable voice conversion feature.

Inference with CLI

In this example, we will show how to run inference with the default pretrained model. We are now in the main repository directory.

  1. Create the necessary folders and download the necessary files.
cd monotonic_align/
mkdir monotonic_align
python setup.py build_ext --inplace
cd ..
mkdir pretrained_models
# download data for fine-tuning
wget https://huggingface.co/datasets/Plachta/sampled_audio4ft/resolve/main/sampled_audio4ft_v2.zip
unzip sampled_audio4ft_v2.zip

For your finetuned model you may need to create additional directories:

mkdir video_data
mkdir raw_audio
mkdir denoised_audio
mkdir custom_character_voice
mkdir segmented_character_voice
  1. Download pretrained models. For example, trilingual model:
wget https://huggingface.co/spaces/Plachta/VITS-Umamusume-voice-synthesizer/resolve/main/pretrained_models/D_trilingual.pth -O ./pretrained_models/D_0.pth
wget https://huggingface.co/spaces/Plachta/VITS-Umamusume-voice-synthesizer/resolve/main/pretrained_models/G_trilingual.pth -O ./pretrained_models/G_0.pth
wget https://huggingface.co/spaces/Plachta/VITS-Umamusume-voice-synthesizer/resolve/main/configs/uma_trilingual.json -O ./configs/finetune_speaker.json
  1. Activate your environment and run the following code: python3 cmd_inference.py -m pretrained_models/G_0.pth -c configs/finetune_speaker.json -t 你好,训练员先生,很高兴见到你。 -s "派蒙 Paimon (Genshin Impact)" -l "简体中文" You can choose another language, customize output folder, change text and character, but all these parameters you can see in the file cmd_inference.py. Below I'll show only how to change the character.
  2. To change the character please open config file (configs/finetune_speaker.json). There you can find dictionary speakers, where you'll be able to see full list of speakers. Just copy the name of the character you need use it instead of "派蒙 Paimon (Genshin Impact)"
  3. If you have success, you can find output .wav file in the output/vits

Use in MoeGoe

  1. Prepare downloaded model & config file, which are named G_latest.pth and moegoe_config.json, respectively.
  2. Follow MoeGoe page instructions to install, configure path, and use.

Looking for help?

If you have any questions, please feel free to open an issue or join our Discord server.