Skip to content

Commit

Permalink
fix: make korean g2p deps optional
Browse files Browse the repository at this point in the history
  • Loading branch information
eginhard committed May 8, 2024
1 parent 8a3d5d1 commit 7096ad8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ The following extras allow the installation of optional dependencies:
| `server` | Dependencies to run the TTS server |
| `bn` | Bangla G2P |
| `ja` | Japanese G2P |
| `ko` | Korean G2P |
| `zh` | Chinese G2P |
| `languages` | All language-specific dependencies |

Expand Down
7 changes: 5 additions & 2 deletions TTS/tts/layers/xtts/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from functools import cached_property

import torch
from hangul_romanize import Transliter
from hangul_romanize.rule import academic
from num2words import num2words
from spacy.lang.ar import Arabic
from spacy.lang.en import English
Expand Down Expand Up @@ -592,6 +590,11 @@ def japanese_cleaners(text, katsu):


def korean_transliterate(text):
try:
from hangul_romanize import Transliter
from hangul_romanize.rule import academic
except ImportError as e:
raise ImportError("Korean requires: hangul_romanize") from e
r = Transliter(academic)
return r.translit(text)

Expand Down
5 changes: 4 additions & 1 deletion TTS/tts/utils/text/korean/phonemizer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from jamo import hangul_to_jamo
try:
from jamo import hangul_to_jamo
except ImportError as e:
raise ImportError("Korean requires: g2pkk, jamo") from e

from TTS.tts.utils.text.korean.korean import normalize

Expand Down
14 changes: 11 additions & 3 deletions TTS/tts/utils/text/phonemizers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from TTS.tts.utils.text.phonemizers.belarusian_phonemizer import BEL_Phonemizer
from TTS.tts.utils.text.phonemizers.espeak_wrapper import ESpeak
from TTS.tts.utils.text.phonemizers.gruut_wrapper import Gruut
from TTS.tts.utils.text.phonemizers.ko_kr_phonemizer import KO_KR_Phonemizer

try:
from TTS.tts.utils.text.phonemizers.bangla_phonemizer import BN_Phonemizer
Expand All @@ -14,12 +13,17 @@
except ImportError:
JA_JP_Phonemizer = None

try:
from TTS.tts.utils.text.phonemizers.ko_kr_phonemizer import KO_KR_Phonemizer
except ImportError:
KO_KR_Phonemizer = None

try:
from TTS.tts.utils.text.phonemizers.zh_cn_phonemizer import ZH_CN_Phonemizer
except ImportError:
ZH_CN_Phonemizer = None

PHONEMIZERS = {b.name(): b for b in (ESpeak, Gruut, KO_KR_Phonemizer)}
PHONEMIZERS = {b.name(): b for b in (ESpeak, Gruut)}


ESPEAK_LANGS = list(ESpeak.supported_languages().keys())
Expand All @@ -40,7 +44,6 @@

# Force default for some languages
DEF_LANG_TO_PHONEMIZER["en"] = DEF_LANG_TO_PHONEMIZER["en-us"]
DEF_LANG_TO_PHONEMIZER["ko-kr"] = KO_KR_Phonemizer.name()
DEF_LANG_TO_PHONEMIZER["be"] = BEL_Phonemizer.name()


Expand All @@ -50,6 +53,9 @@
if JA_JP_Phonemizer is not None:
PHONEMIZERS[JA_JP_Phonemizer.name()] = JA_JP_Phonemizer
DEF_LANG_TO_PHONEMIZER["ja-jp"] = JA_JP_Phonemizer.name()
if KO_KR_Phonemizer is not None:
PHONEMIZERS[KO_KR_Phonemizer.name()] = KO_KR_Phonemizer
DEF_LANG_TO_PHONEMIZER["ko-kr"] = KO_KR_Phonemizer.name()
if ZH_CN_Phonemizer is not None:
PHONEMIZERS[ZH_CN_Phonemizer.name()] = ZH_CN_Phonemizer
DEF_LANG_TO_PHONEMIZER["zh-cn"] = ZH_CN_Phonemizer.name()
Expand Down Expand Up @@ -78,6 +84,8 @@ def get_phonemizer_by_name(name: str, **kwargs) -> BasePhonemizer:
raise ValueError("You need to install JA phonemizer dependencies. Try `pip install coqui-tts[ja]`.")
return JA_JP_Phonemizer(**kwargs)
if name == "ko_kr_phonemizer":
if KO_KR_Phonemizer is None:
raise ValueError("You need to install KO phonemizer dependencies. Try `pip install coqui-tts[ko]`.")
return KO_KR_Phonemizer(**kwargs)
if name == "bn_phonemizer":
if BN_Phonemizer is None:
Expand Down
14 changes: 8 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ dependencies = [
# Coqui stack
"coqui-tts-trainer>=0.1",
"coqpit>=0.0.16",
# Korean
"hangul_romanize",
"jamo",
"g2pkk>=0.1.1",
# Gruut + supported languages
"gruut[de,es,fr]==2.2.3",
# Tortoise
Expand Down Expand Up @@ -114,6 +110,12 @@ bn = [
"bnnumerizer",
"bnunicodenormalizer",
]
# Korean
ko = [
"hangul_romanize",
"jamo",
"g2pkk>=0.1.1",
]
# Japanese
ja = [
"mecab-python3",
Expand All @@ -127,11 +129,11 @@ zh = [
]
# All language-specific dependencies
languages = [
"coqui-tts[bn,ja,zh]",
"coqui-tts[bn,ja,ko,zh]",
]
# Installs all extras (except dev and docs)
all = [
"coqui-tts[notebooks,server,bn,ja,zh]",
"coqui-tts[notebooks,server,bn,ja,ko,zh]",
]

[project.urls]
Expand Down

0 comments on commit 7096ad8

Please sign in to comment.