Skip to content

[OpenVINO-Enable]🐸💬 - a deep learning toolkit for Text-to-Speech, battle-tested in research and production

License

Notifications You must be signed in to change notification settings

18582088138/TTS-OV-xkd

This branch is 1 commit ahead of, 1 commit behind zhaohb/TTS-OV:dev.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

d20f52d · Jul 29, 2024
Dec 11, 2023
Jul 29, 2024
Nov 24, 2023
Dec 12, 2023
Apr 28, 2021
Nov 16, 2023
Nov 7, 2023
Sep 26, 2023
Dec 27, 2023
Jun 15, 2020
Nov 15, 2022
Nov 6, 2023
Dec 12, 2022
Jun 28, 2023
Jun 30, 2023
Mar 16, 2022
Mar 7, 2021
Dec 17, 2020
Dec 8, 2023
Nov 24, 2023
Feb 13, 2018
Jul 12, 2022
Dec 11, 2023
Jul 25, 2024
Jul 24, 2021
Sep 27, 2023
May 12, 2022
Oct 20, 2023
May 3, 2021
Dec 27, 2023
Jul 19, 2022
Jun 22, 2023
Jul 24, 2023

Repository files navigation

Click here to expand/collapse content
    ## 🐸Coqui.ai News - 📣 ⓍTTSv2 is here with 16 languages and better performance across the board. - 📣 ⓍTTS fine-tuning code is out. Check the [example recipes](https://github.com/coqui-ai/TTS/tree/dev/recipes/ljspeech). - 📣 ⓍTTS can now stream with <200ms latency. - 📣 ⓍTTS, our production TTS model that can speak 13 languages, is released [Blog Post](https://coqui.ai/blog/tts/open_xtts), [Demo](https://huggingface.co/spaces/coqui/xtts), [Docs](https://tts.readthedocs.io/en/dev/models/xtts.html) - 📣 [🐶Bark](https://github.com/suno-ai/bark) is now available for inference with unconstrained voice cloning. [Docs](https://tts.readthedocs.io/en/dev/models/bark.html) - 📣 You can use [~1100 Fairseq models](https://github.com/facebookresearch/fairseq/tree/main/examples/mms) with 🐸TTS. - 📣 🐸TTS now supports 🐢Tortoise with faster inference. [Docs](https://tts.readthedocs.io/en/dev/models/tortoise.html)

    🐸TTS is a library for advanced Text-to-Speech generation.

    🚀 Pretrained models in +1100 languages.

    🛠️ Tools for training new models and fine-tuning existing models in any language.

    📚 Utilities for dataset analysis and curation.


    Discord License PyPI version Covenant Downloads DOI

    GithubActions GithubActions GithubActions GithubActions GithubActions GithubActions GithubActions GithubActions GithubActions GithubActions GithubActions Docs


    💬 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.

    Type Platforms
    🚨 Bug Reports GitHub Issue Tracker
    🎁 Feature Requests & Ideas GitHub Issue Tracker
    👩‍💻 Usage Questions GitHub Discussions
    🗯 General Discussion GitHub Discussions or Discord

    🔗 Links and Resources

    Type Links
    💼 Documentation ReadTheDocs
    💾 Installation TTS/README.md
    👩‍💻 Contributing CONTRIBUTING.md
    📌 Road Map Main Development Plans
    🚀 Released Models TTS Releases and Experimental Models
    📰 Papers TTS Papers

    🥇 TTS Performance

    Underlined "TTS*" and "Judy*" are internal 🐸TTS models that are not released open-source. They are here to show the potential. Models prefixed with a dot (.Jofish .Abe and .Janice) are real human voices.

    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 the terminal and Tensorboard.
    • Support for Multi-speaker TTS.
    • Efficient, flexible, lightweight but feature complete Trainer API.
    • Released and ready-to-use models.
    • Tools to curate Text2Speech datasets underdataset_analysis.
    • Utilities to use and test your models.
    • Modular (but not too much) code base enabling easy implementation of new ideas.

    Model Implementations

    Spectrogram models

    End-to-End Models

    Attention Methods

    • Guided Attention: paper
    • Forward Backward Decoding: paper
    • Graves Attention: paper
    • Double Decoder Consistency: blog
    • Dynamic Convolutional Attention: paper
    • Alignment Network: paper

    Speaker Encoder

    Vocoders

    Voice Conversion

    You can also help us implement more models.

    Installation

    🐸TTS is tested on Ubuntu 18.04 with python >= 3.9, < 3.12..

    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/coqui-ai/TTS
    pip install -e .[all,dev,notebooks]  # Select the relevant extras

    If you are on Ubuntu (Debian), you can also run following commands for installation.

    $ make system-deps  # intended to be used on Ubuntu (Debian). Let us know if you have a different OS.
    $ make install

    If you are on Windows, 👑@GuyPaddock wrote installation instructions here.

    Docker Image

    You can also try TTS without install with the docker image. Simply run the following command and you will be able to run TTS without installing it.

    docker run --rm -it -p 5002:5002 --entrypoint /bin/bash ghcr.io/coqui-ai/tts-cpu
    python3 TTS/server/server.py --list_models #To get the list of available models
    python3 TTS/server/server.py --model_name tts_models/en/vctk/vits # To start a server

    You can then enjoy the TTS server here More details about the docker images (like GPU support) can be found here

    Synthesizing speech by 🐸TTS

    🐍 Python API

    Running a multi-speaker and multi-lingual model

    import torch
    from TTS.api import TTS
    
    # Get device
    device = "cuda" if torch.cuda.is_available() else "cpu"
    
    # List available 🐸TTS models
    print(TTS().list_models())
    
    # Init TTS
    tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
    
    # Run TTS
    # ❗ Since this model is multi-lingual voice cloning model, we must set the target speaker_wav and language
    # Text to speech list of amplitude values as output
    wav = tts.tts(text="Hello world!", speaker_wav="my/cloning/audio.wav", language="en")
    # Text to speech to a file
    tts.tts_to_file(text="Hello world!", speaker_wav="my/cloning/audio.wav", language="en", file_path="output.wav")

    Running a single speaker model

    # Init TTS with the target model name
    tts = TTS(model_name="tts_models/de/thorsten/tacotron2-DDC", progress_bar=False).to(device)
    
    # Run TTS
    tts.tts_to_file(text="Ich bin eine Testnachricht.", file_path=OUTPUT_PATH)
    
    # Example voice cloning with YourTTS in English, French and Portuguese
    tts = TTS(model_name="tts_models/multilingual/multi-dataset/your_tts", progress_bar=False).to(device)
    tts.tts_to_file("This is voice cloning.", speaker_wav="my/cloning/audio.wav", language="en", file_path="output.wav")
    tts.tts_to_file("C'est le clonage de la voix.", speaker_wav="my/cloning/audio.wav", language="fr-fr", file_path="output.wav")
    tts.tts_to_file("Isso é clonagem de voz.", speaker_wav="my/cloning/audio.wav", language="pt-br", file_path="output.wav")

    Example voice conversion

    Converting the voice in source_wav to the voice of target_wav

    tts = TTS(model_name="voice_conversion_models/multilingual/vctk/freevc24", progress_bar=False).to("cuda")
    tts.voice_conversion_to_file(source_wav="my/source.wav", target_wav="my/target.wav", file_path="output.wav")

    Example voice cloning together with the voice conversion model.

    This way, you can clone voices by using any model in 🐸TTS.

    tts = TTS("tts_models/de/thorsten/tacotron2-DDC")
    tts.tts_with_vc_to_file(
        "Wie sage ich auf Italienisch, dass ich dich liebe?",
        speaker_wav="target/speaker.wav",
        file_path="output.wav"
    )

    Example text to speech using Fairseq models in ~1100 languages 🤯.

    For Fairseq models, use the following name format: tts_models/<lang-iso_code>/fairseq/vits. You can find the language ISO codes here and learn about the Fairseq models here.

    # TTS with on the fly voice conversion
    api = TTS("tts_models/deu/fairseq/vits")
    api.tts_with_vc_to_file(
        "Wie sage ich auf Italienisch, dass ich dich liebe?",
        speaker_wav="target/speaker.wav",
        file_path="output.wav"
    )

    Command-line tts

    Synthesize speech on command line.

    You can either use your trained model or choose a model from the provided list.

    If you don't specify any models, then it uses LJSpeech based English model.

    Single Speaker Models

    • List provided models:

      $ tts --list_models
      
    • Get model info (for both tts_models and vocoder_models):

      • Query by type/name: The model_info_by_name uses the name as it from the --list_models.

        $ tts --model_info_by_name "<model_type>/<language>/<dataset>/<model_name>"
        

        For example:

        $ tts --model_info_by_name tts_models/tr/common-voice/glow-tts
        $ tts --model_info_by_name vocoder_models/en/ljspeech/hifigan_v2
        
      • Query by type/idx: The model_query_idx uses the corresponding idx from --list_models.

        $ tts --model_info_by_idx "<model_type>/<model_query_idx>"
        

        For example:

        $ tts --model_info_by_idx tts_models/3
        
      • Query info for model info by full name:

        $ tts --model_info_by_name "<model_type>/<language>/<dataset>/<model_name>"
        
    • Run TTS with default models:

      $ tts --text "Text for TTS" --out_path output/path/speech.wav
      
    • Run TTS and pipe out the generated TTS wav file data:

      $ tts --text "Text for TTS" --pipe_out --out_path output/path/speech.wav | aplay
      
    • Run a TTS model with its default vocoder model:

      $ tts --text "Text for TTS" --model_name "<model_type>/<language>/<dataset>/<model_name>" --out_path output/path/speech.wav
      

      For example:

      $ tts --text "Text for TTS" --model_name "tts_models/en/ljspeech/glow-tts" --out_path output/path/speech.wav
      
    • Run with specific TTS and vocoder models from the list:

      $ tts --text "Text for TTS" --model_name "<model_type>/<language>/<dataset>/<model_name>" --vocoder_name "<model_type>/<language>/<dataset>/<model_name>" --out_path output/path/speech.wav
      

      For example:

      $ tts --text "Text for TTS" --model_name "tts_models/en/ljspeech/glow-tts" --vocoder_name "vocoder_models/en/ljspeech/univnet" --out_path output/path/speech.wav
      
    • Run your own TTS model (Using Griffin-Lim Vocoder):

      $ tts --text "Text for TTS" --model_path path/to/model.pth --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/model.pth --config_path path/to/config.json --out_path output/path/speech.wav
          --vocoder_path path/to/vocoder.pth --vocoder_config_path path/to/vocoder_config.json
      

    Multi-speaker Models

    • List the available speakers and choose a <speaker_id> among them:

      $ tts --model_name "<language>/<dataset>/<model_name>"  --list_speaker_idxs
      
    • Run the multi-speaker TTS model with the target speaker ID:

      $ tts --text "Text for TTS." --out_path output/path/speech.wav --model_name "<language>/<dataset>/<model_name>"  --speaker_idx <speaker_id>
      
    • Run your own multi-speaker TTS model:

      $ tts --text "Text for TTS" --out_path output/path/speech.wav --model_path path/to/model.pth --config_path path/to/config.json --speakers_file_path path/to/speaker.json --speaker_idx <speaker_id>
      

    Voice Conversion Models

    $ tts --out_path output/path/speech.wav --model_name "<language>/<dataset>/<model_name>" --source_wav <path/to/speaker/wav> --target_wav <path/to/reference/wav>
    

    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.)
          |- ...
        |- tts/             (text to speech models)
            |- layers/          (model layer definitions)
            |- models/          (model definitions)
            |- utils/           (model specific utilities.)
        |- speaker_encoder/ (Speaker Encoder models.)
            |- (same)
        |- vocoder/         (Vocoder models.)
            |- (same)
    

