Yurii Paniv commited on
Commit
6edda28
1 Parent(s): 8d7e3e3

Add tests for formatter

Browse files
tests/test_formatter.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ukrainian_tts.formatter import preprocess_text
2
+
3
+
4
+ def test_formatter():
5
+ examples = [
6
+ ("Quality of life update", "КВюаліті оф ліфе юпдате"),
7
+ ("Він украв 20000000 $", "Він украв двадцять мільйонів долар"),
8
+ ("111 000 000 000 доларів державного боргу.", "сто одинадцять мільярдів доларів державного боргу."),
9
+ ("11100000001 доларів державного боргу.", "одинадцять мільярдів сто мільйонів один доларів державного боргу."),
10
+ ("це 19-річне вино.", "це дев'ятнадцять-річне вино."),
11
+ ("10-30-40-50-5-9-5", "десять-тридцять-сорок-п'ятдесят-п'ять-дев'ять-п'ять")
12
+ ]
13
+ for item in examples:
14
+ assert preprocess_text(item[0]) == item[1]
ukrainian_tts/formatter.py CHANGED
@@ -1,6 +1,5 @@
1
  import num2words
2
  import re
3
- from .stress import sentence_to_stress, stress_dict, stress_with_model
4
 
5
 
6
  def preprocess_text(text, use_autostress_model=False):
@@ -77,28 +76,5 @@ def preprocess_text(text, use_autostress_model=False):
77
  text = text.replace(english_char.upper(), english[english_char].upper())
78
  text = text.replace(english_char, english[english_char])
79
 
80
- text = sentence_to_stress(
81
- text, stress_with_model if use_autostress_model else stress_dict
82
- )
83
 
84
- return text
85
-
86
-
87
- if __name__ == "__main__":
88
- assert preprocess_text("Quality of life update") == "КВюаліті оф ліфе юпдате"
89
- assert (
90
- preprocess_text("Він украв 20000000 $") == "Він украв двадцять мільйонів долар"
91
- )
92
- assert (
93
- preprocess_text("111 000 000 000 доларів державного боргу.")
94
- == "сто одинадцять мільярдів доларів державного боргу."
95
- )
96
- assert (
97
- preprocess_text("11100000001 доларів державного боргу.")
98
- == "одинадцять мільярдів сто мільйонів одна доларів державного боргу."
99
- )
100
- assert preprocess_text("це 19-річне вино.") == "це дев'ятнадцять-річне вино."
101
- assert (
102
- preprocess_text("10-30-40-50-5-9-5")
103
- == "десять-тридцять-сорок-п'ятдесят-п'ять-дев'ять-п'ять"
104
- )
1
  import num2words
2
  import re
 
3
 
4
 
5
  def preprocess_text(text, use_autostress_model=False):
76
  text = text.replace(english_char.upper(), english[english_char].upper())
77
  text = text.replace(english_char, english[english_char])
78
 
 
 
 
79
 
80
+ return text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ukrainian_tts/tts.py CHANGED
@@ -4,6 +4,7 @@ from os.path import exists, join
4
  from TTS.utils.synthesizer import Synthesizer
5
  from enum import Enum
6
  from .formatter import preprocess_text
 
7
  from torch import no_grad
8
 
9
  class Voices(Enum):
@@ -55,6 +56,7 @@ class TTS:
55
  raise ValueError(f"Invalid value for voice selected! Please use one of the following values: {', '.join([option.value for option in Voices])}.")
56
 
57
  text = preprocess_text(text, stress)
 
58
 
59
  with no_grad():
60
  wavs = self.synthesizer.tts(text, speaker_name=voice)
4
  from TTS.utils.synthesizer import Synthesizer
5
  from enum import Enum
6
  from .formatter import preprocess_text
7
+ from .stress import sentence_to_stress, stress_dict, stress_with_model
8
  from torch import no_grad
9
 
10
  class Voices(Enum):
56
  raise ValueError(f"Invalid value for voice selected! Please use one of the following values: {', '.join([option.value for option in Voices])}.")
57
 
58
  text = preprocess_text(text, stress)
59
+ text = sentence_to_stress(text, stress_with_model if stress else stress_dict)
60
 
61
  with no_grad():
62
  wavs = self.synthesizer.tts(text, speaker_name=voice)