### Programmatic Training Setup Source: https://context7.com/ai4bharat/indicf5/llms.txt Initialize the model, trainer, and dataset using Python classes. ```python from f5_tts.model import CFM, DiT, Trainer from f5_tts.model.utils import get_tokenizer from f5_tts.model.dataset import load_dataset # Model configuration vocab_char_map, vocab_size = get_tokenizer("path/to/vocab.txt", "custom") model_cfg = dict(dim=1024, depth=22, heads=16, ff_mult=2, text_dim=512, conv_layers=4) mel_spec_kwargs = dict( n_fft=1024, hop_length=256, win_length=1024, n_mel_channels=100, target_sample_rate=24000, mel_spec_type="vocos", ) model = CFM( transformer=DiT(**model_cfg, text_num_embeds=vocab_size, mel_dim=100), mel_spec_kwargs=mel_spec_kwargs, vocab_char_map=vocab_char_map, ) # Initialize trainer trainer = Trainer( model, epochs=700, learning_rate=1e-5, num_warmup_updates=1500, save_per_updates=4000, checkpoint_path="checkpoints/", batch_size=3200, batch_size_type="frame", max_samples=64, grad_accumulation_steps=1, max_grad_norm=1.0, logger="wandb", ) # Load dataset and train train_dataset = load_dataset("dataset_name", "custom", mel_spec_kwargs=mel_spec_kwargs, data_dir="data/") trainer.train(train_dataset, resumable_with_seed=666, num_workers=16) ``` -------------------------------- ### Launch Training with Base Config Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/train/README.md Start the training process using the F5TTS_Base_train.yaml configuration file with accelerate launch. ```bash accelerate launch src/f5_tts/train/train.py --config-name F5TTS_Base_train.yaml ``` -------------------------------- ### Install IndicF5 Environment Source: https://github.com/ai4bharat/indicf5/blob/main/README.md Set up the required Python environment and install the IndicF5 package via pip. ```bash conda create -n indicf5 python=3.10 -y conda activate indicf5 pip install git+https://github.com/ai4bharat/IndicF5.git ``` -------------------------------- ### Install Evaluation Dependencies Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/eval/README.md Install the necessary packages for evaluation in editable mode. ```bash pip install -e .[eval] ``` -------------------------------- ### Launch Gradio Web Interface Source: https://context7.com/ai4bharat/indicf5/llms.txt Provides instructions and code examples for launching the interactive Gradio web UI for TTS generation. Supports basic synthesis, multi-style generation, and voice chat. ```APIDOC ## Gradio Web Interface Launch an interactive web UI for TTS generation with support for basic synthesis, multi-style generation, and voice chat features. ### Python ```python # Launch the Gradio app directly from f5_tts.infer.infer_gradio import app # Start the interface app.queue().launch( server_name="0.0.0.0", server_port=7860, share=False, show_api=True ) ``` ### Command Line Interface ```bash # CLI command to launch Gradio interface f5-tts_infer-gradio --port 7860 --host 0.0.0.0 # With public sharing link f5-tts_infer-gradio --share # Custom root path for reverse proxy f5-tts_infer-gradio --root_path "/tts-app" ``` ### Embedding in a Larger Application ```python import gradio as gr from f5_tts.infer.infer_gradio import app with gr.Blocks() as main_app: gr.Markdown("# My TTS Application") with gr.Tab("Text-to-Speech"): app.render() # Embed the F5-TTS interface with gr.Tab("Other Features"): gr.Markdown("Additional application features here") main_app.launch() ``` ``` -------------------------------- ### Launch Gradio Web Interface (Python) Source: https://context7.com/ai4bharat/indicf5/llms.txt Launches the interactive Gradio web UI for TTS generation. Ensure the 'f5_tts' library is installed. The interface supports basic synthesis, multi-style generation, and voice chat. ```python # Launch the Gradio app directly from f5_tts.infer.infer_gradio import app # Start the interface app.queue().launch( server_name="0.0.0.0", server_port=7860, share=False, show_api=True ) ``` -------------------------------- ### Set Wandb API Key (Windows) Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/train/README.md Configure the WANDB_API_KEY environment variable on Windows to allow Weights & Biases logging. Get your API key from wandb.ai/site/. ```bash set WANDB_API_KEY= ``` -------------------------------- ### Start Socket Server for Realtime TTS Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/infer/README.md Run the socket server script to enable communication for realtime text-to-speech. This script should be running before the client connects. ```bash python src/f5_tts/socket_server.py ``` -------------------------------- ### CLI Inference with TOML Configuration Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/infer/README.md Configure F5-TTS CLI inference using a TOML file for more flexible parameter management. This example demonstrates basic TTS generation with specified reference audio and text. ```bash f5-tts_infer-cli -c custom.toml ``` -------------------------------- ### TOML Configuration for Multi-Style Generation Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/infer/README.md Configure F5-TTS CLI for multi-style generation using a TOML file. This example defines multiple voices with their respective reference audios and uses a text file for generation content. ```toml # F5-TTS | E2-TTS model = "F5-TTS" ref_audio = "infer/examples/multi/main.flac" # If an empty "", transcribes the reference audio automatically. ref_text = "" gen_text = "" # File with text to generate. Ignores the text above. gen_file = "infer/examples/multi/story.txt" remove_silence = true output_dir = "tests" [voices.town] ref_audio = "infer/examples/multi/town.flac" ref_text = "" [voices.country] ref_audio = "infer/examples/multi/country.flac" ref_text = "" ``` -------------------------------- ### Load IndicF5 from Hugging Face Transformers Source: https://context7.com/ai4bharat/indicf5/llms.txt Shows how to load the IndicF5 model directly from Hugging Face using the transformers library. This example demonstrates generating Hindi speech with a Punjabi reference voice. ```python from transformers import AutoModel import numpy as np import soundfile as sf # Load IndicF5 from Hugging Face repo_id = "ai4bharat/IndicF5" model = AutoModel.from_pretrained(repo_id, trust_remote_code=True) # Generate Hindi speech with Punjabi reference voice audio = model( "नमस्ते! संगीत की तरह जीवन भी खूबसूरत होता है, बस इसे सही ताल में जीना आना चाहिए.", ref_audio_path="prompts/PAN_F_HAPPY_00001.wav", ref_text="ਭਹੰਪੀ ਵਿੱਚ ਸਮਾਰਕਾਂ ਦੇ ਭਵਨ ਨਿਰਮਾਣ ਕਲਾ ਦੇ ਵੇਰਵੇ ਗੁੰਝਲਦਾਰ ਅਤੇ ਹੈਰਾਨ ਕਰਨ ਵਾਲੇ ਹਨ, ਜੋ ਮੈਨੂੰ ਖੁਸ਼ ਕਰਦੇ ਹਨ।" ) # Normalize int16 audio to float32 if needed if audio.dtype == np.int16: audio = audio.astype(np.float32) / 32768.0 # Save the generated audio sf.write("output.wav", np.array(audio, dtype=np.float32), samplerate=24000) ``` -------------------------------- ### TOML Configuration for Basic TTS Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/infer/README.md Example TOML file for F5-TTS CLI inference. It specifies the model, reference audio, reference text, generation text, and output directory. Setting `gen_file` to empty will use `gen_text`. ```toml # F5-TTS | E2-TTS model = "F5-TTS" ref_audio = "infer/examples/basic/basic_ref_en.wav" # If an empty "", transcribes the reference audio automatically. ref_text = "Some call me nature, others call me mother nature." gen_text = "I don't really care what you call me. I've been a silent spectator, watching species evolve, empires rise and fall. But always remember, I am mighty and enduring." # File with text to generate. Ignores the text above. gen_file = "" remove_silence = false output_dir = "tests" ``` -------------------------------- ### CLI Inference with f5-tts_infer-cli Source: https://context7.com/ai4bharat/indicf5/llms.txt Provides examples of using the command-line interface for IndicF5 inference, including basic usage with explicit parameters, leaving ref_text empty for ASR, using a different vocoder, and configuring via a TOML file. ```bash # Basic CLI inference with explicit parameters f5-tts_infer-cli \ --model "F5-TTS" \ --ref_audio "prompts/TAM_F_HAPPY_00001.wav" \ --ref_text "Reference audio transcript" \ --gen_text "Text to generate speech for" \ --output_dir "outputs" \ --output_file "generated.wav" \ --speed 1.0 # Leave ref_text empty for automatic ASR transcription f5-tts_infer-cli \ --model "F5-TTS" \ --ref_audio "reference.wav" \ --ref_text "" \ --gen_text "The model will auto-transcribe the reference audio." # Use BigVGAN vocoder with local checkpoint f5-tts_infer-cli \ --vocoder_name bigvgan \ --load_vocoder_from_local \ --ckpt_file "ckpts/F5TTS_Base_bigvgan/model_1250000.pt" # Use TOML configuration file f5-tts_infer-cli -c config.toml ``` -------------------------------- ### Train and Finetune via CLI Source: https://context7.com/ai4bharat/indicf5/llms.txt Configure distributed training and execute finetuning or resume training from a checkpoint. ```bash # Setup accelerate for distributed training accelerate config # Train from pretrained checkpoint with custom data python -m f5_tts.train.finetune_cli \ --exp_name "F5TTS_Base" \ --dataset_name "my_dataset" \ --data_dir "/path/to/data" \ --ckpt_dir "/path/to/checkpoints" \ --learning_rate 1e-5 \ --batch_size_per_gpu 3200 \ --batch_size_type "frame" \ --max_samples 64 \ --epochs 700 \ --num_warmup_updates 1500 \ --save_per_updates 4000 \ --tokenizer "custom" \ --tokenizer_path "/path/to/vocab.txt" \ --finetune True \ --pretrain "/path/to/pretrained.pt" \ --logger "wandb" # Resume training from checkpoint python -m f5_tts.train.finetune_cli \ --exp_name "F5TTS_Base" \ --ckpt_dir "/path/to/checkpoints" \ --data_dir "/path/to/data" \ --resume True \ --wandb_resume_id "your_wandb_run_id" ``` -------------------------------- ### Launch Training with Small Config and Overrides Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/train/README.md Initiate training with the F5TTS_Small_train.yaml configuration, overriding accelerate and hydra settings like mixed precision and batch size. ```bash accelerate launch --mixed_precision=fp16 src/f5_tts/train/train.py --config-name F5TTS_Small_train.yaml ++datasets.batch_size_per_gpu=19200 ``` -------------------------------- ### Prepare Emilia Dataset Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/train/README.md Run this script to prepare the Emilia dataset for training. Ensure the dataset is downloaded first. ```bash python src/f5_tts/train/datasets/prepare_emilia.py ``` -------------------------------- ### Prepare Wenetspeech4TTS Dataset Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/train/README.md Run this script to prepare the Wenetspeech4TTS dataset. Download the dataset before execution. ```bash python src/f5_tts/train/datasets/prepare_wenetspeech4tts.py ``` -------------------------------- ### Initialize and Use F5TTS Python API Source: https://context7.com/ai4bharat/indicf5/llms.txt Demonstrates initializing the F5TTS model with custom parameters and performing inference using a reference audio file. It covers accessing generation seeds and manually exporting audio. ```python from f5_tts.api import F5TTS import numpy as np import soundfile as sf # Initialize the TTS model tts = F5TTS( model_type="F5-TTS", # Model type: "F5-TTS" or "E2-TTS" ckpt_file="", # Custom checkpoint path (empty for default) vocab_file="", # Custom vocab file path (empty for default) ode_method="euler", # ODE solver method use_ema=True, # Use exponential moving average weights vocoder_name="vocos", # Vocoder: "vocos" or "bigvgan" device=None, # Device (auto-detect if None) ) # Generate speech with reference audio wav, sample_rate, spectrogram = tts.infer( ref_file="prompts/TAM_F_HAPPY_00001.wav", # Reference audio < 15s ref_text="Reference audio transcript here", # Transcript of ref audio gen_text="Text you want to synthesize into speech.", target_rms=0.1, # Target RMS for audio normalization cross_fade_duration=0.15, # Cross-fade between chunks (seconds) nfe_step=32, # Number of function evaluations (quality) cfg_strength=2.0, # Classifier-free guidance strength speed=1.0, # Speech speed multiplier seed=-1, # Random seed (-1 for random) file_wave="output.wav", # Optional: save directly to file file_spect="output.png", # Optional: save spectrogram remove_silence=False, # Remove silence from output ) # Access the seed used for reproducibility print(f"Generation seed: {tts.seed}") # Manually export audio tts.export_wav(wav, "custom_output.wav", remove_silence=True) ``` -------------------------------- ### Prepare LJSpeech Dataset Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/train/README.md Execute this script to prepare the LJSpeech dataset. The dataset must be downloaded beforehand. ```bash python src/f5_tts/train/datasets/prepare_ljspeech.py ``` -------------------------------- ### Prepare datasets for training Source: https://context7.com/ai4bharat/indicf5/llms.txt Commands to prepare standard or custom datasets for model training. ```bash # Prepare standard datasets python -m f5_tts.train.datasets.prepare_emilia python -m f5_tts.train.datasets.prepare_libritts python -m f5_tts.train.datasets.prepare_ljspeech # Prepare custom dataset from CSV python -m f5_tts.train.datasets.prepare_csv_wavs ``` -------------------------------- ### Prepare LibriTTS Dataset Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/train/README.md Use this script to prepare the LibriTTS dataset. Make sure the dataset is downloaded prior to running. ```bash python src/f5_tts/train/datasets/prepare_libritts.py ``` -------------------------------- ### Create Custom Dataset from CSV Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/train/README.md Prepare a custom dataset using a metadata.csv file. Refer to the provided discussion link for detailed guidance. ```bash python src/f5_tts/train/datasets/prepare_csv_wavs.py ``` -------------------------------- ### Launch Gradio Interface (CLI) Source: https://context7.com/ai4bharat/indicf5/llms.txt Command-line interface commands to launch the Gradio web UI. Options include specifying port, host, enabling public sharing, and setting a custom root path for reverse proxies. ```bash # CLI command to launch Gradio interface f5-tts_infer-gradio --port 7860 --host 0.0.0.0 # With public sharing link f5-tts_infer-gradio --share # Custom root path for reverse proxy f5-tts_infer-gradio --root_path "/tts-app" ``` -------------------------------- ### Configure Finnish F5-TTS Model Paths Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/infer/SHARED.md Use these paths to reference the finetuned Finnish F5-TTS model checkpoint and vocabulary file. ```bash MODEL_CKPT: hf://AsmoKoskinen/F5-TTS_Finish_Model/model_common_voice_fi_vox_populi_fi_20241206.safetensors VOCAB_FILE: hf://AsmoKoskinen/F5-TTS_Finish_Model/vocab.txt ``` -------------------------------- ### Configure Japanese F5-TTS Model Paths Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/infer/SHARED.md Use these paths to reference the Japanese F5-TTS model checkpoint and vocabulary file. ```bash MODEL_CKPT: hf://Jmica/F5TTS/JA_8500000/model_8499660.pt VOCAB_FILE: hf://Jmica/F5TTS/JA_8500000/vocab_updated.txt ``` -------------------------------- ### Configure Accelerate for Training Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/train/README.md Set up the accelerate configuration for distributed training, including multi-GPU DDP and fp16 precision. The configuration is saved to ~/.cache/huggingface/accelerate/default_config.yaml. ```bash accelerate config ``` -------------------------------- ### Configure French F5-TTS Model Paths Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/infer/SHARED.md Use these paths to reference the finetuned French F5-TTS model checkpoint and vocabulary file. ```bash MODEL_CKPT: hf://RASPIAUDIO/F5-French-MixedSpeakers-reduced/model_last_reduced.pt VOCAB_FILE: hf://RASPIAUDIO/F5-French-MixedSpeakers-reduced/vocab.txt ``` -------------------------------- ### Configure F5-TTS Base Model Paths Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/infer/SHARED.md Use these paths to reference the pretrained F5-TTS base model checkpoint and vocabulary file. ```bash MODEL_CKPT: hf://SWivid/F5-TTS/F5TTS_Base/model_1200000.safetensors VOCAB_FILE: hf://SWivid/F5-TTS/F5TTS_Base/vocab.txt ``` -------------------------------- ### Set Wandb API Key (Mac/Linux) Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/train/README.md Set the WANDB_API_KEY environment variable to enable programmatic login to Weights & Biases for logging metrics. Obtain your API key from wandb.ai/site/. ```bash export WANDB_API_KEY= ``` -------------------------------- ### Run Batch Inference Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/eval/README.md Configure the environment and execute the batch inference script for evaluation. ```bash # batch inference for evaluations accelerate config # if not set before bash src/f5_tts/eval/eval_infer_batch.sh ``` -------------------------------- ### Basic Single-Voice Configuration (TOML) Source: https://context7.com/ai4bharat/indicf5/llms.txt Use this configuration for simple text-to-speech synthesis with a single reference voice. Ensure 'ref_audio' and 'ref_text' are correctly set. ```toml # basic_config.toml - Simple single-voice configuration model = "F5-TTS" ref_audio = "prompts/TAM_F_HAPPY_00001.wav" ref_text = "Reference transcript for Tamil female happy voice." gen_text = "Text to synthesize using this voice." gen_file = "" # Or path to text file (overrides gen_text) remove_silence = false output_dir = "outputs" output_file = "output.wav" ``` -------------------------------- ### Run TTS Inference Pipeline Source: https://context7.com/ai4bharat/indicf5/llms.txt Load a model, preprocess reference audio, transcribe, chunk text, and perform full inference. ```python # Load TTS model model = load_model( model_cls=DiT, model_cfg=dict(dim=1024, depth=22, heads=16, ff_mult=2, text_dim=512, conv_layers=4), ckpt_path="path/to/checkpoint.pt", mel_spec_type="vocos", vocab_file="path/to/vocab.txt", ode_method="euler", use_ema=True, device="cuda", ) # Preprocess reference audio (clips to ~15s, removes silence edges) ref_audio_path, ref_text = preprocess_ref_audio_text( ref_audio_orig="long_reference.wav", ref_text="", # Empty for auto-transcription clip_short=True, # Clip long audio device="cuda", ) # Auto-transcribe audio using Whisper transcription = transcribe( ref_audio="audio.wav", language="hi", # Optional language hint ) # Chunk long text for batch processing text_chunks = chunk_text( text="Very long text that needs to be split into manageable chunks for synthesis...", max_chars=135, # Max characters per chunk ) # Full inference pipeline final_wave, sample_rate, spectrogram = infer_process( ref_audio=ref_audio_path, ref_text=ref_text, gen_text="Text to generate", model_obj=model, vocoder=vocoder, mel_spec_type="vocos", target_rms=0.1, cross_fade_duration=0.15, nfe_step=32, cfg_strength=2.0, speed=1.0, device="cuda", ) # Post-processing remove_silence_for_generated_wav("output.wav") save_spectrogram(spectrogram, "spectrogram.png") ``` -------------------------------- ### F5TTS Python API Source: https://context7.com/ai4bharat/indicf5/llms.txt The F5TTS class provides the primary Python interface for model initialization and audio generation. ```APIDOC ## F5TTS Class Inference ### Description Initializes the TTS model and generates speech from text using a reference audio clip for voice cloning. ### Parameters #### Request Body - **model_type** (string) - Optional - "F5-TTS" or "E2-TTS" - **ref_file** (string) - Required - Path to reference audio (< 15s) - **ref_text** (string) - Required - Transcript of reference audio - **gen_text** (string) - Required - Text to synthesize - **nfe_step** (integer) - Optional - Number of function evaluations - **cfg_strength** (float) - Optional - Classifier-free guidance strength - **speed** (float) - Optional - Speech speed multiplier ### Response #### Success Response (200) - **wav** (array) - Generated audio waveform - **sample_rate** (integer) - Audio sample rate - **spectrogram** (array) - Generated spectrogram data ``` -------------------------------- ### Multi-Voice Text File Format (TXT) Source: https://context7.com/ai4bharat/indicf5/llms.txt Format for 'script.txt' used in multi-voice configurations. Use bracketed tags to specify speakers for different parts of the dialogue. ```text # script.txt - Multi-voice text file format [narrator] Once upon a time in a distant land... [character1] Hello there, traveler! Welcome to our village. [character2] We don't see many visitors around here. [narrator] The two villagers exchanged knowing glances. ``` -------------------------------- ### Generate Speech with IndicF5 Source: https://github.com/ai4bharat/indicf5/blob/main/README.md Load the model from Hugging Face and synthesize speech using a reference audio prompt and its transcript. ```python from transformers import AutoModel import numpy as np import soundfile as sf # Load INF5 from Hugging Face repo_id = "ai4bharat/IndicF5" model = AutoModel.from_pretrained(repo_id, trust_remote_code=True) # Generate speech audio = model( "नमस्ते! संगीत की तरह जीवन भी खूबसूरत होता है, बस इसे सही ताल में जीना आना चाहिए.", ref_audio_path="prompts/PAN_F_HAPPY_00001.wav", ref_text="ਭਹੰਪੀ ਵਿੱਚ ਸਮਾਰਕਾਂ ਦੇ ਭਵਨ ਨਿਰਮਾਣ ਕਲਾ ਦੇ ਵੇਰਵੇ ਗੁੰਝਲਦਾਰ ਅਤੇ ਹੈਰਾਨ ਕਰਨ ਵਾਲੇ ਹਨ, ਜੋ ਮੈਨੂੰ ਖੁਸ਼ ਕਰਦੇ ਹਨ。" ) # Normalize and save output if audio.dtype == np.int16: audio = audio.astype(np.float32) / 32768.0 sf.write("samples/namaste.wav", np.array(audio, dtype=np.float32), samplerate=24000) ``` -------------------------------- ### CFM Model - Core Inference API Source: https://context7.com/ai4bharat/indicf5/llms.txt Details on using the Conditional Flow Matching (CFM) model for low-level control over the synthesis process. Includes initialization and the `sample` method for advanced use cases. ```APIDOC ## CFM Model - Core Inference API The Conditional Flow Matching model provides low-level control over the synthesis process with the `sample` method for advanced use cases. ### Python ```python import torch import torchaudio from f5_tts.model import CFM, DiT from f5_tts.model.utils import get_tokenizer from f5_tts.infer.utils_infer import load_vocoder # Load tokenizer vocab_file = "path/to/vocab.txt" vocab_char_map, vocab_size = get_tokenizer(vocab_file, "custom") # Initialize CFM model with DiT backbone model_cfg = dict(dim=1024, depth=22, heads=16, ff_mult=2, text_dim=512, conv_layers=4) model = CFM( transformer=DiT(**model_cfg, text_num_embeds=vocab_size, mel_dim=100), mel_spec_kwargs=dict( n_fft=1024, hop_length=256, win_length=1024, n_mel_channels=100, target_sample_rate=24000, mel_spec_type="vocos", ), vocab_char_map=vocab_char_map, odeint_kwargs=dict(method="euler"), ) # Load vocoder vocoder = load_vocoder(vocoder_name="vocos") # Load and preprocess reference audio audio, sr = torchaudio.load("reference.wav") if sr != 24000: audio = torchaudio.transforms.Resample(sr, 24000)(audio) # Generate with fine-grained control generated, trajectory = model.sample( cond=audio.to(model.device), # Reference audio conditioning text=["Reference text. Generated text here."], # Combined text duration=500, # Output duration in frames steps=32, # NFE steps (higher = better quality) cfg_strength=2.0, # Guidance strength sway_sampling_coef=-1.0, # Sampling coefficient seed=42, # Reproducibility max_duration=4096, # Max output length vocoder=vocoder, # Direct vocoder integration ) ``` ``` -------------------------------- ### Structure custom dataset directory Source: https://context7.com/ai4bharat/indicf5/llms.txt Required file and folder hierarchy for custom training data. ```text # Required directory structure dataset/ ├── metadata.csv └── wavs/ ├── audio001.wav ├── audio002.wav └── audio003.wav ``` -------------------------------- ### Basic CLI Inference with F5-TTS Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/infer/README.md Perform basic text-to-speech inference using the F5-TTS command-line tool. Provide reference audio and text for generation. If ref_text is empty, an ASR model will transcribe the reference audio. ```bash # Leave --ref_text "" will have ASR model transcribe (extra GPU memory usage) f5-tts_infer-cli \ --model "F5-TTS" \ --ref_audio "ref_audio.wav" \ --ref_text "The content, subtitle or transcription of reference audio." \ --gen_text "Some text you want TTS model generate for you." ``` -------------------------------- ### Socket Server for Real-time Streaming Source: https://context7.com/ai4bharat/indicf5/llms.txt Deploy a server to process TTS requests via sockets. ```python # Server setup (socket_server.py) from f5_tts.socket_server import TTSStreamingProcessor, start_server # Initialize the streaming processor processor = TTSStreamingProcessor( ckpt_file="path/to/model.pt", vocab_file="path/to/vocab.txt", ref_audio="path/to/reference.wav", ref_text="Reference audio transcript", device="cuda", dtype=torch.float32, ) # Start the server start_server( host="0.0.0.0", port=9998, processor=processor, ) ``` -------------------------------- ### Perform Objective Evaluation Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/eval/README.md Run WER and SIM evaluations on generated audio files for specific test sets. ```bash # Evaluation for Seed-TTS test set python src/f5_tts/eval/eval_seedtts_testset.py --gen_wav_dir # Evaluation for LibriSpeech-PC test-clean (cross-sentence) python src/f5_tts/eval/eval_librispeech_test_clean.py --gen_wav_dir --librispeech_test_clean_path ``` -------------------------------- ### Inference Utilities Source: https://context7.com/ai4bharat/indicf5/llms.txt Overview of core utility functions for preprocessing, inference, and post-processing, which serve as building blocks for custom TTS pipelines. ```APIDOC ## Inference Utilities Core utility functions for preprocessing, inference, and post-processing provide building blocks for custom pipelines. ### Python ```python from f5_tts.infer.utils_infer import ( preprocess_ref_audio_text, infer_process, infer_batch_process, load_model, load_vocoder, chunk_text, transcribe, remove_silence_for_generated_wav, save_spectrogram, ) from f5_tts.model import DiT # Load vocoder (vocos or bigvgan) vocoder = load_vocoder( vocoder_name="vocos", is_local=False, # Download from HuggingFace local_path="", # Or specify local path device="cuda", ) ``` ``` -------------------------------- ### Inference Utilities Import (Python) Source: https://context7.com/ai4bharat/indicf5/llms.txt Imports core utility functions for F5-TTS inference pipelines. These include functions for preprocessing, batch processing, model and vocoder loading, text chunking, transcription, silence removal, and spectrogram saving. ```python from f5_tts.infer.utils_infer import ( preprocess_ref_audio_text, infer_process, infer_batch_process, load_model, load_vocoder, chunk_text, transcribe, remove_silence_for_generated_wav, save_spectrogram, ) from f5_tts.model import DiT # Load vocoder (vocos or bigvgan) vocoder = load_vocoder( vocoder_name="vocos", is_local=False, # Download from HuggingFace local_path="", # Or specify local path device="cuda", ) ``` -------------------------------- ### Integrate F5-TTS into a Gradio App Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/infer/README.md Use the F5-TTS Gradio app as a component within a larger Gradio application. Ensure all necessary Gradio components are defined before rendering the F5-TTS app. ```python import gradio as gr from f5_tts.infer.infer_gradio import app with gr.Blocks() as main_app: gr.Markdown("# This is an example of using F5-TTS within a bigger Gradio app") # ... other Gradio components app.render() main_app.launch() ``` -------------------------------- ### CLI Inference Source: https://context7.com/ai4bharat/indicf5/llms.txt Command-line interface for batch processing and automated speech synthesis. ```APIDOC ## f5-tts_infer-cli ### Description Executes speech synthesis via command line using explicit arguments or a TOML configuration file. ### Parameters #### Query Parameters - **--model** (string) - Optional - Model type - **--ref_audio** (string) - Required - Path to reference audio - **--ref_text** (string) - Optional - Transcript of reference audio (empty for auto-ASR) - **--gen_text** (string) - Required - Text to synthesize - **--output_dir** (string) - Optional - Directory to save output - **--speed** (float) - Optional - Speech speed multiplier - **-c** (string) - Optional - Path to TOML configuration file ``` -------------------------------- ### Multi-Voice Configuration (TOML) Source: https://context7.com/ai4bharat/indicf5/llms.txt Configure for multi-speaker synthesis by defining multiple voices within the TOML file. Use 'gen_file' with voice tags for dialogue synthesis. Auto-transcription is supported for 'ref_text'. ```toml # multi_voice.toml - Multi-speaker configuration model = "F5-TTS" ref_audio = "voices/narrator.wav" ref_text = "" # Auto-transcribe gen_text = "" gen_file = "script.txt" # Contains voice tags like [narrator], [character1] remove_silence = true output_dir = "outputs" output_file = "dialogue.wav" [voices.character1] ref_audio = "voices/character1.wav" ref_text = "" [voices.character2] ref_audio = "voices/character2.wav" ref_text = "Character 2 reference transcript" ``` -------------------------------- ### CFM Model Core Inference API (Python) Source: https://context7.com/ai4bharat/indicf5/llms.txt Utilizes the Conditional Flow Matching (CFM) model for advanced TTS synthesis with fine-grained control. Requires loading a tokenizer, initializing the CFM model with a DiT backbone, and loading a vocoder. Reference audio and text are processed for generation. ```python import torch import torchaudio from f5_tts.model import CFM, DiT from f5_tts.model.utils import get_tokenizer from f5_tts.infer.utils_infer import load_vocoder # Load tokenizer vocab_file = "path/to/vocab.txt" vocab_char_map, vocab_size = get_tokenizer(vocab_file, "custom") # Initialize CFM model with DiT backbone model_cfg = dict(dim=1024, depth=22, heads=16, ff_mult=2, text_dim=512, conv_layers=4) model = CFM( transformer=DiT(**model_cfg, text_num_embeds=vocab_size, mel_dim=100), mel_spec_kwargs=dict( n_fft=1024, hop_length=256, win_length=1024, n_mel_channels=100, target_sample_rate=24000, mel_spec_type="vocos", ), vocab_char_map=vocab_char_map, odeint_kwargs=dict(method="euler"), ) # Load vocoder vocoder = load_vocoder(vocoder_name="vocos") # Load and preprocess reference audio audio, sr = torchaudio.load("reference.wav") if sr != 24000: audio = torchaudio.transforms.Resample(sr, 24000)(audio) # Generate with fine-grained control generated, trajectory = model.sample( cond=audio.to(model.device), # Reference audio conditioning text=["Reference text. Generated text here."], # Combined text duration=500, # Output duration in frames steps=32, # NFE steps (higher = better quality) cfg_strength=2.0, # Guidance strength sway_sampling_coef=-1.0, # Sampling coefficient seed=42, # Reproducibility max_duration=4096, # Max output length vocoder=vocoder, # Direct vocoder integration ) ``` -------------------------------- ### Implement streaming TTS client in Python Source: https://context7.com/ai4bharat/indicf5/llms.txt Connects to a TTS server via socket to receive and play audio chunks in real-time using PyAudio. ```python import socket import numpy as np import asyncio import pyaudio async def listen_to_voice(text, server_ip='localhost', server_port=9998): client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client_socket.connect((server_ip, server_port)) p = pyaudio.PyAudio() stream = p.open( format=pyaudio.paFloat32, channels=1, rate=24000, output=True, frames_per_buffer=2048 ) buffer = b'' try: # Send text to synthesize client_socket.sendall(text.encode('utf-8')) # Receive and play audio chunks while True: chunk = client_socket.recv(1024) if not chunk: break if b"END_OF_AUDIO" in chunk: buffer += chunk.replace(b"END_OF_AUDIO", b"") if buffer: audio_array = np.frombuffer(buffer, dtype=np.float32).copy() stream.write(audio_array.tobytes()) break buffer += chunk if len(buffer) >= 4096: audio_array = np.frombuffer(buffer[:4096], dtype=np.float32).copy() stream.write(audio_array.tobytes()) buffer = buffer[4096:] finally: stream.stop_stream() stream.close() p.terminate() client_socket.close() # Usage asyncio.run(listen_to_voice("Hello, this is real-time streaming TTS!")) ``` -------------------------------- ### CLI Inference: Choose Vocoder Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/infer/README.md Specify the vocoder to use for inference with the F5-TTS CLI. Use `--load_vocoder_from_local` and provide the checkpoint path for the desired vocoder. ```bash f5-tts_infer-cli --vocoder_name bigvgan --load_vocoder_from_local --ckpt_file ``` ```bash f5-tts_infer-cli --vocoder_name vocos --load_vocoder_from_local --ckpt_file ``` -------------------------------- ### Enable Offline Wandb Logging Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/train/README.md Set the WANDB_MODE environment variable to 'offline' to log metrics locally without connecting to the Weights & Biases service. This is useful if you cannot access Wandb. ```bash export WANDB_MODE=offline ``` -------------------------------- ### Run Speech Editing Script Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/infer/README.md Execute the speech editing script using this command. Ensure you are in the correct project directory. ```bash python src/f5_tts/infer/speech_edit.py ``` -------------------------------- ### Hugging Face Transformers Integration Source: https://context7.com/ai4bharat/indicf5/llms.txt Load the IndicF5 model directly from Hugging Face for integration into existing ML pipelines. ```APIDOC ## Hugging Face Model Inference ### Description Loads the model via `AutoModel.from_pretrained` and performs inference using the model's callable interface. ### Parameters #### Request Body - **text** (string) - Required - Text to synthesize - **ref_audio_path** (string) - Required - Path to reference audio - **ref_text** (string) - Required - Transcript of reference audio ### Response #### Success Response (200) - **audio** (array) - Generated audio data ``` -------------------------------- ### Python Socket Realtime Client for TTS Source: https://github.com/ai4bharat/indicf5/blob/main/f5_tts/infer/README.md A Python client using asyncio and sockets to send text to a server and play back the received audio stream. Ensure the server's sampling rate matches the client's configuration. ```python import socket import numpy as np import asyncio import pyaudio async def listen_to_voice(text, server_ip='localhost', server_port=9999): client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client_socket.connect((server_ip, server_port)) async def play_audio_stream(): buffer = b'' p = pyaudio.PyAudio() stream = p.open(format=pyaudio.paFloat32, channels=1, rate=24000, # Ensure this matches the server's sampling rate output=True, frames_per_buffer=2048) try: while True: chunk = await asyncio.get_event_loop().run_in_executor(None, client_socket.recv, 1024) if not chunk: # End of stream break if b"END_OF_AUDIO" in chunk: buffer += chunk.replace(b"END_OF_AUDIO", b"") if buffer: audio_array = np.frombuffer(buffer, dtype=np.float32).copy() # Make a writable copy stream.write(audio_array.tobytes()) break buffer += chunk if len(buffer) >= 4096: audio_array = np.frombuffer(buffer[:4096], dtype=np.float32).copy() # Make a writable copy stream.write(audio_array.tobytes()) buffer = buffer[4096:] finally: stream.stop_stream() stream.close() p.terminate() try: # Send only the text to the server await asyncio.get_event_loop().run_in_executor(None, client_socket.sendall, text.encode('utf-8')) await play_audio_stream() print("Audio playback finished.") except Exception as e: print(f"Error in listen_to_voice: {e}") finally: client_socket.close() # Example usage: Replace this with your actual server IP and port async def main(): await listen_to_voice("my name is jenny..", server_ip='localhost', server_port=9998) # Run the main async function asyncio.run(main()) ``` -------------------------------- ### Define metadata.csv for custom datasets Source: https://context7.com/ai4bharat/indicf5/llms.txt Format requirements for the metadata CSV file used in custom dataset preparation. ```csv # metadata.csv format for custom datasets audio_file|text|speaker_id wavs/audio001.wav|This is the transcript of audio 001.|speaker1 wavs/audio002.wav|Another sample with different content.|speaker1 wavs/audio003.wav|A different speaker saying something.|speaker2 ``` -------------------------------- ### Embed Gradio Interface in Larger App (Python) Source: https://context7.com/ai4bharat/indicf5/llms.txt Embeds the F5-TTS Gradio interface within a larger Gradio application using `gr.Blocks`. This allows integrating TTS functionality alongside other features in a custom UI. ```python # Embed in a larger Gradio application import gradio as gr from f5_tts.infer.infer_gradio import app with gr.Blocks() as main_app: gr.Markdown("# My TTS Application") with gr.Tab("Text-to-Speech"): app.render() # Embed the F5-TTS interface with gr.Tab("Other Features"): gr.Markdown("Additional application features here") main_app.launch() ``` -------------------------------- ### Cite IndicF5 Source: https://github.com/ai4bharat/indicf5/blob/main/README.md BibTeX entry for referencing the IndicF5 model in research or projects. ```bibtex @misc{AI4Bharat_IndicF5_2025, author = {Praveen S V and Srija Anand and Soma Siddhartha and Mitesh M. Khapra}, title = {IndicF5: High-Quality Text-to-Speech for Indian Languages}, year = {2025}, url = {https://github.com/AI4Bharat/IndicF5}, } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.