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}") |