File size: 1,712 Bytes
be1bb68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
from TTS.utils.synthesizer import Synthesizer
from huggingface_hub import hf_hub_download
import gradio as gr
import tempfile

REPO_ID = "jhlfrfufyfn/bel-tts"

my_title = "Беларускі тэкст-у-маўленне"
my_description = "Беларускамоўны мадэль для агучвання тэкста. "

be_text = "Гепарды жывуць у адкрытых і прасторных месцах, дзе ёсць шмат здабычы."

my_inputs = [
  gr.inputs.Textbox(lines=5, label="Input Text", default=be_text),
]

my_outputs = gr.outputs.Audio(type="file", label="Output Audio")

def tts(text: str):
    best_model_path = hf_hub_download(repo_id=REPO_ID, filename="model.pth") 
    config_path = hf_hub_download(repo_id=REPO_ID, filename="config.json")
    vocoder_path = hf_hub_download(repo_id=REPO_ID, filename="vocoder.pth")
    scale_stats_path = hf_hub_download(repo_id=REPO_ID, filename="scale_stats.npy")
    vocoder_config_path = hf_hub_download(repo_id=REPO_ID, filename="vocoder_config.json")
    
    # init synthesizer  
    synthesizer = Synthesizer(
        best_model_path,
        config_path,
        None,
        None,
        vocoder_path,
        vocoder_config_path,
        None,
        None,
        False
    )

    # create audio file
    wavs = synthesizer.tts(text)
    with tempfile.NamedTemporaryFile(suffix = ".wav", delete = False) as fp:
        synthesizer.save_wav(wavs, fp)                      
    return fp.name 


iface = gr.Interface(
    fn=tts, 
    inputs=my_inputs, 
    outputs=my_outputs, 
    title=my_title, 
    description = my_description, 
    article = "",
    examples = "", 
    allow_flagging=False
)
iface.launch()