Update Notes

2024/07/23

  1. XTTS-V2 model supports using openvino to accelerate the inference process. Currently only verified on Linux system.

2024/07/24

  1. Support sdpa optimization

2024/07/25

  1. Expose device options to support different devices

Running Guide

Installation

🐸TTS is tested on Ubuntu 18.04 with python >= 3.9, < 3.12..

git clone https://github.com/zhaohb/TTS-OV.git
pip install openvino_dev # Optional, you can compile openvino yourself and use sdpa optimization. [Optional Optimization]
pip install onnx
cd TTS-OV
pip install -r requirements.txt
pip install transformers==4.42.4
pip install -e . 

Using the model directly:

import os
import torch
import torchaudio
from TTS.tts.configs.xtts_config import XttsConfig
from TTS.tts.models.xtts import Xtts
from TTS.tts.models.xtts_model import GPTModel, HifiModel, GPTInferModel, GPTInferPastModel
import time
import numpy as np

print("Loading model...")
config = XttsConfig()
config.load_json("/home/emr/hongbo/models/XTTS-v2/config.json")
model = Xtts.init_from_config(config)
model.load_checkpoint(config, checkpoint_dir="/home/emr/hongbo/models/XTTS-v2")

gpt_cond_latent, speaker_embedding = model.get_conditioning_latents(audio_path=["en_sample.wav", "en_sample.wav"])

