# print('= ='*8) # print('[io] :: coqui-tts') # !pip install -q coqui-tts # print('= ='*8) # print('[io] :: gradio') # !pip install -q gradio # print('= ='*8) import os import torch import numpy as np import gradio as gr from TTS.api import TTS os.environ["COQUI_TOS_AGREED"] = "1" gcPU = torch.device('cuda' if torch.cuda.is_available() else 'cpu') def func__vcTTS(*ip): print('[p] :: ... processing ...') print(f"[logs] :: processing on '{gcPU}' device") try: vc_tts = TTS(model_name=ip[0], progress_bar=True).to(gcPU) op = torch.tensor(vc_tts.tts(text=ip[1],speaker_wav=ip[2],language='en')).numpy() return 'vcTTS',(24000,op) except ValueError as expn__ve: vc_tts = TTS(model_name=ip[0], progress_bar=True).to(gcPU) op = torch.tensor(vc_tts.tts(text=ip[1],speaker_wav=ip[2])).numpy() return 'vcTTS',(24000,op) except Exception as expn: return expn,gr.Audio() io = gr.Blocks() with gr.Blocks() as io: ip0 = gr.Dropdown(choices=sorted(TTS.list_models()), label="TTS model",value='tts_models/multilingual/multi-dataset/xtts_v2') gr.Markdown('
[ip] :: text
') ip1 = gr.Textbox() gr.Markdown('
[ip] :: audio
') ip2 = gr.Audio(type='filepath') gr.Markdown("
") p = gr.Button('vcTTS') # voice clone - TTS gr.Markdown("
") gr.Markdown('
[op] :: text-audio
') op0 = gr.Textbox() op1 = gr.Audio(type='numpy') p.click(func__vcTTS, inputs=[ip0,ip1,ip2], outputs=[op0,op1]) io.launch(share=False,debug=False)