Spaces:
Sleeping
Sleeping
| import os | |
| import gradio as gr | |
| from TTS.api import TTS | |
| import torch | |
| # Accept Coqui TTS license automatically | |
| os.environ["COQUI_TOS_AGREED"] = "1" | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2").to(device) | |
| def clone_voice(sample_audio, text): | |
| if sample_audio is None or text.strip() == "": | |
| return None | |
| output_path = "output.wav" | |
| tts.tts_to_file( | |
| text=text, | |
| file_path=output_path, | |
| speaker_wav=sample_audio, | |
| language="en" | |
| ) | |
| return output_path | |
| demo = gr.Interface( | |
| fn=clone_voice, | |
| inputs=[gr.Audio(type="filepath"), gr.Textbox(label="Enter text")], | |
| outputs=gr.Audio(type="filepath"), | |
| title="π€ Voice Cloning App (XTTS-v2)" | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |