### Install and run the XTTS fine-tuning demo locally Source: https://coqui-tts.readthedocs.io/en/latest/models/xtts.html Commands to install necessary dependencies and launch the Gradio fine-tuning interface. ```bash pip install coqui-tts ``` ```bash pip install gradio faster_whisper ``` ```bash python3 -m TTS.demos.xtts_ft_demo.xtts_demo ``` -------------------------------- ### Start Training Source: https://coqui-tts.readthedocs.io/en/latest/tutorial_for_nervous_beginners.html To start a new training run, execute this command. Ensure CUDA_VISIBLE_DEVICES is set to the desired GPU. ```bash CUDA_VISIBLE_DEVICES=0 python train.py ``` -------------------------------- ### Start Docker Compose Source: https://coqui-tts.readthedocs.io/en/latest/_sources/docker_images.md.txt Command to start the services defined in your Docker Compose file. ```bash docker-compose up ``` -------------------------------- ### Install Coqui TTS using make on Ubuntu Source: https://coqui-tts.readthedocs.io/en/latest/installation.html After installing system dependencies, use this make command to complete the installation of Coqui TTS on Ubuntu. ```bash make install ``` -------------------------------- ### Install PyTorch, torchaudio, and torchcodec with uv Source: https://coqui-tts.readthedocs.io/en/latest/installation.html Use this command to install PyTorch and related libraries, letting uv automatically select the appropriate versions for your system. This is recommended before installing Coqui TTS if you plan to use PyTorch. ```bash uv pip install torch torchaudio torchcodec --torch-backend=auto ``` -------------------------------- ### Start CPU TTS Server Source: https://coqui-tts.readthedocs.io/en/latest/_sources/docker_images.md.txt Launch a TTS server using the CPU Docker image and get a shell inside the container to run server commands. ```bash docker run --rm -it -p 5002:5002 --entrypoint /bin/bash ghcr.io/idiap/coqui-tts-cpu ``` ```bash tts-server --list_models #To get the list of available models ``` ```bash tts-server --model_name tts_models/en/vctk/vits ``` -------------------------------- ### Install Coqui TTS from source Source: https://coqui-tts.readthedocs.io/en/latest/installation.html Clone the Coqui TTS repository and install it locally in editable mode using uv. This method is recommended if you plan to develop or train models. ```bash git clone https://github.com/idiap/coqui-ai-TTS cd coqui-ai-TTS uv pip install -e . ``` -------------------------------- ### Start Fine-tuning with TTS/bin/train_tts.py Source: https://coqui-tts.readthedocs.io/en/latest/_sources/training/finetuning.md.txt Starts fine-tuning using the generic training script. Requires paths to both the model config and the pre-trained model file. ```bash CUDA_VISIBLE_DEVICES="0" python TTS/bin/train_tts.py \ --config_path /home/ubuntu/.local/share/tts/tts_models--en--ljspeech--glow-tts/config.json \ --restore_path /home/ubuntu/.local/share/tts/tts_models--en--ljspeech--glow-tts/model_file.pth ``` -------------------------------- ### Start TTS Server with GPU Docker Image Source: https://coqui-tts.readthedocs.io/en/latest/docker_images.html Launch a TTS server using the GPU Docker image. This command enables GPU acceleration and gets a shell inside the container. ```bash docker run --rm -it -p 5002:5002 --gpus all --entrypoint /bin/bash ghcr.io/idiap/coqui-tts tts-server --list_models #To get the list of available models tts-server --model_name tts_models/en/vctk/vits --use_cuda ``` -------------------------------- ### Install system dependencies on Ubuntu Source: https://coqui-tts.readthedocs.io/en/latest/installation.html Run this command on Ubuntu systems to install necessary system-level dependencies for Coqui TTS. ```bash make system-deps ``` -------------------------------- ### Start Training with JSON Config Source: https://coqui-tts.readthedocs.io/en/latest/tutorial_for_nervous_beginners.html Execute the training script with the --config_path argument pointing to your JSON configuration file. ```bash $ CUDA_VISIBLE_DEVICES="0" python TTS/bin/train_tts.py --config_path config.json ``` -------------------------------- ### Start TTS Server with CPU Docker Image Source: https://coqui-tts.readthedocs.io/en/latest/docker_images.html Launch a TTS server using the CPU Docker image. This command gets a shell inside the container to run server commands. ```bash docker run --rm -it -p 5002:5002 --entrypoint /bin/bash ghcr.io/idiap/coqui-tts-cpu tts-server --list_models #To get the list of available models tts-server --model_name tts_models/en/vctk/vits ``` -------------------------------- ### Install Coqui TTS from PyPI Source: https://coqui-tts.readthedocs.io/en/latest/installation.html Install the Coqui TTS package from the Python Package Index (PyPI) using uv. This is the simplest method if you only need to synthesize speech with pretrained models. ```bash uv pip install coqui-tts ``` -------------------------------- ### Start Fine-tuning with recipes/ljspeech/glow_tts/train_glowtts.py Source: https://coqui-tts.readthedocs.io/en/latest/_sources/training/finetuning.md.txt Initiates fine-tuning using a specific training script. Requires the path to the pre-trained model file. ```bash CUDA_VISIBLE_DEVICES="0" python recipes/ljspeech/glow_tts/train_glowtts.py \ --restore_path /home/ubuntu/.local/share/tts/tts_models--en--ljspeech--glow-tts/model_file.pth ``` -------------------------------- ### Multi-speaker Training Setup Source: https://coqui-tts.readthedocs.io/en/latest/training/training_a_model.html Python script demonstrating the setup for multi-speaker training in Coqui TTS. This includes importing necessary modules for trainers, configurations, datasets, models, and utilities. ```python import os from trainer import Trainer, TrainerArgs from TTS.config.shared_configs import BaseAudioConfig from TTS.tts.configs.glow_tts_config import GlowTTSConfig from TTS.tts.configs.shared_configs import BaseDatasetConfig from TTS.tts.datasets import load_tts_samples from TTS.tts.models.glow_tts import GlowTTS from TTS.tts.utils.speakers import SpeakerManager from TTS.tts.utils.text.tokenizer import TTSTokenizer from TTS.utils.audio import AudioProcessor ``` -------------------------------- ### Example Training Log Output Source: https://coqui-tts.readthedocs.io/en/latest/training/training_a_model.html This is a sample of the initial output from a training log, showing experiment details, hardware configuration, audio processor settings, and initial training metrics. ```text > Experiment folder: /your/output_path/-Juni-23-2021_02+52-78899209 > Using CUDA: True > Number of GPUs: 1 > Setting up Audio Processor... | > sample_rate:22050 | > resample:False | > num_mels:80 | > min_level_db:-100 | > frame_shift_ms:None | > frame_length_ms:None | > ref_level_db:20 | > fft_size:1024 | > power:1.5 | > preemphasis:0.0 | > griffin_lim_iters:60 | > signal_norm:True | > symmetric_norm:True | > mel_fmin:0 | > mel_fmax:None | > spec_gain:20.0 | > stft_pad_mode:reflect | > max_norm:4.0 | > clip_norm:True | > do_trim_silence:True | > trim_db:45 | > do_sound_norm:False | > stats_path:None | > base:10 | > hop_length:256 | > win_length:1024 | > Found 13100 files in /your/dataset/path/ljspeech/LJSpeech-1.1 > Using model: glow_tts > Model has 28356129 parameters > EPOCH: 0/1000 > DataLoader initialization | > Use phonemes: False | > Number of instances : 12969 | > Max length sequence: 187 | > Min length sequence: 5 | > Avg length sequence: 98.3403500655409 | > Num. instances discarded by max-min (max=500, min=3) seq limits: 0 | > Batch group size: 0. > TRAINING (2021-06-23 14:52:54) --> STEP: 0/405 -- GLOBAL_STEP: 0 | > loss: 2.34670 | > log_mle: 1.61872 | > loss_dur: 0.72798 | > align_error: 0.52744 | > current_lr: 2.5e-07 | > grad_norm: 5.036039352416992 | > step_time: 5.8815 | > loader_time: 0.0065 ... ``` -------------------------------- ### Python Training Script Setup Source: https://coqui-tts.readthedocs.io/en/latest/tutorial_for_nervous_beginners.html This script sets up the training environment by defining dataset configurations, initializing the audio processor and tokenizer, loading training samples, and initializing the model and trainer. It's the core script for initiating a training run. ```python output_path = os.path.dirname(os.path.abspath(__file__)) def main(): # DEFINE DATASET CONFIG # Set LJSpeech as our target dataset and define its path. # You can also use a simple Dict to define the dataset and pass it to your custom formatter. dataset_config = BaseDatasetConfig( formatter="ljspeech", meta_file_train="metadata.csv", path=os.path.join(output_path, "../LJSpeech-1.1/") ) # INITIALIZE THE TRAINING CONFIGURATION # Configure the model. Every config class inherits the BaseTTSConfig. config = GlowTTSConfig( batch_size=32, eval_batch_size=16, num_loader_workers=4, num_eval_loader_workers=4, run_eval=True, test_delay_epochs=-1, epochs=1000, text_cleaner="phoneme_cleaners", use_phonemes=True, phoneme_language="en-us", phoneme_cache_path=os.path.join(output_path, "phoneme_cache"), print_step=25, print_eval=False, mixed_precision=True, output_path=output_path, datasets=[dataset_config], ) # INITIALIZE THE AUDIO PROCESSOR # Audio processor is used for feature extraction and audio I/O. # It mainly serves to the dataloader and the training loggers. ap = AudioProcessor.init_from_config(config) # INITIALIZE THE TOKENIZER # Tokenizer is used to convert text to sequences of token IDs. # If characters are not defined in the config, default characters are passed to the config tokenizer, config = TTSTokenizer.init_from_config(config) # LOAD DATA SAMPLES # Each sample is a list of ```[text, audio_file_path, speaker_name]``` # You can define your custom sample loader returning the list of samples. # Or define your custom formatter and pass it to the `load_tts_samples`. # Check `TTS.tts.datasets.load_tts_samples` for more details. train_samples, eval_samples = load_tts_samples( dataset_config, eval_split=True, eval_split_max_size=config.eval_split_max_size, eval_split_size=config.eval_split_size, ) # INITIALIZE THE MODEL # Models take a config object and a speaker manager as input # Config defines the details of the model like the number of layers, the size of the embedding, etc. # Speaker manager is used by multi-speaker models. model = GlowTTS(config, ap, tokenizer, speaker_manager=None) # INITIALIZE THE TRAINER # Trainer provides a generic API to train all the 🐸TTS models with all its perks like mixed-precision training, # distributed training, etc. trainer = Trainer( TrainerArgs(), config, output_path, model=model, train_samples=train_samples, eval_samples=eval_samples ) # AND... 3,2,1... 🚀 trainer.fit() if __name__ == "__main__": main() ``` -------------------------------- ### Install uv for Environment Management Source: https://coqui-tts.readthedocs.io/en/latest/contributing.html Installs the uv tool for managing Python virtual environments. This is a prerequisite for setting up the development environment. ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` -------------------------------- ### Run TTS Model Source: https://coqui-tts.readthedocs.io/en/latest/_sources/server.md.txt Basic command to start the server with a specific model from the release list. ```bash tts-server --model_name "///" ``` -------------------------------- ### Install Development Dependencies Source: https://coqui-tts.readthedocs.io/en/latest/contributing.html Installs system dependencies and development packages for Coqui TTS. Assumes an Ubuntu/Debian-based system for system dependencies. ```bash make system-deps # intended to be used on Ubuntu (Debian). Let us know if you have a different OS. make install_dev ``` -------------------------------- ### Install Coqui TTS from source with optional server and Japanese G2P dependencies Source: https://coqui-tts.readthedocs.io/en/latest/installation.html Install Coqui TTS from source in editable mode, including optional dependencies for the TTS server and Japanese language processing (G2P). ```bash uv pip install -e .[server,ja] ``` -------------------------------- ### Start GPU TTS Server Source: https://coqui-tts.readthedocs.io/en/latest/_sources/docker_images.md.txt Launch a TTS server using the GPU Docker image and enable CUDA. Access the web interface at http://localhost:5002. ```bash docker run --rm -it -p 5002:5002 --gpus all --entrypoint /bin/bash ghcr.io/idiap/coqui-tts ``` ```bash tts-server --list_models #To get the list of available models ``` ```bash tts-server --model_name tts_models/en/vctk/vits --use_cuda ``` -------------------------------- ### Install Coqui TTS with optional server and Japanese G2P dependencies Source: https://coqui-tts.readthedocs.io/en/latest/installation.html Install Coqui TTS with specific optional dependencies, such as those required for the TTS server and Japanese language processing (G2P). ```bash uv pip install coqui-tts[server,ja] ``` -------------------------------- ### Install DeepSpeed for Faster Inference Source: https://coqui-tts.readthedocs.io/en/latest/_sources/models/xtts.md.txt Installs the DeepSpeed library, which is required for faster model loading and inference when `use_deepspeed=True` is specified. ```bash pip install deepspeed ``` -------------------------------- ### List Available TTS Models Source: https://coqui-tts.readthedocs.io/en/latest/server.html Use this command to see all the TTS models that are available for use with the server. Ensure you have installed the server dependencies. ```bash tts-server --list_models ``` -------------------------------- ### Start TTS Training via CLI Source: https://coqui-tts.readthedocs.io/en/latest/_sources/tutorial_for_nervous_beginners.md.txt Launches TTS model training using a specified JSON configuration file. This method is an alternative to running a Python script directly. ```bash $ CUDA_VISIBLE_DEVICES="0" python TTS/bin/train_tts.py --config_path config.json ``` -------------------------------- ### Initialize and Train GlowTTS Model Source: https://coqui-tts.readthedocs.io/en/latest/training/training_a_model.html This script initializes the dataset, audio processor, tokenizer, and the GlowTTS model, then starts the training process. Ensure dataset_config and GlowTTSConfig are updated to match your dataset and desired model parameters. ```python output_path = os.path.dirname(os.path.abspath(__file__)) def main(): # DEFINE DATASET CONFIG # Set LJSpeech as our target dataset and define its path. # You can also use a simple Dict to define the dataset and pass it to your custom formatter. dataset_config = BaseDatasetConfig( formatter="ljspeech", meta_file_train="metadata.csv", path=os.path.join(output_path, "../LJSpeech-1.1/") ) # INITIALIZE THE TRAINING CONFIGURATION # Configure the model. Every config class inherits the BaseTTSConfig. config = GlowTTSConfig( batch_size=32, eval_batch_size=16, num_loader_workers=4, num_eval_loader_workers=4, run_eval=True, test_delay_epochs=-1, epochs=1000, text_cleaner="phoneme_cleaners", use_phonemes=True, phoneme_language="en-us", phoneme_cache_path=os.path.join(output_path, "phoneme_cache"), print_step=25, print_eval=False, mixed_precision=True, output_path=output_path, datasets=[dataset_config], ) # INITIALIZE THE AUDIO PROCESSOR # Audio processor is used for feature extraction and audio I/O. # It mainly serves to the dataloader and the training loggers. ap = AudioProcessor.init_from_config(config) # INITIALIZE THE TOKENIZER # Tokenizer is used to convert text to sequences of token IDs. # If characters are not defined in the config, default characters are passed to the config tokenizer, config = TTSTokenizer.init_from_config(config) # LOAD DATA SAMPLES # Each sample is a list of ```[text, audio_file_path, speaker_name]``` # You can define your custom sample loader returning the list of samples. # Or define your custom formatter and pass it to the `load_tts_samples`. # Check `TTS.tts.datasets.load_tts_samples` for more details. train_samples, eval_samples = load_tts_samples( dataset_config, eval_split=True, eval_split_max_size=config.eval_split_max_size, eval_split_size=config.eval_split_size, ) # INITIALIZE THE MODEL # Models take a config object and a speaker manager as input # Config defines the details of the model like the number of layers, the size of the embedding, etc. # Speaker manager is used by multi-speaker models. model = GlowTTS(config, ap, tokenizer, speaker_manager=None) # INITIALIZE THE TRAINER # Trainer provides a generic API to train all the 🐸TTS models with all its perks like mixed-precision training, # distributed training, etc. trainer = Trainer( TrainerArgs(), config, output_path, model=model, train_samples=train_samples, eval_samples=eval_samples ) # AND... 3,2,1... 🚀 trainer.fit() if __name__ == "__main__": main() ``` -------------------------------- ### Run TTS with Vocoder Source: https://coqui-tts.readthedocs.io/en/latest/_sources/server.md.txt Start the server using both a TTS model and a compatible vocoder model. ```bash tts-server --model_name "///" \ --vocoder_name "///" ``` -------------------------------- ### Start TTS Model Training Source: https://coqui-tts.readthedocs.io/en/latest/_sources/tutorial_for_nervous_beginners.md.txt Initiates the training process for a TTS model using a Python script. Ensure CUDA is available for GPU acceleration. ```bash CUDA_VISIBLE_DEVICES=0 python train.py ``` -------------------------------- ### Synthesize Speech with Coqui TTS Command Line Source: https://coqui-tts.readthedocs.io/en/latest/models/bark.html Provides command-line examples for using the Bark model with Coqui TTS. Demonstrates cloning a voice using a reference audio file and generating speech with a random voice. ```bash # Clone the `ljspeech` voice and cache it under that ID for later reuse without reference audio. tts --model_name tts_models/multilingual/multi-dataset/bark \ --text "This is an example." --out_path "output.wav" \ --speaker_wav tests/data/ljspeech/wavs/*.wav --speaker_idx "ljspeech" # Random voice generation tts --model_name tts_models/multilingual/multi-dataset/bark \ --text "This is an example." --out_path "output.wav" ``` -------------------------------- ### Command-line Interface for Voice Cloning Source: https://coqui-tts.readthedocs.io/en/latest/_sources/cloning.md.txt Provides command-line examples for cloning voices using the Coqui TTS CLI, including caching and reuse. ```APIDOC ## Command-line Interface for Voice Cloning ### Description This section demonstrates how to perform voice cloning using the Coqui TTS command-line interface (CLI). It includes examples for cloning a voice from reference audio and then reusing the cached voice. ### Method `tts` command ### Parameters #### Command-line Arguments - **--model_name** (string) - Required - The name of the TTS model to use (e.g., `tts_models/multilingual/multi-dataset/xtts_v2`). - **--text** (string) - Required - The text to synthesize. - **--language_idx** (string) - Required - The language code for synthesis (e.g., `en`). - **--speaker_wav** (string) - Required (for cloning) - Path(s) to reference audio file(s) for voice cloning. - **--speaker_idx** (string) - Optional - A custom speaker ID for caching the cloned voice. - **--voice_dir** (string) - Optional - Directory to store cached voices. ### Request Example ```bash # 1. Clone the voice from `speaker_wav` and cache it under a custom speaker ID tts --model_name "tts_models/multilingual/multi-dataset/xtts_v2" \ --text "Hello world" \ --language_idx "en" \ --speaker_wav "my/cloning/audio.wav" "my/cloning/audio2.wav" \ --speaker_idx "MySpeaker1" # 2. The voice can now be reused without providing reference audio tts --model_name "tts_models/multilingual/multi-dataset/xtts_v2" \ --text "Hello world" \ --language_idx "en" \ --speaker_idx "MySpeaker1" ``` ### Response #### Success Response (File Output) - The synthesized speech is saved to a file. ``` -------------------------------- ### Docker Compose Configuration Source: https://coqui-tts.readthedocs.io/en/latest/_sources/docker_images.md.txt Example Docker Compose configuration for running Coqui TTS CPU version. This sets up the service, port, and entrypoint. ```yaml services: coqui: image: ghcr.io/idiap/coqui-tts-cpu container_name: coqui ports: - "5002:5002" entrypoint: /bin/bash command: -c "tts-server --model_name tts_models/multilingual/multi-dataset/xtts_v2" ``` -------------------------------- ### XTTS Inference - Command Line Source: https://coqui-tts.readthedocs.io/en/latest/_sources/models/xtts.md.txt Examples of using the XTTS model via the command line for listing languages, speakers, and performing inference with specific speakers or cloned voices. ```APIDOC ## XTTS Inference - Command Line ### List Supported Languages ```console tts --model_name tts_models/multilingual/multi-dataset/xtts_v2 \ --list_language_idx ``` ### List Available Coqui Speakers ```console >>> tts --model_name tts_models/multilingual/multi-dataset/xtts_v2 \ --list_speaker_idx ['Claribel Dervla', 'Daisy Studious', 'Gracie Wise', 'Tammie Ema', 'Alison Dietlinde', 'Ana Florence', 'Annmarie Nele', 'Asya Anara', 'Brenda Stern', 'Gitta Nikolina', 'Henriette Usha', 'Sofia Hellen', 'Tammy Grit', 'Tanja Adelina', 'Vjollca Johnnie', 'Andrew Chipper', 'Badr Odhiambo', 'Dionisio Schuyler', 'Royston Min', 'Viktor Eka', 'Abrahan Mack', 'Adde Michal', 'Baldur Sanjin', 'Craig Gutsy', 'Damien Black', 'Gilberto Mathias', 'Ilkin Urbano', 'Kazuhiko Atallah', 'Ludvig Milivoj', 'Suad Qasim', 'Torcull Diarmuid', 'Viktor Menelaos', 'Zacharie Aimilios', 'Nova Hogarth', 'Maja Ruoho', 'Uta Obando', 'Lidiya Szekeres', 'Chandra MacFarland', 'Szofi Granger', 'Camilla Holmström', 'Lilya Stainthorpe', 'Zofija Kendrick', 'Narelle Moon', 'Barbora MacLean', 'Alexandra Hisakawa', 'Alma María', 'Rosemary Okafor', 'Ige Behringer', 'Filip Traverse', 'Damjan Chapman', 'Wulf Carlevaro', 'Aaron Dreschner', 'Kumar Dahl', 'Eugenio Mataracı', 'Ferran Simen', 'Xavier Hayasaka', 'Luis Moray', 'Marcos Rudaski'] ``` ### Inference with a Coqui Speaker ```console tts --model_name tts_models/multilingual/multi-dataset/xtts_v2 \ --text "It took me quite a long time to develop a voice, and now that I have it I'm not going to be silent." \ --speaker_idx "Ana Florence" \ --language_idx en \ --use_cuda ``` ### Voice Cloning - Single Reference ```console tts --model_name tts_models/multilingual/multi-dataset/xtts_v2 \ --text "Bugün okula gitmek istemiyorum." \ --speaker_wav /path/to/target/speaker.wav \ --language_idx tr \ --use_cuda ``` ### Voice Cloning - Multiple References ```console tts --model_name tts_models/multilingual/multi-dataset/xtts_v2 \ --text "Bugün okula gitmek istemiyorum." \ --speaker_wav /path/to/target/speaker.wav /path/to/target/speaker_2.wav /path/to/target/speaker_3.wav \ --language_idx tr \ --use_cuda ``` ### Voice Cloning - All WAV files in a directory ```console tts --model_name tts_models/multilingual/multi-dataset/xtts_v2 \ --text "Bugün okula gitmek istemiyorum." \ --speaker_wav /path/to/target/*.wav \ --language_idx tr \ --use_cuda ``` ``` -------------------------------- ### Formatter Output Example Source: https://coqui-tts.readthedocs.io/en/latest/datasets/formatting_your_dataset.html A formatter parses the metadata file and returns a list of dictionaries, each containing audio file path, text, speaker name, and language. ```python >>> formatter(metafile_path) [ {"audio_file":"audio1.wav", "text":"This is my sentence.", "speaker_name":"MyDataset", "language": "lang_code"}, {"audio_file":"audio1.wav", "text":"This is maybe a sentence.", "speaker_name":"MyDataset", "language": "lang_code"}, ... ] ``` -------------------------------- ### Fine-tune with Custom Arguments Source: https://coqui-tts.readthedocs.io/en/latest/training/finetuning.html Fine-tune a model using a training script and override configuration parameters via command-line arguments. This example sets a custom run name and learning rate. ```bash CUDA_VISIBLE_DEVICES="0" python recipes/ljspeech/glow_tts/train_glowtts.py \ --restore_path /home/ubuntu/.local/share/tts/tts_models--en--ljspeech--glow-tts/model_file.pth --coqpit.run_name "glow-tts-finetune" \ --coqpit.lr 0.00001 ``` -------------------------------- ### Build Coqui TTS Docker development image Source: https://coqui-tts.readthedocs.io/en/latest/contributing.html Build the Docker image for development. This command installs all necessary dependencies within the container. Ensure you are in the root directory of the cloned repository. ```bash docker build --tag=tts-dev:latest -f .\dockerfiles\Dockerfile.dev . ``` -------------------------------- ### Synthesize Speech with Coqui TTS API Source: https://coqui-tts.readthedocs.io/en/latest/models/bark.html Shows how to use the Coqui TTS API to synthesize speech with the Bark model. Includes examples for cloning a voice and caching it, reusing a cached voice, and generating speech with a random speaker. Assumes CUDA is available for better performance. ```python from TTS.api import TTS # Load the model to GPU # Bark is really slow on CPU, so we recommend using GPU. tts = TTS("tts_models/multilingual/multi-dataset/bark").to("cuda") # Clone voice and cache it with the custom ID `ljspeech`. tts.tts_to_file(text="Hello, my name is Manmay , how are you?", file_path="output.wav", speaker_wav=["tests/data/ljspeech/wavs/LJ001-0001.wav"], speaker="ljspeech") # When you run it again it uses the stored values to generate the voice. tts.tts_to_file(text="Hello, my name is Manmay , how are you?", file_path="output.wav", speaker="ljspeech") # random speaker tts = TTS("tts_models/multilingual/multi-dataset/bark").to("cuda") tts.tts_to_file("hello world", file_path="out.wav") ``` -------------------------------- ### Monitor training with Tensorboard Source: https://coqui-tts.readthedocs.io/en/latest/_sources/training/training_a_model.md.txt Launch the Tensorboard server pointing to the directory containing training logs. ```bash $ tensorboard --logdir= ``` -------------------------------- ### Load and run synthesis with Synthesizer Source: https://coqui-tts.readthedocs.io/en/latest/_sources/main_classes/synthesizer.md.txt Initializes the Synthesizer using ModelManager to download and load a model, then generates and saves audio. ```python from TTS.utils.manage import ModelManager from TTS.utils.synthesizer import Synthesizer model_path, config_path, _ = ModelManager().download_model("tts_models/en/ljspeech/vits") synth = Synthesizer(tts_checkpoint=model_path, tts_config_path=config_path) wav = synth.tts("Hello World") synth.save_wav(wav, "test_audio.wav") ``` -------------------------------- ### Initialize and synthesize with Bark model Source: https://coqui-tts.readthedocs.io/en/latest/_sources/models/bark.md.txt Directly initialize the Bark model from configuration and perform synthesis with or without voice cloning. ```python text = "Hello, my name is Manmay , how are you?" from TTS.tts.configs.bark_config import BarkConfig from TTS.tts.models.bark import Bark config = BarkConfig() model = Bark.init_from_config(config) model.load_checkpoint(config, checkpoint_dir="path/to/model/dir/", eval=True) # Random speaker output_dict = model.synthesize(text) # Cloning a speaker. output_dict = model.synthesize(text, speaker_wav="path/to/speaker.wav") ``` -------------------------------- ### Execute Model Training Source: https://coqui-tts.readthedocs.io/en/latest/_sources/faq.md.txt Commands to initiate model training on either a single GPU or multiple GPUs. ```bash CUDA_VISIBLE_DEVICES="0" python train_tts.py --config_path config.json ``` ```bash python3 -m trainer.distribute --gpus "0,1" --script TTS/bin/train_tts.py --config_path config.json ``` -------------------------------- ### Uninstall Old TTS and Install Coqui TTS Source: https://coqui-tts.readthedocs.io/en/latest/_sources/faq.md.txt To avoid conflicts, uninstall the original TTS package and its related components before installing coqui-tts. Ensure a clean environment by purging the pip cache. ```bash pip uninstall TTS trainer coqpit pip cache purge pip install coqui-tts ``` -------------------------------- ### Train Multi-speaker Glow-TTS Source: https://coqui-tts.readthedocs.io/en/latest/_sources/training/training_a_model.md.txt Example script for training a Glow-TTS model on the VCTK dataset. ```python {literalinclude} ../../../recipes/vctk/glow_tts/train_glow_tts.py ``` -------------------------------- ### XTTS API Inference Source: https://coqui-tts.readthedocs.io/en/latest/models/xtts.html Examples of using the TTS Python API for voice cloning and speech synthesis. ```APIDOC ## XTTS API Inference ### Voice Cloning - Single Reference This Python code snippet demonstrates how to clone a speaker voice using a single audio reference via the TTS API. #### Parameters - `text` (string) - Required - The text to synthesize. - `file_path` (string) - Required - The path to save the output audio file. - `speaker_wav` (list of strings) - Required - A list containing the path to the target speaker's audio file. - `language` (string) - Required - The language code for synthesis (e.g., 'en'). - `split_sentences` (boolean) - Optional - Whether to split the text into sentences. Defaults to True. #### Request Example ```python from TTS.api import TTS tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to("cuda") tts.tts_to_file(text="It took me quite a long time to develop a voice, and now that I have it I'm not going to be silent.", file_path="output.wav", speaker_wav=["/path/to/target/speaker.wav"], language="en", split_sentences=True ) ``` ``` -------------------------------- ### Manage TTS Server Source: https://coqui-tts.readthedocs.io/en/latest/_sources/server.md.txt Commands to view help documentation and list available models for the TTS server. ```bash tts-server -h # see the help tts-server --list_models # list the available models. ``` -------------------------------- ### XTTS Command Line Inference Source: https://coqui-tts.readthedocs.io/en/latest/models/xtts.html Examples of using the TTS command-line interface for various inference tasks with the XTTS model. ```APIDOC ## XTTS Command Line Inference ### List Supported Languages This command lists all languages supported by the XTTS model. ```bash tts --model_name tts_models/multilingual/multi-dataset/xtts_v2 --list_language_idx ``` ### List Available Speakers This command lists all available Coqui speakers for use with the XTTS model. ```bash tts --model_name tts_models/multilingual/multi-dataset/xtts_v2 --list_speaker_idx ``` ### Inference with a Coqui Speaker This command performs inference using a specified Coqui speaker. #### Parameters - `--model_name` (string) - Required - The name of the XTTS model. - `--text` (string) - Required - The text to synthesize. - `--speaker_idx` (string) - Required - The index of the speaker to use. - `--language_idx` (string) - Required - The language index for synthesis. - `--use_cuda` - Optional - Use CUDA for acceleration. ```bash tts --model_name tts_models/multilingual/multi-dataset/xtts_v2 --text "It took me quite a long time to develop a voice, and now that I have it I'm not going to be silent." --speaker_idx "Ana Florence" --language_idx en --use_cuda ``` ### Voice Cloning - Single Reference This command clones a speaker voice using a single audio reference. #### Parameters - `--model_name` (string) - Required - The name of the XTTS model. - `--text` (string) - Required - The text to synthesize. - `--speaker_wav` (string) - Required - Path to the target speaker's audio file. - `--language_idx` (string) - Required - The language index for synthesis. - `--use_cuda` - Optional - Use CUDA for acceleration. ```bash tts --model_name tts_models/multilingual/multi-dataset/xtts_v2 --text "Bugün okula gitmek istemiyorum." --speaker_wav /path/to/target/speaker.wav --language_idx tr --use_cuda ``` ### Voice Cloning - Multiple References This command clones a speaker voice using multiple audio references. #### Parameters - `--model_name` (string) - Required - The name of the XTTS model. - `--text` (string) - Required - The text to synthesize. - `--speaker_wav` (string array) - Required - Paths to the target speaker's audio files. - `--language_idx` (string) - Required - The language index for synthesis. - `--use_cuda` - Optional - Use CUDA for acceleration. ```bash tts --model_name tts_models/multilingual/multi-dataset/xtts_v2 --text "Bugün okula gitmek istemiyorum." --speaker_wav /path/to/target/speaker.wav /path/to/target/speaker_2.wav /path/to/target/speaker_3.wav --language_idx tr --use_cuda ``` ### Voice Cloning - All WAV files in a directory This command clones a speaker voice using all WAV files in a specified directory. #### Parameters - `--model_name` (string) - Required - The name of the XTTS model. - `--text` (string) - Required - The text to synthesize. - `--speaker_wav` (string) - Required - Path pattern to the target speaker's audio files (e.g., `/path/to/target/*.wav`). - `--language_idx` (string) - Required - The language index for synthesis. - `--use_cuda` - Optional - Use CUDA for acceleration. ```bash tts --model_name tts_models/multilingual/multi-dataset/xtts_v2 --text "Bugün okula gitmek istemiyorum." --speaker_wav /path/to/target/*.wav --language_idx tr --use_cuda ``` ``` -------------------------------- ### Perform manual streaming inference with XTTS Source: https://coqui-tts.readthedocs.io/en/latest/_sources/models/xtts.md.txt Demonstrates how to load an XTTS model, compute conditioning latents, and stream generated audio chunks to a file. ```python import os import time import torch import torchaudio from TTS.tts.configs.xtts_config import XttsConfig from TTS.tts.models.xtts import Xtts print("Loading model...") config = XttsConfig() config.load_json("/path/to/xtts/config.json") model = Xtts.init_from_config(config) model.load_checkpoint(config, checkpoint_dir="/path/to/xtts/", use_deepspeed=True) model.cuda() print("Computing speaker latents...") gpt_cond_latent, speaker_embedding = model.get_conditioning_latents(audio_path=["reference.wav"]) print("Inference...") t0 = time.time() chunks = model.inference_stream( "It took me quite a long time to develop a voice and now that I have it I am not going to be silent.", "en", gpt_cond_latent, speaker_embedding ) wav_chuncks = [] for i, chunk in enumerate(chunks): if i == 0: print(f"Time to first chunck: {time.time() - t0}") print(f"Received chunk {i} of audio length {chunk.shape[-1]}") wav_chuncks.append(chunk) wav = torch.cat(wav_chuncks, dim=0) torchaudio.save("xtts_streaming.wav", wav.squeeze().unsqueeze(0).cpu(), 24000) ``` -------------------------------- ### Basic Inference with CPU Docker Image Source: https://coqui-tts.readthedocs.io/en/latest/docker_images.html Generate an audio file using the CPU version of the Coqui TTS Docker image. Mount a local directory to store the output. ```bash docker run --rm -v ~/tts-output:/root/tts-output ghcr.io/idiap/coqui-tts-cpu --text "Hello." --out_path /root/tts-output/hello.wav ``` -------------------------------- ### Train Vocoder Model Source: https://coqui-tts.readthedocs.io/en/latest/_sources/tutorial_for_nervous_beginners.md.txt This example shows the Python script used for training a vocoder model, similar to how TTS models are trained. ```python from TTS.vocoder.train import train_vocoder train_vocoder("../recipes/ljspeech/hifigan/config.json") ``` -------------------------------- ### Define metadata file format Source: https://coqui-tts.readthedocs.io/en/latest/_sources/datasets/formatting_your_dataset.md.txt Example of the pipe-delimited metadata file format mapping audio files to raw and normalized transcriptions. ```text # metadata.txt audio1|This is my sentence.|This is my sentence. audio2|1469 and 1470|fourteen sixty-nine and fourteen seventy audio3|It'll be $16 sir.|It'll be sixteen dollars sir. ... ``` -------------------------------- ### CPU Inference with Docker Source: https://coqui-tts.readthedocs.io/en/latest/_sources/docker_images.md.txt Generate audio from text using the CPU Docker image. Mount a volume to save the output file. ```bash docker run --rm -v ~/tts-output:/root/tts-output ghcr.io/idiap/coqui-tts-cpu --text "Hello." --out_path /root/tts-output/hello.wav ``` -------------------------------- ### Run Tests with uv Source: https://coqui-tts.readthedocs.io/en/latest/contributing.html Executes the test suite using uv for environment management. Use 'make test' to stop at the first error or 'make test_all' to run all tests and report all errors. ```bash uv run make test # stop at the first error uv run make test_all # run all the tests, report all the errors ``` -------------------------------- ### XTTS Inference - API Source: https://coqui-tts.readthedocs.io/en/latest/_sources/models/xtts.md.txt Python API examples for performing XTTS inference, including voice cloning with single or multiple audio references. ```APIDOC ## XTTS Inference - API ### Voice Cloning - Single Reference Splits the text into sentences and generates audio for each sentence. The audio files are then concatenated to produce the final audio. You can optionally disable sentence splitting for better coherence but more VRAM and possibly hitting models context length limit. ```python from TTS.api import TTS tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to("cuda") # Example usage for voice cloning with a single reference WAV file # tts.tts_to_file(text="Your text here", speaker_wav="/path/to/your/speaker.wav", language="en", file_path="output.wav") ``` ### Voice Cloning - Multiple References Similar to single reference cloning, but allows providing multiple WAV files for potentially better voice cloning results. ```python # Example usage for voice cloning with multiple reference WAV files # tts.tts_to_file(text="Your text here", speaker_wav=["/path/to/speaker1.wav", "/path/to/speaker2.wav"], language="en", file_path="output_multi.wav") ``` ``` -------------------------------- ### Get Additional Synthesis Outputs Source: https://coqui-tts.readthedocs.io/en/latest/main_classes/synthesizer.html Obtain detailed synthesis outputs, including audio segments and timestamps, by setting return_dict=True. The output is a Python dictionary. ```python print(synth.tts("Hello World. This is a test.", return_dict=True)) ``` -------------------------------- ### List Available TTS Server Models Source: https://coqui-tts.readthedocs.io/en/latest/_sources/tutorial_for_nervous_beginners.md.txt Use the `--list_models` flag with the `tts-server` command to view models accessible by the local demo server. ```bash $ tts-server --list_models ``` -------------------------------- ### Run Voice Conversion Model Source: https://coqui-tts.readthedocs.io/en/latest/inference.html Perform voice conversion by providing the model name and paths to the source and target WAV files. ```bash tts --out_path output/path/speech.wav --model_name "//" \ --source_wav --target_wav ``` -------------------------------- ### Get Speaker Embeddings for Coqui Speakers Source: https://coqui-tts.readthedocs.io/en/latest/_sources/models/xtts.md.txt Retrieves the conditioning latent and speaker embedding for a specific Coqui speaker by accessing the model's speaker manager. ```python gpt_cond_latent, speaker_embedding = model.speaker_manager.speakers["Ana Florence"].values() ``` -------------------------------- ### Initialize TTS and Synthesize Speech (Multi-speaker) Source: https://coqui-tts.readthedocs.io/en/latest/inference.html Initializes a multi-speaker and multi-lingual TTS model (XTTS v2) and demonstrates synthesizing speech with voice cloning from an audio file and using a preset speaker. Ensure the correct device (GPU or CPU) is selected. ```python 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()) # Initialize TTS tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device) # List speakers print(tts.speakers) # Run TTS # ❗ XTTS supports both, but many models allow only one of the `speaker` and # `speaker_wav` arguments # TTS with list of amplitude values as output, clone the voice from `speaker_wav` wav = tts.tts( text="Hello world!", speaker_wav="my/cloning/audio.wav", language="en" ) # TTS to a file, use a preset speaker tts.tts_to_file( text="Hello world!", speaker="Craig Gutsy", language="en", file_path="output.wav" ) ``` -------------------------------- ### Pull GPU Docker Image Source: https://coqui-tts.readthedocs.io/en/latest/docker_images.html Use this command to pull the latest Coqui TTS GPU Docker image from Docker Hub. Ensure you have compatible NVIDIA drivers installed. ```bash docker pull ghcr.io/idiap/coqui-tts ``` -------------------------------- ### Run multi-GPU training Source: https://coqui-tts.readthedocs.io/en/latest/_sources/training/training_a_model.md.txt Utilize the DDP back-end to distribute training across multiple specified GPUs. ```bash $ CUDA_VISIBLE_DEVICES="0, 1, 2" python -m trainer.distribute --script /train_glowtts.py ``` -------------------------------- ### Configure GlowTTS Training Source: https://coqui-tts.readthedocs.io/en/latest/_sources/faq.md.txt A sample configuration file for training a GlowTTS network, defining model parameters, dataset paths, and training settings. ```json { "model": "glow_tts", "batch_size": 32, "eval_batch_size": 16, "num_loader_workers": 4, "num_eval_loader_workers": 4, "run_eval": true, "test_delay_epochs": -1, "epochs": 1000, "text_cleaner": "english_cleaners", "use_phonemes": false, "phoneme_language": "en-us", "phoneme_cache_path": "phoneme_cache", "print_step": 25, "print_eval": true, "mixed_precision": false, "output_path": "recipes/ljspeech/glow_tts/", "test_sentences": ["Test this sentence.", "This test sentence.", "Sentence this test."], "datasets":[{"formatter": "ljspeech", "meta_file_train":"metadata.csv", "path": "recipes/ljspeech/LJSpeech-1.1/"}] } ``` -------------------------------- ### Clone and Reuse Voices with Python API Source: https://coqui-tts.readthedocs.io/en/latest/_sources/cloning.md.txt Demonstrates initializing a model, cloning a voice from reference files, and reusing the cached voice. ```python import torch from TTS.api import TTS # Get device device = "cuda" if torch.cuda.is_available() else "cpu" # Initialize a TTS model with voice cloning support api = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device) # 1. Clone the voice from `speaker_wav` and cache it under a custom speaker ID api.tts_to_file( text="Hello world", speaker_wav=["my/cloning/audio.wav", "my/cloning/audio2.wav"], speaker="MySpeaker1", language="en", ) # 2. The voice can now be reused without providing reference audio api.tts_to_file( text="Hello world", speaker="MySpeaker1", language="en", ) ``` -------------------------------- ### Monitor Training with Tensorboard Source: https://coqui-tts.readthedocs.io/en/latest/training/training_a_model.html Use this command to monitor your model's training progress via Tensorboard. Ensure you replace `` with the actual path. ```bash tensorboard --logdir= ``` -------------------------------- ### Voice Cloning with TTS and FreeVC Python API Source: https://coqui-tts.readthedocs.io/en/latest/vc.html Combine Text-to-Speech (TTS) with Voice Conversion (VC) to clone a voice. This example synthesizes speech and then converts its voice using the FreeVC model. ```python 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=["target1.wav", "target2.wav"], file_path="output.wav" ) ``` -------------------------------- ### Get Supported Locales via CURL Source: https://coqui-tts.readthedocs.io/en/latest/_sources/marytts.md.txt Use this CURL command to retrieve a list of supported locales from the Mary-TTS compatible Coqui TTS server. This helps in identifying available language options. ```bash curl http://localhost:59125/locales ```