Skip to content

Commit

Permalink
handle language in speech2text.py: backoff to automatic detection
Browse files Browse the repository at this point in the history
  • Loading branch information
ruokolt committed Feb 2, 2024
1 parent 1bf6457 commit a2e9c4f
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/speech2text.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,20 @@ def main():

# Check language if given
language = args.SPEECH2TEXT_LANGUAGE
if language and language.lower() in settings.supported_languages:
# Language is given in long form: convert to short form (two-letter abbreviation)
language = settings.supported_languages[language.lower()]
elif language and language not in settings.supported_languages.values():
logger.warning(
f"Given language '{language}' not found among supported languages: {' '.join([lang for lang in settings.supported_languages.keys()])}. Opting to detect language automatically."
)
language = None
if language:
if language.lower() in settings.supported_languages.keys():
# Language is given in OK long form: convert to short form (two-letter abbreviation)
language = settings.supported_languages[language.lower()]
elif language.lower() in settings.supported_languages.values():
# Language is given in OK short form
pass
else:
# Given language not OK
pretty_language_list = ", ".join([f'{lang} ({short})' for lang, short in settings.supported_languages.items()])
logger.warning(
f"Given language '{language}' not found among supported languages: {pretty_language_list}. Opting to detect language automatically"
)
language = None

with mp.Manager() as manager:
shared_dict = manager.dict()
Expand Down

0 comments on commit a2e9c4f

Please sign in to comment.