| from TTS.api import TTS |
| import gradio as gr |
| import torch |
|
|
| tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2") |
| tts.to("cuda" if torch.cuda.is_available() else "cpu") |
|
|
| def synthesize(text, speaker_wav): |
| output_path = "output.wav" |
| if speaker_wav is None: |
| return "No voice sample uploaded.", None |
|
|
| speaker_path = "temp_speaker.wav" |
| speaker_wav.save(speaker_path) |
|
|
| tts.tts_to_file( |
| text=text, |
| speaker_wav=speaker_path, |
| language="en", |
| file_path=output_path |
| ) |
| return "Done. Listen below.", output_path |
|
|
| iface = gr.Interface( |
| fn=synthesize, |
| inputs=[ |
| gr.Textbox(label="Text to Speak", placeholder="Come closer... I've been waiting in the dark."), |
| gr.Audio(source="upload", type="file", label="Creepy Voice Sample") |
| ], |
| outputs=[ |
| gr.Textbox(label="Status"), |
| gr.Audio(label="Result Audio") |
| ], |
| title="XTTS‑V2 Horror Whisperer 👻", |
| description="Upload a voice and make it say creepy stuff. XTTS‑v2 powered, GPU-juiced. 🧟♂️💀" |
| ) |
|
|
| if __name__ == "__main__": |
| iface.launch() |
|
|