From a2e9c4f2bc83740552e4a6c27b7c0be8ca36ad2d Mon Sep 17 00:00:00 2001 From: Teemu Ruokolainen Date: Fri, 2 Feb 2024 10:40:08 +0200 Subject: [PATCH] handle language in speech2text.py: backoff to automatic detection --- src/speech2text.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/speech2text.py b/src/speech2text.py index 0188c3d..508c378 100644 --- a/src/speech2text.py +++ b/src/speech2text.py @@ -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()