From 63e37858cffa05b0999a81799bad6ca37740b322 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Sat, 28 Aug 2021 16:11:36 +0200 Subject: [PATCH] Added try/except on recognize_google method for audio without any detected speech --- jarvis/utils/flask_utils.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/jarvis/utils/flask_utils.py b/jarvis/utils/flask_utils.py index 54c3962..1ad2fc2 100644 --- a/jarvis/utils/flask_utils.py +++ b/jarvis/utils/flask_utils.py @@ -30,10 +30,14 @@ def process_audio_request(): r = sr.Recognizer() audio = sr.AudioData(frame_data, sample_rate, sample_width) - result_stt = r.recognize_google(audio, language=languages_utils.get_language_only_country()) + try: + result_stt = r.recognize_google(audio, language=languages_utils.get_language_only_country()) - return jsonify( - intent_manager.recognise(result_stt, request.headers.get('Client-Ip'), request.headers.get('Client-Port'))) + return jsonify( + intent_manager.recognise(result_stt, request.headers.get('Client-Ip'), request.headers.get('Client-Port'))) + + except sr.UnknownValueError: + print("[Error] No speech detected in the send audio!") def get_data_in_request(flask_request):