jhlfrfufyfn commited on
Commit
5dfe98a
1 Parent(s): e6797ff

Create app.py

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