File size: 1,518 Bytes
1cb0fa6
 
 
 
 
 
 
 
54cb645
1cb0fa6
67f1cda
1cb0fa6
 
 
54cb645
 
1cb0fa6
 
 
12079a8
 
4669deb
1cb0fa6
c2b5d4a
b770598
4669deb
 
 
 
 
 
1cb0fa6
 
 
 
 
 
 
 
 
 
 
 
 
67f1cda
1cb0fa6
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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('<center>[ip] :: text</center>')
  ip1 = gr.Textbox()
  gr.Markdown('<center>[ip] :: audio</center>')
  ip2 = gr.Audio(type='filepath')
  gr.Markdown("<hr>")
  p = gr.Button('vcTTS') # voice clone - TTS
  gr.Markdown("<hr>")
  gr.Markdown('<center>[op] :: text-audio</center>')
  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)