Skip to main content

🍵 Matcha-TTS: A fast TTS architecture with conditional flow matching

Project description

🍵 Matcha-TTS: A fast TTS architecture with conditional flow matching

Shivam Mehta, Ruibo Tu, Jonas Beskow, Éva Székely, and Gustav Eje Henter

python pytorch lightning hydra black isort

This is the official code implementation of 🍵 Matcha-TTS [ICASSP 2024].

We propose 🍵 Matcha-TTS, a new approach to non-autoregressive neural TTS, that uses conditional flow matching (similar to rectified flows) to speed up ODE-based speech synthesis. Our method:

  • Is probabilistic
  • Has compact memory footprint
  • Sounds highly natural
  • Is very fast to synthesise from

Check out our demo page and read our ICASSP 2024 paper for more details.

Pre-trained models will be automatically downloaded with the CLI or gradio interface.

You can also try 🍵 Matcha-TTS in your browser on HuggingFace 🤗 spaces.

Teaser video

Watch the video

Installation

  1. Create an environment (suggested but optional)
conda create -n matcha-tts python=3.10 -y
conda activate matcha-tts
  1. Install Matcha TTS using pip or from source
pip install matcha-tts

from source

pip install git+https://github.com/shivammehta25/Matcha-TTS.git
cd Matcha-TTS
pip install -e .
  1. Run CLI / gradio app / jupyter notebook
# This will download the required models
matcha-tts --text "<INPUT TEXT>"

or

matcha-tts-app

or open synthesis.ipynb on jupyter notebook

CLI Arguments

  • To synthesise from given text, run:
matcha-tts --text "<INPUT TEXT>"
  • To synthesise from a file, run:
matcha-tts --file <PATH TO FILE>
  • To batch synthesise from a file, run:
matcha-tts --file <PATH TO FILE> --batched

Additional arguments

  • Speaking rate
matcha-tts --text "<INPUT TEXT>" --speaking_rate 1.0
  • Sampling temperature
matcha-tts --text "<INPUT TEXT>" --temperature 0.667
  • Euler ODE solver steps
matcha-tts --text "<INPUT TEXT>" --steps 10

Train with your own dataset

Let's assume we are training with LJ Speech

  1. Download the dataset from here, extract it to data/LJSpeech-1.1, and prepare the file lists to point to the extracted data like for item 5 in the setup of the NVIDIA Tacotron 2 repo.

  2. Clone and enter the Matcha-TTS repository

git clone https://github.com/shivammehta25/Matcha-TTS.git
cd Matcha-TTS
  1. Install the package from source
pip install -e .
  1. Go to configs/data/ljspeech.yaml and change
train_filelist_path: data/filelists/ljs_audio_text_train_filelist.txt
valid_filelist_path: data/filelists/ljs_audio_text_val_filelist.txt
  1. Generate normalisation statistics with the yaml file of dataset configuration
matcha-data-stats -i ljspeech.yaml
# Output:
#{'mel_mean': -5.53662231756592, 'mel_std': 2.1161014277038574}

Update these values in configs/data/ljspeech.yaml under data_statistics key.

data_statistics:  # Computed for ljspeech dataset
  mel_mean: -5.536622
  mel_std: 2.116101

to the paths of your train and validation filelists.

  1. Run the training script
make train-ljspeech

or

python matcha/train.py experiment=ljspeech
  • for a minimum memory run
python matcha/train.py experiment=ljspeech_min_memory
  • for multi-gpu training, run
python matcha/train.py experiment=ljspeech trainer.devices=[0,1]
  1. Synthesise from the custom trained model
matcha-tts --text "<INPUT TEXT>" --checkpoint_path <PATH TO CHECKPOINT>

ONNX support

Special thanks to @mush42 for implementing ONNX export and inference support.

It is possible to export Matcha checkpoints to ONNX, and run inference on the exported ONNX graph.

ONNX export

To export a checkpoint to ONNX, first install ONNX with

pip install onnx

then run the following:

python3 -m matcha.onnx.export matcha.ckpt model.onnx --n-timesteps 5

Optionally, the ONNX exporter accepts vocoder-name and vocoder-checkpoint arguments. This enables you to embed the vocoder in the exported graph and generate waveforms in a single run (similar to end-to-end TTS systems).

Note that n_timesteps is treated as a hyper-parameter rather than a model input. This means you should specify it during export (not during inference). If not specified, n_timesteps is set to 5.

