jhlfrfufyfn commited on
Commit
3390142
1 Parent(s): 035988c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from TTS.utils.synthesizer import Synthesizer
2
+ from huggingface_hub import hf_hub_download
3
+ import gradio as gr
4
+ import tempfile
5
+
6
+ REPO_ID = "jhlfrfufyfn/bel-tts"
7
+
8
+ my_title = "Беларускі тэкст-у-маўленне"
9
+ my_description = "Беларускамоўны мадэль для агучвання тэкста. "
10
+
11
+ be_text = "Гепарды жывуць у адкрытых і прасторных месцах, дзе ёсць шмат здабычы."
12
+
13
+ my_inputs = [
14
+ gr.inputs.Textbox(lines=5, label="Input Text", default=be_text),
15
+ ]
16
+
17
+ my_outputs = gr.outputs.Audio(type="file", label="Output Audio")
18
+
19
+ def tts(text: str):
20
+ best_model_path = hf_hub_download(repo_id=REPO_ID, filename="model.pth")
21
+ config_path = hf_hub_download(repo_id=REPO_ID, filename="config.json")
22
+ vocoder_path = hf_hub_download(repo_id=REPO_ID, filename="vocoder.pth")
23
+ scale_stats_path = hf_hub_download(repo_id=REPO_ID, filename="scale_stats.npy")
24
+ vocoder_config_path = hf_hub_download(repo_id=REPO_ID, filename="vocoder_config.json")
25
+
26
+ # init synthesizer
27
+ synthesizer = Synthesizer(
28
+ best_model_path,
29
+ config_path,
30
+ None,
31
+ None,
32
+ vocoder_path,
33
+ vocoder_config_path,
34
+ None,
35
+ None,
36
+ False
37
+ )
38
+
39
+ # create audio file
40
+ wavs = synthesizer.tts(text)
41
+ with tempfile.NamedTemporaryFile(suffix = ".wav", delete = False) as fp:
42
+ synthesizer.save_wav(wavs, fp)
43
+ return fp.name
44
+
45
+
46
+ iface = gr.Interface(
47
+ fn=tts,
48
+ inputs=my_inputs,
49
+ outputs=my_outputs,
50
+ title=my_title,
51
+ description = my_description,
52
+ article = "",
53
+ examples = "",
54
+ allow_flagging=False
55
+ )
56
+ iface.launch()