Spaces:
Runtime error
Runtime error
| import os | |
| from TTS.api import TTS | |
| import gradio as gr | |
| # β³ License agreement auto accept | |
| os.environ["COQUI_TOS_AGREED"] = "1" | |
| # π€ Load model | |
| tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2", progress_bar=False, gpu=False) | |
| # π’ Voice clone + TTS function | |
| def clone_and_speak(audio, text, speed): | |
| if audio is None or text.strip() == "": | |
| return "Please upload a voice sample and enter some text." | |
| output_path = "output.wav" | |
| tts.tts_to_file(text=text, speaker_wav=audio, file_path=output_path, speed=speed) | |
| return output_path | |
| # π¨ UI Design | |
| with gr.Blocks() as demo: | |
| gr.Markdown("<h1 style='text-align: center; color: #4CAF50;'>ποΈ Voice Cloning Tool</h1>") | |
| with gr.Row(): | |
| with gr.Column(): | |
| audio_input = gr.Audio(type="filepath", label="Upload Your Voice Sample") | |
| text_input = gr.Textbox(label="Enter text to speak in your voice") | |
| speed_input = gr.Slider(minimum=0.5, maximum=1.5, value=1.0, step=0.1, label="Speed") | |
| submit_button = gr.Button("Clone Voice") | |
| with gr.Column(): | |
| audio_output = gr.Audio(label="Cloned Voice Output") | |
| submit_button.click(fn=clone_and_speak, inputs=[audio_input, text_input, speed_input], outputs=audio_output) | |
| demo.launch() | |