Spaces:
Sleeping
Sleeping
| import spaces | |
| import gradio as gr | |
| import torch | |
| from TTS.api import TTS | |
| import os | |
| os.environ["COQUI_TOS_AGREED"] = "1" | |
| import gradio as gr | |
| import torch | |
| from TTS.api import TTS | |
| import spaces | |
| import os | |
| # 1. Initialize the model on CPU first | |
| # We do this OUTSIDE the function so it doesn't reload every time you click the button | |
| tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=False) | |
| # Give it enough time for voice cloning | |
| def clone(text, audio): | |
| # 2. Check if CUDA is actually available before moving | |
| if torch.cuda.is_available(): | |
| tts.to("cuda") | |
| # 3. Perform the synthesis | |
| tts.tts_to_file( | |
| text=text, | |
| speaker_wav=audio, | |
| language="en", | |
| file_path="./output.wav" | |
| ) | |
| # 4. Move it back to CPU to be a good citizen on ZeroGPU | |
| if torch.cuda.is_available(): | |
| tts.to("cpu") | |
| return "./output.wav" | |
| # ... your Gradio Blocks/Interface code ... | |
| iface = gr.Interface(fn=clone, | |
| inputs=[gr.Textbox(label='Text'),gr.Audio(type='filepath', label='Voice reference audio file')], | |
| outputs=gr.Audio(type='filepath'), | |
| title='Voice Clone', | |
| description=""" | |
| by [Tony Assi](https://www.tonyassi.com/) | |
| --- | |
| <h3>If you like voice clone then try <a href="https://huggingface.co/spaces/tonyassi/video-face-swap" target="_blank" rel="noopener noreferrer">Video Face Swap</a></h3> | |
| --- | |
| This space uses xtts_v2 model. Non-commercial use only. [Coqui Public Model License](https://huggingface.co/coqui/XTTS-v2/blob/main/LICENSE.txt) | |
| Please ❤️ this Space. [Email me](mailto:tony.assi.media@gmail.com). | |
| """, | |
| theme = gr.themes.Base(primary_hue="teal",secondary_hue="teal",neutral_hue="slate"), | |
| examples=[["Hey! It's me Dorthy, from the Wizard of Oz. Type in whatever you'd like me to say.","./audio/Wizard-of-Oz-Dorthy.wav"], | |
| ["It's me Vito Corleone, from the Godfather. Type in whatever you'd like me to say.","./audio/Godfather.wav"], | |
| ["Hey, it's me Paris Hilton. Type in whatever you'd like me to say.","./audio/Paris-Hilton.mp3"], | |
| ["Hey, it's me Megan Fox from Transformers. Type in whatever you'd like me to say.","./audio/Megan-Fox.mp3"], | |
| ["Hey there, it's me Jeff Goldblum. Type in whatever you'd like me to say.","./audio/Jeff-Goldblum.mp3"], | |
| ["Hey there, it's me Heath Ledger as the Joker. Type in whatever you'd like me to say.","./audio/Heath-Ledger.mp3"],]) | |
| iface.launch() |