gpt_ov_model = GPTModel(model=model, device='CPU')
hifi_ov_model = HifiModel(model=model, device='CPU')
gpt_infer_model = GPTInferModel(model=model, device='CPU')
gpt_infer_past_model=GPTInferPastModel(model=model, device='CPU')

print("Ov Inference...")
out = model.inference(
    "OpenVINO is an open-source software toolkit for optimizing and deploying deep learning models. It enables programmers to develop scalable and efficient AI solutions with relatively few lines of code. It supports several popular model formats.",
    "en",
    # " OpenVINO是一个开源工具包,可优化和部署深度学习模型。它提供了针对视觉、音频和语言模型的深度学习性能加速,支持流行框架。",
    # "zh-cn",
    gpt_cond_latent,
    speaker_embedding,
    temperature=0.7, # Add custom parameters here
    use_ov = True,
    gpt_ov_model=gpt_ov_model,
    hifi_ov_model=hifi_ov_model,
    gpt_infer_model=gpt_infer_model,
    gpt_infer_past_model=gpt_infer_past_model,
)
torchaudio.save("ov_test.wav", torch.tensor(out["wav"]).unsqueeze(0), 24000)

Optional Optimization

By default, we use the official release of openvino, but the official version of OpenVINO sdpa and stateful optimization are bundled together, and we are now using stateless, so we cannot use sdpa optimization. However, we can choose to use the enable_sdpa_stateless branch of openvino to ensure that XTTS-V2 can use sdpa optimization.

Get the openvino code:

  git clone https://github.com/zhangYiIntel/openvino.git
  cd openvino/
  git checkout remotes/origin/yi3/enable_sdpa_stateless -b enable_sdpa_stateless

We can refer to this link Build OpenVINO™ Runtime for Linux systems to compile and install openvino.

After compiling and installing, we can use sdpa optimization. Maybe The speed of inference will shock you.

About

[OpenVINO-Enable]🐸💬 - a deep learning toolkit for Text-to-Speech, battle-tested in research and production

Resources

License

Code of conduct

Citation

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 92.2%
  • Jupyter Notebook 7.3%
  • HTML 0.3%
  • Shell 0.1%
  • Makefile 0.1%
  • Cython 0.0%