File size: 626 Bytes
17ed7d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from TTS.api import TTS

# Initialize the TTS object
tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2", progress_bar=True)
tts.to("cpu")  # Use CPU if GPU is not available

# Define the text and output file path
text = "Hello, this is a test of the XTTS v2 text-to-speech model."
output_audio_path = "output_audio.wav"

# Generate speech using a specific speaker ID
tts.tts_to_file(
    text=text,
    file_path=output_audio_path,
    speaker="Ana Florence",  # Use a valid speaker ID
    language="en"  # Specify the language
)

print(f"Speech generated and saved to {output_audio_path}")