1# 1. Enable GPU: Runtime → Change runtime type → GPU
2# 2. Install
3!pip install -q f5-tts soundfile
4
5# 3. Download model (~1.3GB)
6from huggingface_hub import snapshot_download
7snapshot_download("SWivid/F5-TTS", local_dir="./f5tts_model", allow_patterns=["F5TTS_v1_Base/*"])
8
9# 4. Clone a voice
10from f5_tts.api import F5TTS
11tts = F5TTS(ckpt_file="./f5tts_model/F5TTS_v1_Base/model_1250000.safetensors",
12 vocab_file="./f5tts_model/F5TTS_v1_Base/vocab.txt")
13
14wav, sr, _ = tts.infer(
15 ref_file="/content/my_voice.wav", # Upload your audio first
16 ref_text="Exact transcript of your audio.",
17 gen_text="Say this in the cloned voice!",
18 nfe_step=32,
19)
20
21import soundfile as sf
22sf.write("output.wav", wav, sr)
1pip install f5-tts soundfile
2
3python -c "
4from f5_tts.api import F5TTS
5import soundfile as sf
6
7tts = F5TTS() # Auto-downloads model on first run
8wav, sr, _ = tts.infer(
9 ref_file='my_voice.wav',
10 ref_text='Hello, this is my voice.',
11 gen_text='Hello from my local machine!',
12)
13sf.write('output.wav', wav, sr)
14"
1# 1. Prepare your data:
2# my_voice/
3# ├── metadata.csv # format: audio_path|text
4# └── wavs/
5# ├── clip001.wav
6# └── clip002.wav
7
8# 2. Run training
9python train_voice_clone.py \
10 --hf_dataset mythicinfinity/libritts_r \
11 --hf_config clean \
12 --hf_split train.clean.100 \
13 --epochs 20 \
14 --lr 1e-5
1pip install f5-tts
2
3# Prepare dataset
4python -m f5_tts.train.datasets.prepare_csv_wavs \
5 /path/to/my_voice \
6 /path/to/prepared_data/MyVoice_custom
7
8# Fine-tune
9python -m f5_tts.train.finetune_cli \
10 --exp_name F5TTS_v1_Base \
11 --dataset_name MyVoice \
12 --tokenizer custom \
13 --finetune \
14 --learning_rate 1e-5 \
15 --batch_size_per_gpu 38400 \
16 --batch_size_type frame \
17 --max_samples 64 \
18 --epochs 20 \
19 --num_warmup_updates 300 \
20 --grad_accumulation_steps 2 \
21 --logger tensorboard
1@article{shen2024f5tts,
2 title={F5-TTS: A Fairytaler that Fakes Fluent and Faithful Speech with Flow Matching},
3 author={Shen, Yusheng and Wang, Zhijian and Dalmia, Shaylen and Su, Yuchuan and Liu, Zhejian and Marino, Kevin and Zonooz, Bahram and Yao, Zirun and Ma, Xinyin},
4 journal={arXiv preprint arXiv:2410.06885},
5 year={2024}
6}