|
from TTS.api import TTS
|
|
import simpleaudio as sa
|
|
import torch
|
|
|
|
|
|
if torch.cuda.is_available():
|
|
device = "cuda"
|
|
else:
|
|
device = "cpu"
|
|
|
|
|
|
tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2", progress_bar=True)
|
|
tts.to(device)
|
|
|
|
|
|
output_audio_path = "output_audio.wav"
|
|
|
|
|
|
print("Enter text to generate speech. Type 'exit' to quit.")
|
|
while True:
|
|
|
|
text = input("Enter text: ")
|
|
|
|
|
|
if text.lower() == "exit":
|
|
print("Exiting...")
|
|
break
|
|
|
|
|
|
tts.tts_to_file(
|
|
text=text,
|
|
file_path=output_audio_path,
|
|
speaker="Ana Florence",
|
|
language="en"
|
|
)
|
|
|
|
print(f"Speech generated and saved to {output_audio_path}")
|
|
|
|
|
|
wave_obj = sa.WaveObject.from_wave_file(output_audio_path)
|
|
play_obj = wave_obj.play()
|
|
play_obj.wait_done() |