This is a fine-tuned version of
Coqui XTTS v2 for English text-to-speech synthesis.
1pip install TTS==0.22.0 torch==2.5.1 torchaudio==2.5.1 transformers==4.40.0
2pip install huggingface_hub
1import os
2import torch
3import torchaudio
4from huggingface_hub import hf_hub_download
5from TTS.tts.configs.xtts_config import XttsConfig
6from TTS.tts.models.xtts import Xtts
7
8# Download model files
9repo_id = "TurkishCodeMan/xtts-v2-english-finetuned"
10model_path = hf_hub_download(repo_id=repo_id, filename="model.pth")
11config_path = hf_hub_download(repo_id=repo_id, filename="config.json")
12vocab_path = hf_hub_download(repo_id=repo_id, filename="vocab.json")
13
14# Load model
15config = XttsConfig()
16config.load_json(config_path)
17
18model = Xtts.init_from_config(config)
19model.load_checkpoint(
20 config,
21 checkpoint_dir=os.path.dirname(model_path),
22 checkpoint_path=model_path,
23 vocab_path=vocab_path,
24 use_deepspeed=False
25)
26model.cuda()
27
28# Generate speech (download a sample reference audio first)
29ref_audio = hf_hub_download(repo_id=repo_id, filename="samples/speaker_reference.wav")
30gpt_cond_latent, speaker_embedding = model.get_conditioning_latents(audio_path=ref_audio)
31
32out = model.inference(
33 text="Hello, this is a test of the fine-tuned XTTS model.",
34 language="en",
35 gpt_cond_latent=gpt_cond_latent,
36 speaker_embedding=speaker_embedding,
37)
38
39wav = torch.tensor(out["wav"]).unsqueeze(0)
40torchaudio.save("output.wav", wav, 24000)