From 79c551fb3a391b7ad99f5ea419cac0ace6fc996e Mon Sep 17 00:00:00 2001 From: Mohammad Sadeq Sirjani Date: Tue, 13 Jun 2023 10:42:15 +0330 Subject: [PATCH] feat: fix this issue --- app.py | 5 +++++ voice_engine/speech_to_text.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 55e84fe..912aaba 100644 --- a/app.py +++ b/app.py @@ -59,6 +59,11 @@ def ask(language: str): prompt = speech_to_text.convert(file_path=secure_file_path, language=language) + if prompt is None: + return jsonify({"data": None, + "message": "Google Speech Recognition could not understand audio", + "status": "success"}), 400 + os.remove(secure_file_path) engine = gpt_engine.GptEngine() diff --git a/voice_engine/speech_to_text.py b/voice_engine/speech_to_text.py index 6f0340b..022c3e3 100644 --- a/voice_engine/speech_to_text.py +++ b/voice_engine/speech_to_text.py @@ -3,7 +3,7 @@ import speech_recognition as sr -def convert(file_path: str, language: str = 'en-US') -> str: +def convert(file_path: str, language: str = 'en') -> str: recognizer = sr.Recognizer() with sr.AudioFile(file_path) as src: