Spaces:
Running
Running
Yurii Paniv
commited on
Commit
•
77f184e
1
Parent(s):
e5a3778
Apply black formatter
Browse files- app.py +25 -5
- formatter.py +20 -8
app.py
CHANGED
@@ -110,11 +110,31 @@ iface = gr.Interface(
|
|
110 |
+ "Github: [https://github.com/robinhad/ukrainian-tts](https://github.com/robinhad/ukrainian-tts)"
|
111 |
+ f'<center><img src="{badge}" alt="visitors badge"/></center>',
|
112 |
examples=[
|
113 |
-
[
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
],
|
119 |
)
|
120 |
iface.launch(enable_queue=True, prevent_thread_lock=True)
|
|
|
110 |
+ "Github: [https://github.com/robinhad/ukrainian-tts](https://github.com/robinhad/ukrainian-tts)"
|
111 |
+ f'<center><img src="{badge}" alt="visitors badge"/></center>',
|
112 |
examples=[
|
113 |
+
[
|
114 |
+
"Введ+іть, б+удь л+аска, сво+є р+ечення.",
|
115 |
+
VoiceOption.FemaleVoice.value,
|
116 |
+
StressOption.ManualStress.value,
|
117 |
+
],
|
118 |
+
[
|
119 |
+
"Введ+іть, б+удь л+аска, сво+є р+ечення.",
|
120 |
+
VoiceOption.MaleVoice.value,
|
121 |
+
StressOption.ManualStress.value,
|
122 |
+
],
|
123 |
+
[
|
124 |
+
"Введіть, будь ласка, своє речення.",
|
125 |
+
VoiceOption.MaleVoice.value,
|
126 |
+
StressOption.ManualStress.value,
|
127 |
+
],
|
128 |
+
[
|
129 |
+
"Привіт, як тебе звати?",
|
130 |
+
VoiceOption.FemaleVoice.value,
|
131 |
+
StressOption.AutomaticStress.value,
|
132 |
+
],
|
133 |
+
[
|
134 |
+
"Договір підписано 4 квітня 1949 року.",
|
135 |
+
VoiceOption.FemaleVoice.value,
|
136 |
+
StressOption.AutomaticStress.value,
|
137 |
+
],
|
138 |
],
|
139 |
)
|
140 |
iface.launch(enable_queue=True, prevent_thread_lock=True)
|
formatter.py
CHANGED
@@ -2,6 +2,7 @@ import num2words
|
|
2 |
import re
|
3 |
from stress import sentence_to_stress
|
4 |
|
|
|
5 |
def preprocess_text(text, autostress=False):
|
6 |
# currencies
|
7 |
text = text.replace("$", "долар")
|
@@ -11,12 +12,12 @@ def preprocess_text(text, autostress=False):
|
|
11 |
text = text.replace("`", "'")
|
12 |
text = text.replace("ʼ", "'")
|
13 |
# numbers
|
14 |
-
text = re.sub(r
|
15 |
|
16 |
def detect_num_and_convert(word):
|
17 |
numbers = "0123456789,."
|
18 |
result = []
|
19 |
-
parts = word.split("-")
|
20 |
for part in parts:
|
21 |
is_number = all(map(lambda x: x in numbers, part))
|
22 |
if is_number:
|
@@ -28,7 +29,7 @@ def preprocess_text(text, autostress=False):
|
|
28 |
result.append(part)
|
29 |
return "-".join(result)
|
30 |
|
31 |
-
#print([detect_num_and_convert(word) for word in text.split(" ")])
|
32 |
text = " ".join([detect_num_and_convert(word) for word in text.split(" ")])
|
33 |
|
34 |
# fallback numbers
|
@@ -73,7 +74,7 @@ def preprocess_text(text, autostress=False):
|
|
73 |
}
|
74 |
for english_char in english.keys():
|
75 |
# uppercase
|
76 |
-
text = text.replace(english_char.upper(),
|
77 |
text = text.replace(english_char, english[english_char])
|
78 |
|
79 |
if autostress:
|
@@ -84,8 +85,19 @@ def preprocess_text(text, autostress=False):
|
|
84 |
|
85 |
if __name__ == "__main__":
|
86 |
assert preprocess_text("Quality of life update") == "КВюаліті оф ліфе юпдате"
|
87 |
-
assert
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
assert preprocess_text("це 19-річне вино.") == "це дев'ятнадцять-річне вино."
|
91 |
-
assert
|
|
|
|
|
|
|
|
2 |
import re
|
3 |
from stress import sentence_to_stress
|
4 |
|
5 |
+
|
6 |
def preprocess_text(text, autostress=False):
|
7 |
# currencies
|
8 |
text = text.replace("$", "долар")
|
|
|
12 |
text = text.replace("`", "'")
|
13 |
text = text.replace("ʼ", "'")
|
14 |
# numbers
|
15 |
+
text = re.sub(r"(\d)\s+(\d)", r"\1\2", text)
|
16 |
|
17 |
def detect_num_and_convert(word):
|
18 |
numbers = "0123456789,."
|
19 |
result = []
|
20 |
+
parts = word.split("-") # for handling complex words
|
21 |
for part in parts:
|
22 |
is_number = all(map(lambda x: x in numbers, part))
|
23 |
if is_number:
|
|
|
29 |
result.append(part)
|
30 |
return "-".join(result)
|
31 |
|
32 |
+
# print([detect_num_and_convert(word) for word in text.split(" ")])
|
33 |
text = " ".join([detect_num_and_convert(word) for word in text.split(" ")])
|
34 |
|
35 |
# fallback numbers
|
|
|
74 |
}
|
75 |
for english_char in english.keys():
|
76 |
# uppercase
|
77 |
+
text = text.replace(english_char.upper(), english[english_char].upper())
|
78 |
text = text.replace(english_char, english[english_char])
|
79 |
|
80 |
if autostress:
|
|
|
85 |
|
86 |
if __name__ == "__main__":
|
87 |
assert preprocess_text("Quality of life update") == "КВюаліті оф ліфе юпдате"
|
88 |
+
assert (
|
89 |
+
preprocess_text("Він украв 20000000 $") == "Він украв двадцять мільйонів долар"
|
90 |
+
)
|
91 |
+
assert (
|
92 |
+
preprocess_text("111 000 000 000 доларів державного боргу.")
|
93 |
+
== "сто одинадцять мільярдів доларів державного боргу."
|
94 |
+
)
|
95 |
+
assert (
|
96 |
+
preprocess_text("11100000001 доларів державного боргу.")
|
97 |
+
== "одинадцять мільярдів сто мільйонів одна доларів державного боргу."
|
98 |
+
)
|
99 |
assert preprocess_text("це 19-річне вино.") == "це дев'ятнадцять-річне вино."
|
100 |
+
assert (
|
101 |
+
preprocess_text("10-30-40-50-5-9-5")
|
102 |
+
== "десять-тридцять-сорок-п'ятдесят-п'ять-дев'ять-п'ять"
|
103 |
+
)
|