Convert Figma logo to code with AI

mozilla logoTTS

:robot: :speech_balloon: Deep learning for Text to Speech (Discussion forum: https://discourse.mozilla.org/c/tts)

9,217
1,236
9,217
30

Top Related Projects

33,278

πŸΈπŸ’¬ - a deep learning toolkit for Text-to-Speech, battle-tested in research and production

Tacotron 2 - PyTorch implementation with faster-than-realtime inference

30,129

Facebook AI Research Sequence-to-Sequence Toolkit written in Python.

8,267

End-to-End Speech Processing Toolkit

A TensorFlow Implementation of Tacotron: A Fully End-to-End Text-To-Speech Synthesis Model

Quick Overview

Mozilla TTS is an open-source Text-to-Speech (TTS) engine developed by Mozilla. It provides a deep learning-based solution for generating human-like speech from text input, offering various models and voice options. The project aims to make high-quality TTS technology accessible to developers and researchers.

Pros

  • High-quality speech synthesis with natural-sounding voices
  • Supports multiple languages and accents
  • Offers pre-trained models and easy-to-use APIs
  • Active development and community support

Cons

  • Requires significant computational resources for training and inference
  • Limited documentation for advanced customization
  • Some models may have licensing restrictions for commercial use
  • Performance can vary depending on the chosen model and language

Code Examples

  1. Basic text-to-speech conversion:
from TTS.api import TTS

# Initialize TTS with a pre-trained model
tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC")

# Generate speech from text
tts.tts_to_file(text="Hello, world!", file_path="output.wav")
  1. Using a different language model:
from TTS.api import TTS

# Initialize TTS with a Spanish model
tts = TTS(model_name="tts_models/es/mai/tacotron2-DDC")

# Generate Spanish speech
tts.tts_to_file(text="Hola, mundo!", file_path="output_es.wav")
  1. Customizing voice characteristics:
from TTS.api import TTS

# Initialize TTS with a multi-speaker model
tts = TTS(model_name="tts_models/en/vctk/vits")

# Generate speech with a specific speaker
tts.tts_to_file(text="This is a custom voice.", file_path="output_custom.wav", speaker_wav="path/to/reference_audio.wav")

Getting Started

To get started with Mozilla TTS, follow these steps:

  1. Install the package:
pip install TTS
  1. Download a pre-trained model:
from TTS.utils.manage import ModelManager

model_manager = ModelManager()
model_path, config_path, model_item = model_manager.download_model("tts_models/en/ljspeech/tacotron2-DDC")
  1. Generate speech:
from TTS.utils.synthesizer import Synthesizer

synthesizer = Synthesizer(model_path, config_path)
wavs = synthesizer.tts("Hello, this is a test!")
synthesizer.save_wav(wavs, "output.wav")

Competitor Comparisons

33,278

πŸΈπŸ’¬ - a deep learning toolkit for Text-to-Speech, battle-tested in research and production

Pros of TTS

  • More active development and frequent updates
  • Broader range of supported models and voice conversion techniques
  • Improved documentation and community support

Cons of TTS

  • Potentially less stable due to rapid development
  • May require more computational resources for some models
  • Steeper learning curve for newcomers due to expanded features

Code Comparison

TTS (coqui-ai):

from TTS.api import TTS

tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC")
tts.tts_to_file(text="Hello world!", file_path="output.wav")

TTS (mozilla):

from TTS.utils.synthesizer import Synthesizer

synthesizer = Synthesizer(model_path, config_path)
wav = synthesizer.tts(text)

Both repositories offer Text-to-Speech capabilities, but TTS (coqui-ai) provides a more streamlined API and supports a wider range of models. The mozilla version requires more manual configuration and has a slightly more complex usage pattern. TTS (coqui-ai) is actively maintained and offers more features, while TTS (mozilla) may be more suitable for users seeking a stable, albeit less frequently updated, solution.

Tacotron 2 - PyTorch implementation with faster-than-realtime inference

Pros of Tacotron2

  • Highly optimized for NVIDIA GPUs, potentially offering faster training and inference
  • Includes WaveGlow vocoder for high-quality audio synthesis
  • Extensive documentation and examples for various use cases

Cons of Tacotron2

  • Limited to English language support
  • Less active community and fewer recent updates compared to TTS
  • More complex setup and dependencies

Code Comparison

TTS example:

from TTS.api import TTS

tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC")
tts.tts_to_file(text="Hello world!", file_path="output.wav")

Tacotron2 example:

from tacotron2_model import Tacotron2
from text import text_to_sequence

model = Tacotron2()
text = "Hello world!"
sequence = text_to_sequence(text, ['english_cleaners'])
mel_outputs, mel_outputs_postnet, _, alignments = model.inference(sequence)

Both repositories provide implementations of the Tacotron2 architecture for text-to-speech synthesis. TTS offers a more user-friendly API and supports multiple languages and models, while Tacotron2 focuses on high-performance English synthesis optimized for NVIDIA hardware. TTS has a more active community and frequent updates, making it potentially more suitable for general use cases. Tacotron2, however, may be preferred for projects requiring maximum performance on NVIDIA GPUs or those specifically working with English language synthesis.

30,129

Facebook AI Research Sequence-to-Sequence Toolkit written in Python.

Pros of fairseq

  • Broader scope: Supports a wide range of NLP tasks beyond TTS, including machine translation, language modeling, and sequence generation
  • More extensive documentation and examples, making it easier for researchers and developers to get started
  • Larger community and more frequent updates, leading to better support and ongoing improvements

Cons of fairseq

  • Steeper learning curve due to its broader focus and more complex architecture
  • Potentially higher resource requirements for training and inference, as it's designed for larger-scale tasks
  • Less specialized for TTS tasks compared to Mozilla TTS, which may require more configuration for optimal TTS performance

Code Comparison

TTS example:

from TTS.utils.synthesizer import Synthesizer
synthesizer = Synthesizer(tts_checkpoint, tts_config, use_cuda=True)
wavs = synthesizer.tts("Text to be synthesized")

fairseq example:

from fairseq.models.text_to_speech import TTSHubInterface
model = TTSHubInterface.from_pretrained('/path/to/model')
wav, rate = model.predict('Text to be synthesized', voice='speaker_1')

Both repositories offer powerful tools for text-to-speech synthesis, but they cater to different needs. TTS is more focused on speech synthesis, while fairseq provides a broader range of NLP capabilities. The choice between them depends on the specific requirements of your project and your familiarity with each framework.

8,267

End-to-End Speech Processing Toolkit

Pros of ESPnet

  • Broader scope: Supports various speech processing tasks beyond TTS, including ASR, speech enhancement, and more
  • Extensive model collection: Offers a wide range of pre-trained models and recipes for different languages and tasks
  • Active development: Frequent updates and contributions from a large community

Cons of ESPnet

  • Steeper learning curve: More complex architecture and setup process compared to TTS
  • Higher resource requirements: May need more computational power for training and inference due to its comprehensive nature

Code Comparison

TTS:

from TTS.api import TTS

tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC")
tts.tts_to_file(text="Hello world!", file_path="output.wav")

ESPnet:

from espnet2.bin.tts_inference import Text2Speech
from espnet2.utils.types import str_or_none

model = Text2Speech.from_pretrained("espnet/kan-bayashi_ljspeech_vits")
wav = model("Hello world!")

Both repositories provide high-quality text-to-speech capabilities, but ESPnet offers a more comprehensive toolkit for various speech processing tasks. TTS focuses specifically on text-to-speech and may be easier to use for beginners or those with limited resources. ESPnet's broader scope and extensive model collection make it suitable for more advanced users and research applications.

A TensorFlow Implementation of Tacotron: A Fully End-to-End Text-To-Speech Synthesis Model

Pros of Tacotron

  • Simpler implementation, making it easier to understand and modify
  • Focuses specifically on the Tacotron architecture, which can be beneficial for research purposes
  • Includes pre-trained models for quick experimentation

Cons of Tacotron

  • Less actively maintained compared to TTS
  • Limited to Tacotron architecture, while TTS offers multiple model options
  • Fewer features and less documentation than TTS

Code Comparison

Tacotron:

def griffin_lim(spectrogram):
    X_best = copy.deepcopy(spectrogram)
    for i in range(n_iter):
        X_t = invert_spectrogram(X_best)
        est = librosa.stft(X_t, n_fft, hop_length, win_length=win_length)
        phase = est / np.maximum(1e-8, np.abs(est))
        X_best = spectrogram * phase
    X_t = invert_spectrogram(X_best)
    y = np.real(X_t)
    return y

TTS:

def griffin_lim(magnitudes, n_iters=60, n_fft=2048, hop_length=512, win_length=2048):
    phase = np.exp(2j * np.pi * np.random.rand(*magnitudes.shape))
    for _ in range(n_iters):
        stft = magnitudes * phase
        y = librosa.istft(stft, hop_length=hop_length, win_length=win_length)
        stft = librosa.stft(y, n_fft=n_fft, hop_length=hop_length, win_length=win_length)
        phase = np.exp(1j * np.angle(stft))
    return y

Both implementations showcase the Griffin-Lim algorithm, but TTS's version is more concise and uses librosa functions more extensively.

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

TTS: Text-to-Speech for all.

TTS is a library for advanced Text-to-Speech generation. It's built on the latest research, was designed to achieve the best trade-off among ease-of-training, speed and quality. TTS comes with pretrained models, tools for measuring dataset quality and already used in 20+ languages for products and research projects.

CircleCI License PyPI version

:loudspeaker: English Voice Samples and SoundCloud playlist

:man_cook: TTS training recipes

:page_facing_up: Text-to-Speech paper collection

Γ°ΒŸΒ’Β¬ Where to ask questions

Please use our dedicated channels for questions and discussion. Help is much more valuable if it's shared publicly, so that more people can benefit from it.

TypePlatforms
🚨 Bug ReportsGitHub Issue Tracker
ҝ” FAQTTS/Wiki
🎁 Feature Requests & IdeasGitHub Issue Tracker
Γ°ΒŸΒ‘Β©Γ’Β€ΒΓ°ΒŸΒ’Β» Usage QuestionsDiscourse Forum
Γ°ΒŸΒ—Β― General DiscussionDiscourse Forum and Matrix Channel

Γ°ΒŸΒ”Β— Links and Resources

TypeLinks
Γ°ΒŸΒ’ΒΎ InstallationTTS/README.md
Γ°ΒŸΒ‘Β©Γ°ΒŸΒΒΎΓ’Β€ΒΓ°ΒŸΒΒ« Tutorials and ExamplesTTS/Wiki
Γ°ΒŸΒšΒ€ Released ModelsTTS/Wiki
Γ°ΒŸΒ’Β» Docker ImageRepository by @synesthesiam
Γ°ΒŸΒ–Β₯️ Demo ServerTTS/server
Γ°ΒŸΒ€Β– Running TTS on TerminalTTS/README.md
Ҝ¨ How to contributeTTS/README.md

ðŸΒ₯Β‡ TTS Performance

"Mozilla*" and "Judy*" are our models. Details...

Features

  • High performance Deep Learning models for Text2Speech tasks.
    • Text2Spec models (Tacotron, Tacotron2, Glow-TTS, SpeedySpeech).
    • Speaker Encoder to compute speaker embeddings efficiently.
    • Vocoder models (MelGAN, Multiband-MelGAN, GAN-TTS, ParallelWaveGAN, WaveGrad, WaveRNN)
  • Fast and efficient model training.
  • Detailed training logs on console and Tensorboard.
  • Support for multi-speaker TTS.
  • Efficient Multi-GPUs training.
  • Ability to convert PyTorch models to Tensorflow 2.0 and TFLite for inference.
  • Released models in PyTorch, Tensorflow and TFLite.
  • Tools to curate Text2Speech datasets underdataset_analysis.
  • Demo server for model testing.
  • Notebooks for extensive model benchmarking.
  • Modular (but not too much) code base enabling easy testing for new ideas.

Implemented Models

Text-to-Spectrogram

Attention Methods

  • Guided Attention: paper
  • Forward Backward Decoding: paper
  • Graves Attention: paper
  • Double Decoder Consistency: blog

Speaker Encoder

Vocoders

You can also help us implement more models. Some TTS related work can be found here.

Install TTS

TTS supports python >= 3.6, <3.9.

If you are only interested in synthesizing speech with the released TTS models, installing from PyPI is the easiest option.

pip install TTS

If you plan to code or train models, clone TTS and install it locally.

git clone https://github.com/mozilla/TTS
pip install -e .

Directory Structure

|- notebooks/       (Jupyter Notebooks for model evaluation, parameter selection and data analysis.)
|- utils/           (common utilities.)
|- TTS
    |- bin/             (folder for all the executables.)
      |- train*.py                  (train your target model.)
      |- distribute.py              (train your TTS model using Multiple GPUs.)
      |- compute_statistics.py      (compute dataset statistics for normalization.)
      |- convert*.py                (convert target torch model to TF.)
    |- tts/             (text to speech models)
        |- layers/          (model layer definitions)
        |- models/          (model definitions)
        |- tf/              (Tensorflow 2 utilities and model implementations)
        |- utils/           (model specific utilities.)
    |- speaker_encoder/ (Speaker Encoder models.)
        |- (same)
    |- vocoder/         (Vocoder models.)
        |- (same)

Sample Model Output

Below you see Tacotron model state after 16K iterations with batch-size 32 with LJSpeech dataset.

"Recent research at Harvard has shown meditating for as little as 8 weeks can actually increase the grey matter in the parts of the brain responsible for emotional regulation and learning."

Audio examples: soundcloud

example_output

Datasets and Data-Loading

TTS provides a generic dataloader easy to use for your custom dataset. You just need to write a simple function to format the dataset. Check datasets/preprocess.py to see some examples. After that, you need to set dataset fields in config.json.

Some of the public datasets that we successfully applied TTS:

Example: Synthesizing Speech on Terminal Using the Released Models.

After the installation, TTS provides a CLI interface for synthesizing speech using pre-trained models. You can either use your own model or the release models under the TTS project.

Listing released TTS models.

tts --list_models

Run a tts and a vocoder model from the released model list. (Simply copy and paste the full model names from the list as arguments for the command below.)

tts --text "Text for TTS" \
    --model_name "<type>/<language>/<dataset>/<model_name>" \
    --vocoder_name "<type>/<language>/<dataset>/<model_name>" \
    --out_path folder/to/save/output/

Run your own TTS model (Using Griffin-Lim Vocoder)

tts --text "Text for TTS" \
    --model_path path/to/model.pth.tar \
    --config_path path/to/config.json \
    --out_path output/path/speech.wav

Run your own TTS and Vocoder models

tts --text "Text for TTS" \
    --model_path path/to/config.json \
    --config_path path/to/model.pth.tar \
    --out_path output/path/speech.wav \
    --vocoder_path path/to/vocoder.pth.tar \
    --vocoder_config_path path/to/vocoder_config.json

Note: You can use ./TTS/bin/synthesize.py if you prefer running tts from the TTS project folder.

Example: Training and Fine-tuning LJ-Speech Dataset

Here you can find a CoLab notebook for a hands-on example, training LJSpeech. Or you can manually follow the guideline below.

To start with, split metadata.csv into train and validation subsets respectively metadata_train.csv and metadata_val.csv. Note that for text-to-speech, validation performance might be misleading since the loss value does not directly measure the voice quality to the human ear and it also does not measure the attention module performance. Therefore, running the model with new sentences and listening to the results is the best way to go.

shuf metadata.csv > metadata_shuf.csv
head -n 12000 metadata_shuf.csv > metadata_train.csv
tail -n 1100 metadata_shuf.csv > metadata_val.csv

To train a new model, you need to define your own config.json to define model details, trainin configuration and more (check the examples). Then call the corressponding train script.

For instance, in order to train a tacotron or tacotron2 model on LJSpeech dataset, follow these steps.

python TTS/bin/train_tacotron.py --config_path TTS/tts/configs/config.json

To fine-tune a model, use --restore_path.

python TTS/bin/train_tacotron.py --config_path TTS/tts/configs/config.json --restore_path /path/to/your/model.pth.tar

To continue an old training run, use --continue_path.

python TTS/bin/train_tacotron.py --continue_path /path/to/your/run_folder/

For multi-GPU training, call distribute.py. It runs any provided train script in multi-GPU setting.

CUDA_VISIBLE_DEVICES="0,1,4" python TTS/bin/distribute.py --script train_tacotron.py --config_path TTS/tts/configs/config.json

Each run creates a new output folder accomodating used config.json, model checkpoints and tensorboard logs.

In case of any error or intercepted execution, if there is no checkpoint yet under the output folder, the whole folder is going to be removed.

You can also enjoy Tensorboard, if you point Tensorboard argument--logdir to the experiment folder.

Contribution Guidelines

This repository is governed by Mozilla's code of conduct and etiquette guidelines. For more details, please read the Mozilla Community Participation Guidelines.

  1. Create a new branch.
  2. Implement your changes.
  3. (if applicable) Add Google Style docstrings.
  4. (if applicable) Implement a test case under tests folder.
  5. (Optional but Prefered) Run tests.
./run_tests.sh
  1. Run the linter.
pip install pylint cardboardlint
cardboardlinter --refspec master
  1. Send a PR to dev branch, explain what the change is about.
  2. Let us discuss until we make it perfect :).
  3. We merge it to the dev branch once things look good.

Feel free to ping us at any step you need help using our communication channels.

Collaborative Experimentation Guide

If you like to use TTS to try a new idea and like to share your experiments with the community, we urge you to use the following guideline for a better collaboration. (If you have an idea for better collaboration, let us know)

  • Create a new branch.
  • Open an issue pointing your branch.
  • Explain your idea and experiment.
  • Share your results regularly. (Tensorboard log files, audio results, visuals etc.)

Major TODOs

Acknowledgement