Skip to content

Commit

Permalink
fix: make bangla g2p deps optional
Browse files Browse the repository at this point in the history
  • Loading branch information
eginhard committed May 8, 2024
1 parent 4f2eff4 commit ea893c3
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
sed -i 's/https:\/\/coqui.gateway.scarf.sh\//https:\/\/github.com\/coqui-ai\/TTS\/releases\/download\//g' TTS/.models.json
- name: Install TTS
run: |
python3 -m uv pip install --system "coqui-tts[dev,server,ja] @ ."
python3 -m uv pip install --system "coqui-tts[dev,server,languages] @ ."
python3 setup.py egg_info
- name: Unit tests
run: make ${{ matrix.subset }}
Expand Down
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,33 @@ If you plan to code or train models, clone 🐸TTS and install it locally.

```bash
git clone https://github.com/idiap/coqui-ai-TTS
pip install -e .[all,dev,notebooks,server] # Select the relevant extras
pip install -e .
```

### Optional dependencies

The following extras allow the installation of optional dependencies:

| Name | Description |
|------|-------------|
| `all` | All optional dependencies, except `dev` and `docs` |
| `dev` | Development dependencies |
| `dev` | Dependencies for building the documentation |
| `notebooks` | Dependencies only used in notebooks |
| `server` | Dependencies to run the TTS server |
| `bn` | Bangla G2P |
| `ja` | Japanese G2P |
| `languages` | All language-specific dependencies |

You can install them with one of the following commands:

```bash
pip install coqui-tts[server,ja]
pip install -e .[server,ja]
```

### Platforms

If you are on Ubuntu (Debian), you can also run following commands for installation.

```bash
Expand Down
9 changes: 6 additions & 3 deletions TTS/tts/utils/text/bangla/phonemizer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import re

import bangla
from bnnumerizer import numerize
from bnunicodenormalizer import Normalizer
try:
import bangla
from bnnumerizer import numerize
from bnunicodenormalizer import Normalizer
except ImportError as e:
raise ImportError("Bangla requires: bangla, bnnumerizer, bnunicodenormalizer") from e

# initialize
bnorm = Normalizer()
Expand Down
18 changes: 12 additions & 6 deletions TTS/tts/utils/text/phonemizers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from TTS.tts.utils.text.phonemizers.bangla_phonemizer import BN_Phonemizer
from TTS.tts.utils.text.phonemizers.base import BasePhonemizer
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
from TTS.tts.utils.text.phonemizers.zh_cn_phonemizer import ZH_CN_Phonemizer

try:
from TTS.tts.utils.text.phonemizers.bangla_phonemizer import BN_Phonemizer
except ImportError:
BN_Phonemizer = None

try:
from TTS.tts.utils.text.phonemizers.ja_jp_phonemizer import JA_JP_Phonemizer
except ImportError:
JA_JP_Phonemizer = None

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


ESPEAK_LANGS = list(ESpeak.supported_languages().keys())
Expand All @@ -34,12 +38,12 @@
DEF_LANG_TO_PHONEMIZER["en"] = DEF_LANG_TO_PHONEMIZER["en-us"]
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()
DEF_LANG_TO_PHONEMIZER["be"] = BEL_Phonemizer.name()


# JA phonemizer has deal breaking dependencies like MeCab for some systems.
# So we only have it when we have it.
if BN_Phonemizer is not None:
PHONEMIZERS[BN_Phonemizer.name()] = BN_Phonemizer
DEF_LANG_TO_PHONEMIZER["bn"] = BN_Phonemizer.name()
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()
Expand All @@ -63,11 +67,13 @@ def get_phonemizer_by_name(name: str, **kwargs) -> BasePhonemizer:
return ZH_CN_Phonemizer(**kwargs)
if name == "ja_jp_phonemizer":
if JA_JP_Phonemizer is None:
raise ValueError("You need to install JA phonemizer dependencies. Try `pip install coqui-tts[ja]`.")
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":
return KO_KR_Phonemizer(**kwargs)
if name == "bn_phonemizer":
if BN_Phonemizer is None:
raise ValueError("You need to install BN phonemizer dependencies. Try `pip install coqui-tts[bn]`.")
return BN_Phonemizer(**kwargs)
if name == "be_phonemizer":
return BEL_Phonemizer(**kwargs)
Expand Down
16 changes: 11 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ dependencies = [
"g2pkk>=0.1.1",
# Gruut + supported languages
"gruut[de,es,fr]==2.2.3",
# Bangla
"bangla",
"bnnumerizer",
"bnunicodenormalizer",
# Tortoise
"einops>=0.6.0",
"transformers>=4.33.0",
Expand Down Expand Up @@ -115,15 +111,25 @@ notebooks = [
# For running the TTS server
server = ["flask>=2.0.1"]
# Language-specific dependencies, mainly for G2P
# Bangla
bn = [
"bangla",
"bnnumerizer",
"bnunicodenormalizer",
]
# Japanese
ja = [
"mecab-python3",
"unidic-lite==1.0.8",
"cutlet",
]
# All language-specific dependencies
languages = [
"coqui-tts[bn,ja]",
]
# Installs all extras (except dev and docs)
all = [
"coqui-tts[notebooks,server,ja]",
"coqui-tts[notebooks,server,bn,ja]",
]

[project.urls]
Expand Down

0 comments on commit ea893c3

Please sign in to comment.