Skip to content

Commit

Permalink
fix: filter unsupported languages in get_lang_list
Browse files Browse the repository at this point in the history
  • Loading branch information
Artrajz committed Sep 21, 2024
1 parent b0c9ef2 commit ca2cb15
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions tts_app/voice_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,26 @@ def update_default_params(state):


def get_lang_list(lang, speaker_lang):
lang_list = re.split(r'[,,\s]+', lang)
new_lang_list = []

for idx in range(len(lang_list)):
if lang_list[idx].strip() == "":
continue
lang_list[idx] = lang_list[idx].lower()
lang = lang_list[idx]
if lang not in ["auto", "mix"] and len(speaker_lang) > 1 and lang not in speaker_lang:
logger.info(f"[{ModelType.BERT_VITS2.value}] lang \"{lang}\" is not in {speaker_lang}")
status = "error"
msg = f"lang '{lang}' is not in {speaker_lang}"
return new_lang_list, status, msg
new_lang_list.append(lang)

if "auto" in lang_list and len(lang_list) > 1:
status = "error"
msg = "Do not pass 'auto' along with other languages."
return new_lang_list, status, msg

status = ""
msg = ""
lang_list = [l.lower().strip() for l in re.split(r'[,,\s]+', lang) if l.strip()]

if len(speaker_lang) == 1:
return speaker_lang, "", ""

special_langs = {"auto", "mix"}

for special in special_langs:
if special in lang_list and len(lang_list) > 1:
return [special], "warning", f"Do not pass '{special}' along with other languages."

new_lang_list = [lang for lang in lang_list if lang in speaker_lang or lang in special_langs]
unsupported_language = [lang for lang in lang_list if lang not in speaker_lang and lang not in special_langs]

status = "warning" if unsupported_language else ""
msg = f"Unsupported languages: {unsupported_language}" if unsupported_language else ""

if not new_lang_list:
new_lang_list = ["auto"]

return new_lang_list, status, msg


Expand Down

0 comments on commit ca2cb15

Please sign in to comment.