Yurii Paniv commited on
Commit
9e96240
1 Parent(s): 2196691

Apply stress model for words with vowel_count > 1

Browse files
Files changed (3) hide show
  1. app.py +2 -2
  2. requirements.txt +1 -1
  3. stress.py +15 -3
app.py CHANGED
@@ -60,7 +60,7 @@ def tts(text: str, stress: str):
60
  with torch.no_grad():
61
  wavs = synthesizer.tts(text)
62
  synthesizer.save_wav(wavs, fp)
63
- return fp.name
64
 
65
 
66
  iface = gr.Interface(
@@ -75,7 +75,7 @@ iface = gr.Interface(
75
  choices=[option.value for option in StressOption],
76
  ),
77
  ],
78
- outputs=gr.outputs.Audio(label="Output"),
79
  title="🐸💬🇺🇦 - Coqui TTS",
80
  theme="huggingface",
81
  description="Україномовний🇺🇦 TTS за допомогою Coqui TTS (для наголосу використовуйте + перед голосною)",
60
  with torch.no_grad():
61
  wavs = synthesizer.tts(text)
62
  synthesizer.save_wav(wavs, fp)
63
+ return fp.name, text
64
 
65
 
66
  iface = gr.Interface(
75
  choices=[option.value for option in StressOption],
76
  ),
77
  ],
78
+ outputs=[gr.outputs.Audio(label="Output"), gr.outputs.Textbox(label="Наголошений текст")],
79
  title="🐸💬🇺🇦 - Coqui TTS",
80
  theme="huggingface",
81
  description="Україномовний🇺🇦 TTS за допомогою Coqui TTS (для наголосу використовуйте + перед голосною)",
requirements.txt CHANGED
@@ -1 +1 @@
1
- TTS==0.6.2
1
+ TTS==0.7.1
stress.py CHANGED
@@ -11,7 +11,10 @@ replace_accents = importer.load_pickle("uk-accentor", "replace_accents")
11
  # Back to CPU
12
  # accentor.cpu()
13
 
14
- alphabet = "абгґдеєжзиіїйклмнопрстуфхцчшщьюя"
 
 
 
15
 
16
  def accent_word(word):
17
  with torch.no_grad():
@@ -44,7 +47,14 @@ def sentence_to_stress(sentence):
44
  if not all(first_word_sep) or len(element) == 0:
45
  continue
46
  else:
47
- new_list[word_index] = accent_word(new_list[word_index])
 
 
 
 
 
 
 
48
 
49
  return "".join(new_list)
50
 
@@ -52,10 +62,12 @@ def sentence_to_stress(sentence):
52
  if __name__ == "__main__":
53
  sentence = "Кам'янець-Подільський - місто в Хмельницькій області України, центр Кам'янець-Подільської міської об'єднаної територіальної громади і Кам'янець-Подільського району."
54
  print(sentence_to_stress(sentence))
 
 
55
  #test_words1 = ["словотворення", "архаїчний", "програма", "а-ля-фуршет"]
56
 
57
  stressed_words = accentor.predict(["привіт"], mode='stress')
58
  plused_words = [replace_accents(x) for x in stressed_words]
59
 
60
  print('With stress:', stressed_words)
61
- print('With pluses:', plused_words)
11
  # Back to CPU
12
  # accentor.cpu()
13
 
14
+ vowels = "аеєиіїоуюя"
15
+ consonants = "бвгґджзйклмнпрстфхцчшщь"
16
+ special = "'"
17
+ alphabet = vowels + consonants + special
18
 
19
  def accent_word(word):
20
  with torch.no_grad():
47
  if not all(first_word_sep) or len(element) == 0:
48
  continue
49
  else:
50
+ vowels_in_words = list(map(lambda letter: letter in vowels, new_list[word_index]))
51
+ if vowels_in_words.count(True) == 0:
52
+ continue
53
+ elif vowels_in_words.count(True) == 1:
54
+ vowel_index = vowels_in_words.index(True)
55
+ new_list[word_index] = new_list[word_index][0:vowel_index] + "+" + new_list[word_index][vowel_index::]
56
+ else:
57
+ new_list[word_index] = accent_word(new_list[word_index])
58
 
59
  return "".join(new_list)
60
 
62
  if __name__ == "__main__":
63
  sentence = "Кам'янець-Подільський - місто в Хмельницькій області України, центр Кам'янець-Подільської міської об'єднаної територіальної громади і Кам'янець-Подільського району."
64
  print(sentence_to_stress(sentence))
65
+ sentence = "Привіт, як тебе звати?"
66
+ print(sentence_to_stress(sentence))
67
  #test_words1 = ["словотворення", "архаїчний", "програма", "а-ля-фуршет"]
68
 
69
  stressed_words = accentor.predict(["привіт"], mode='stress')
70
  plused_words = [replace_accents(x) for x in stressed_words]
71
 
72
  print('With stress:', stressed_words)
73
+ print('With pluses:', plused_words)