Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load the japanese phonemizer only if there's an environment variable set #2826

Closed
wants to merge 13 commits into from
Closed
2 changes: 2 additions & 0 deletions .github/workflows/zoo_tests0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:

test:
runs-on: ubuntu-latest
env:
ENABLE_JAPANESE: 1
strategy:
fail-fast: false
matrix:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/zoo_tests1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:

test:
runs-on: ubuntu-latest
env:
ENABLE_JAPANESE: 1
strategy:
fail-fast: false
matrix:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/zoo_tests2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:

test:
runs-on: ubuntu-latest
env:
ENABLE_JAPANESE: 1
strategy:
fail-fast: false
matrix:
Expand Down
28 changes: 14 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@ help:
target_dirs := tests TTS notebooks recipes

test_all: ## run tests and don't stop on an error.
nose2 --with-coverage --coverage TTS tests
./run_bash_tests.sh
ENABLE_JAPANESE=1 nose2 --with-coverage --coverage TTS tests
ENABLE_JAPANESE=1 ./run_bash_tests.sh

test: ## run tests.
nose2 -F -v -B --with-coverage --coverage TTS tests
ENABLE_JAPANESE=1 nose2 -F -v -B --with-coverage --coverage TTS tests

test_vocoder: ## run vocoder tests.
nose2 -F -v -B --with-coverage --coverage TTS tests.vocoder_tests
ENABLE_JAPANESE=1 nose2 -F -v -B --with-coverage --coverage TTS tests.vocoder_tests

test_tts: ## run tts tests.
nose2 -F -v -B --with-coverage --coverage TTS tests.tts_tests
ENABLE_JAPANESE=1 nose2 -F -v -B --with-coverage --coverage TTS tests.tts_tests

test_tts2: ## run tts tests.
nose2 -F -v -B --with-coverage --coverage TTS tests.tts_tests2
ENABLE_JAPANESE=1 nose2 -F -v -B --with-coverage --coverage TTS tests.tts_tests2

test_aux: ## run aux tests.
nose2 -F -v -B --with-coverage --coverage TTS tests.aux_tests
./run_bash_tests.sh
ENABLE_JAPANESE=1 nose2 -F -v -B --with-coverage --coverage TTS tests.aux_tests
ENABLE_JAPANESE=1 ./run_bash_tests.sh

test_zoo: ## run zoo tests.
nose2 -F -v -B --with-coverage --coverage TTS tests.zoo_tests
ENABLE_JAPANESE=1 nose2 -F -v -B --with-coverage --coverage TTS tests.zoo_tests

inference_tests: ## run inference tests.
nose2 -F -v -B --with-coverage --coverage TTS tests.inference_tests
ENABLE_JAPANESE=1 nose2 -F -v -B --with-coverage --coverage TTS tests.inference_tests

api_tests: ## run api tests.
nose2 -F -v -B --with-coverage --coverage TTS tests.api_tests
ENABLE_JAPANESE=1 nose2 -F -v -B --with-coverage --coverage TTS tests.api_tests

data_tests: ## run data tests.
nose2 -F -v -B --with-coverage --coverage TTS tests.data_tests
ENABLE_JAPANESE=1 nose2 -F -v -B --with-coverage --coverage TTS tests.data_tests

test_text: ## run text tests.
nose2 -F -v -B --with-coverage --coverage TTS tests.text_tests
ENABLE_JAPANESE=1 nose2 -F -v -B --with-coverage --coverage TTS tests.text_tests

test_failed: ## only run tests failed the last time.
nose2 -F -v -B --with-coverage --coverage TTS tests
ENABLE_JAPANESE=1 nose2 -F -v -B --with-coverage --coverage TTS tests

style: ## update code style.
black ${target_dirs}
Expand Down
18 changes: 14 additions & 4 deletions TTS/tts/utils/text/phonemizers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@
from TTS.tts.utils.text.phonemizers.base import BasePhonemizer
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.ja_jp_phonemizer import JA_JP_Phonemizer
import os
if "ENABLE_JAPANESE" in os.environ:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can easily try-catch the import and show a warning if the user wants to use JA but it is not installed. ENV variable is not necessary as we already expect you to show your intentions when you install TTS with pip install TTS[ja]

JAPANESE_ENABLED = True
from TTS.tts.utils.text.phonemizers.ja_jp_phonemizer import JA_JP_Phonemizer
else:
JAPANESE_ENABLED = False
print("Japanese disabled. Please create an environment variable named ENABLE_JAPANESE and install additional dependencies if you need to generate Japanese speech.")
from TTS.tts.utils.text.phonemizers.ko_kr_phonemizer import KO_KR_Phonemizer
from TTS.tts.utils.text.phonemizers.zh_cn_phonemizer import ZH_CN_Phonemizer

PHONEMIZERS = {b.name(): b for b in (ESpeak, Gruut, JA_JP_Phonemizer)}
phonemizer_classes = [ESpeak, Gruut]
if JAPANESE_ENABLED:
phonemizer_classes.append(JA_JP_Phonemizer);
PHONEMIZERS = {b.name(): b for b in phonemizer_classes}


ESPEAK_LANGS = list(ESpeak.supported_languages().keys())
Expand All @@ -26,7 +35,8 @@

# Force default for some languages
DEF_LANG_TO_PHONEMIZER["en"] = DEF_LANG_TO_PHONEMIZER["en-us"]
DEF_LANG_TO_PHONEMIZER["ja-jp"] = JA_JP_Phonemizer.name()
if JAPANESE_ENABLED:
DEF_LANG_TO_PHONEMIZER["ja-jp"] = JA_JP_Phonemizer.name()
DEF_LANG_TO_PHONEMIZER["zh-cn"] = ZH_CN_Phonemizer.name()
DEF_LANG_TO_PHONEMIZER["ko-kr"] = KO_KR_Phonemizer.name()
DEF_LANG_TO_PHONEMIZER["bn"] = BN_Phonemizer.name()
Expand All @@ -48,7 +58,7 @@ def get_phonemizer_by_name(name: str, **kwargs) -> BasePhonemizer:
return Gruut(**kwargs)
if name == "zh_cn_phonemizer":
return ZH_CN_Phonemizer(**kwargs)
if name == "ja_jp_phonemizer":
if name == "ja_jp_phonemizer" and JAPANESE_ENABLED:
return JA_JP_Phonemizer(**kwargs)
if name == "ko_kr_phonemizer":
return KO_KR_Phonemizer(**kwargs)
Expand Down
Loading