Skip to content

Commit

Permalink
Fix language flags generated by espeak-ng phonemizer (#1801)
Browse files Browse the repository at this point in the history
* fix language flags generated by espeak-ng phonemizer

* Style

* Updated language flag regex to consider all language codes alike
  • Loading branch information
Lokhozt authored Aug 7, 2022
1 parent 8c64508 commit 75ac9e3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions TTS/tts/utils/text/phonemizers/espeak_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import re
import subprocess
from typing import Dict, List

Expand Down Expand Up @@ -163,6 +164,13 @@ def phonemize_espeak(self, text: str, separator: str = "|", tie=False) -> str:

# dealing with the conditions descrived above
ph_decoded = ph_decoded[:1].replace("_", "") + ph_decoded[1:]

# espeak-ng backend can add language flags that need to be removed:
# "sɛʁtˈɛ̃ mˈo kɔm (en)fˈʊtbɔːl(fr) ʒenˈɛʁ de- flˈaɡ də- lˈɑ̃ɡ."
# phonemize needs to remove the language flags of the returned text:
# "sɛʁtˈɛ̃ mˈo kɔm fˈʊtbɔːl ʒenˈɛʁ de- flˈaɡ də- lˈɑ̃ɡ."
ph_decoded = re.sub(r"\(.+?\)", "", ph_decoded)

phonemes += ph_decoded.strip()
return phonemes.replace("_", separator)

Expand Down

0 comments on commit 75ac9e3

Please sign in to comment.