File size: 1,402 Bytes
0ebcf15
 
 
 
 
 
 
 
 
28ea968
 
0ebcf15
 
 
20636e5
28ea968
 
0ebcf15
 
 
 
 
 
28ea968
 
 
0ebcf15
 
 
 
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
import gradio as gr
import torch.cuda

from InferenceInterfaces.ControllableInterface import ControllableInterface
from Utility.utils import float2pcm


class TTSWebUI:

    def __init__(self, gpu_id="cpu", title="Simplistic Stochastic Speech Synthesis with ToucanTTS", article="For a multilingual version, have a look at https://huggingface.co/spaces/Flux9665/MassivelyMultilingualTTS"):
        self.controllable_ui = ControllableInterface(gpu_id=gpu_id)
        self.iface = gr.Interface(fn=self.read,
                                  inputs=[gr.Textbox(lines=2,
                                                     placeholder="write what you want the synthesis to read here...",
                                                     value="What I cannot create, I do not understand.",
                                                     label="Text input")],
                                  outputs=[gr.Audio(type="numpy", label="Speech")],
                                  title=title,
                                  theme="default",
                                  allow_flagging="never",
                                  article=article)
        self.iface.launch()

    def read(self, prompt):
        sr, wav = self.controllable_ui.read(prompt, -24.)
        return sr, float2pcm(wav)


if __name__ == '__main__':
    TTSWebUI(gpu_id="cuda" if torch.cuda.is_available() else "cpu")