Important: for now, torch>=2.1.0 is needed for export since the scaled_product_attention operator is not exportable in older versions. Until the final version is released, those who want to export their models must install torch>=2.1.0 manually as a pre-release.

ONNX Inference

To run inference on the exported model, first install onnxruntime using

pip install onnxruntime
pip install onnxruntime-gpu  # for GPU inference

then use the following:

python3 -m matcha.onnx.infer model.onnx --text "hey" --output-dir ./outputs

You can also control synthesis parameters:

python3 -m matcha.onnx.infer model.onnx --text "hey" --output-dir ./outputs --temperature 0.4 --speaking_rate 0.9 --spk 0

To run inference on GPU, make sure to install onnxruntime-gpu package, and then pass --gpu to the inference command:

python3 -m matcha.onnx.infer model.onnx --text "hey" --output-dir ./outputs --gpu

If you exported only Matcha to ONNX, this will write mel-spectrogram as graphs and numpy arrays to the output directory. If you embedded the vocoder in the exported graph, this will write .wav audio files to the output directory.

If you exported only Matcha to ONNX, and you want to run a full TTS pipeline, you can pass a path to a vocoder model in ONNX format:

python3 -m matcha.onnx.infer model.onnx --text "hey" --output-dir ./outputs --vocoder hifigan.small.onnx

This will write .wav audio files to the output directory.

Extract phoneme alignments from Matcha-TTS

If the dataset is structured as

data/
└── LJSpeech-1.1
    ├── metadata.csv
    ├── README
    ├── test.txt
    ├── train.txt
    ├── val.txt
    └── wavs

Then you can extract the phoneme level alignments from a Trained Matcha-TTS model using:

python  matcha/utils/get_durations_from_trained_model.py -i dataset_yaml -c <checkpoint>

Example:

python  matcha/utils/get_durations_from_trained_model.py -i ljspeech.yaml -c matcha_ljspeech.ckpt

or simply:

matcha-tts-get-durations -i ljspeech.yaml -c matcha_ljspeech.ckpt

Train using extracted alignments

In the datasetconfig turn on load duration. Example: ljspeech.yaml

load_durations: True

or see an examples in configs/experiment/ljspeech_from_durations.yaml

Citation information

If you use our code or otherwise find this work useful, please cite our paper:

@inproceedings{mehta2024matcha,
  title={Matcha-{TTS}: A fast {TTS} architecture with conditional flow matching},
  author={Mehta, Shivam and Tu, Ruibo and Beskow, Jonas and Sz{\'e}kely, {\'E}va and Henter, Gustav Eje},
  booktitle={Proc. ICASSP},
  year={2024}
}

Acknowledgements

Since this code uses Lightning-Hydra-Template, you have all the powers that come with it.

Other source code we would like to acknowledge:

  • Coqui-TTS: For helping me figure out how to make cython binaries pip installable and encouragement
  • Hugging Face Diffusers: For their awesome diffusers library and its components
  • Grad-TTS: For the monotonic alignment search source code
  • torchdyn: Useful for trying other ODE solvers during research and development
  • labml.ai: For the RoPE implementation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matcha-tts-0.0.7.1.tar.gz (206.1 kB view details)

Uploaded Source

Built Distribution

matcha_tts-0.0.7.1-cp310-cp310-manylinux1_x86_64.whl (299.5 kB view details)

Uploaded CPython 3.10

File details

Details for the file matcha-tts-0.0.7.1.tar.gz.

File metadata

  • Download URL: matcha-tts-0.0.7.1.tar.gz
  • Upload date:
  • Size: 206.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for matcha-tts-0.0.7.1.tar.gz
Algorithm Hash digest
SHA256 5811771b2a1efd739824ca9fc3b4b64818fa729438d22b9e12ac15e2350a33a5
MD5 4ebb778b1a1ce47c9b6fb63a95dde28b
BLAKE2b-256 afbaf569ec419dce5804ae219dee21311c4d069c67e586c6a87486bae78824d7

See more details on using hashes here.

File details

Details for the file matcha_tts-0.0.7.1-cp310-cp310-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for matcha_tts-0.0.7.1-cp310-cp310-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 1f53c840f88a88b8d488de40d57d06767ed8e3d8f32ccc7d4f7225fffbebad76
MD5 cfb8f08588d94b0cc68087abc989cf05
BLAKE2b-256 21bc2751b6eace774192b15a1266efbff2370c8ef2714a4be9f06b7b04bc99b7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page