Skip to content

Commit

Permalink
Add 2 functions to verify any spacy language can be instantiated. By …
Browse files Browse the repository at this point in the history
…now, the only one that needs special packages is Korean. So, all languages works well but Korean
  • Loading branch information
defaultdeveloperuser committed Feb 28, 2024
1 parent 30a2d8d commit 3db0dec
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion TTS/tts/layers/xtts/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,27 @@

from TTS.tts.layers.xtts.zh_num2words import TextNorm as zh_num2words

import spacy

# These 2 functions are to verify that any language can be instantiated
def get_spacy_available_langs():
from pathlib import Path
spacy_path = Path(spacy.__file__.replace('__init__.py',''))
spacy_langs = spacy_path / 'lang'
SPACY_LANGS = [str(x).split('/')[-1] for x in spacy_langs.iterdir() if x.is_dir() and str(x).split('/')[-1] != '__pycache__']
print("Available languages in Spacy:", SPACY_LANGS)
return SPACY_LANGS
def get_all_spacy_langs():
SPACY_LANGS = get_spacy_available_langs()
spacy_lang_instances = []
for lang in SPACY_LANGS:
spacy_lang_instances.append(get_spacy_lang(lang))

def get_spacy_lang(lang):
try:
lang_model = get_lang_class(lang)()
except ImportError:
except ImportError as e:
print("Error", e)
# Fallback to English if the language model is not available
lang_model = English()
return lang_model
Expand Down

0 comments on commit 3db0dec

Please sign in to comment.