Spaces:
Running
Running
Yurii Paniv
commited on
Commit
·
7927694
1
Parent(s):
86e7d18
#22 Support acute accent in text
Browse files- tests/test_stress.py +4 -0
- ukrainian_tts/formatter.py +1 -1
- ukrainian_tts/stress.py +9 -3
tests/test_stress.py
CHANGED
|
@@ -7,6 +7,10 @@ def test_stress_table():
|
|
| 7 |
"Бабин біб розцвів у дощ — Буде бабі біб у борщ.\n\nБоронила",
|
| 8 |
"Б+абин б+іб розцв+ів +у д+ощ — Б+уде б+абі б+іб +у б+орщ.\n\nБорон+ила",
|
| 9 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
(
|
| 11 |
"Бабин біб розцвів у дощ — Буде бабі біб у борщ.,,Боронила",
|
| 12 |
"Б+абин б+іб розцв+ів +у д+ощ — Б+уде б+абі б+іб +у б+орщ.,,Борон+ила",
|
|
|
|
| 7 |
"Бабин біб розцвів у дощ — Буде бабі біб у борщ.\n\nБоронила",
|
| 8 |
"Б+абин б+іб розцв+ів +у д+ощ — Б+уде б+абі б+іб +у б+орщ.\n\nБорон+ила",
|
| 9 |
),
|
| 10 |
+
(
|
| 11 |
+
"Баби\u0301н біб розцвів.",
|
| 12 |
+
"Баб+ин б+іб розцв+ів.",
|
| 13 |
+
), # handle acute accent
|
| 14 |
(
|
| 15 |
"Бабин біб розцвів у дощ — Буде бабі біб у борщ.,,Боронила",
|
| 16 |
"Б+абин б+іб розцв+ів +у д+ощ — Б+уде б+абі б+іб +у б+орщ.,,Борон+ила",
|
ukrainian_tts/formatter.py
CHANGED
|
@@ -92,7 +92,7 @@ def preprocess_text(text):
|
|
| 92 |
"y": "і",
|
| 93 |
"z": "з",
|
| 94 |
}
|
| 95 |
-
for english_char, english_value in english.
|
| 96 |
# uppercase
|
| 97 |
text = text.replace(english_char.upper(), english_value.upper())
|
| 98 |
text = text.replace(english_char, english_value)
|
|
|
|
| 92 |
"y": "і",
|
| 93 |
"z": "з",
|
| 94 |
}
|
| 95 |
+
for english_char, english_value in english.items():
|
| 96 |
# uppercase
|
| 97 |
text = text.replace(english_char.upper(), english_value.upper())
|
| 98 |
text = text.replace(english_char, english_value)
|
ukrainian_tts/stress.py
CHANGED
|
@@ -10,17 +10,19 @@ special = "'-"
|
|
| 10 |
alphabet = vowels + consonants + special + "+"
|
| 11 |
|
| 12 |
|
| 13 |
-
def _shift_stress(stressed):
|
| 14 |
new_stressed = ""
|
| 15 |
start = 0
|
| 16 |
last = 0
|
| 17 |
|
| 18 |
# shift stress symbol by one "при+віт" -> "пр+ивіт"
|
| 19 |
while True:
|
| 20 |
-
plus_position = stressed.find(
|
| 21 |
if plus_position != -1:
|
| 22 |
new_stressed += (
|
| 23 |
-
stressed[last : plus_position - 1]
|
|
|
|
|
|
|
| 24 |
)
|
| 25 |
start = plus_position + 1
|
| 26 |
last = start
|
|
@@ -44,6 +46,10 @@ def stress_dict(sentence: str):
|
|
| 44 |
|
| 45 |
|
| 46 |
def sentence_to_stress(sentence: str, stress_function=stress_dict) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
# save custom stress positions
|
| 48 |
all_stresses = []
|
| 49 |
orig_words = sentence.split(" ")
|
|
|
|
| 10 |
alphabet = vowels + consonants + special + "+"
|
| 11 |
|
| 12 |
|
| 13 |
+
def _shift_stress(stressed, symboll_to_shift="+"):
|
| 14 |
new_stressed = ""
|
| 15 |
start = 0
|
| 16 |
last = 0
|
| 17 |
|
| 18 |
# shift stress symbol by one "при+віт" -> "пр+ивіт"
|
| 19 |
while True:
|
| 20 |
+
plus_position = stressed.find(symboll_to_shift, start)
|
| 21 |
if plus_position != -1:
|
| 22 |
new_stressed += (
|
| 23 |
+
stressed[last : plus_position - 1]
|
| 24 |
+
+ symboll_to_shift
|
| 25 |
+
+ stressed[plus_position - 1]
|
| 26 |
)
|
| 27 |
start = plus_position + 1
|
| 28 |
last = start
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
def sentence_to_stress(sentence: str, stress_function=stress_dict) -> str:
|
| 49 |
+
# replace acute accent with plus
|
| 50 |
+
sentence = _shift_stress(sentence, "́")
|
| 51 |
+
sentence = sentence.replace("́", "+")
|
| 52 |
+
|
| 53 |
# save custom stress positions
|
| 54 |
all_stresses = []
|
| 55 |
orig_words = sentence.split(" ")
|