Skip to content

Commit

Permalink
Add check for empty recognized text in speech_to_text function (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashesh3 authored Feb 1, 2024
1 parent be1e738 commit c4cf731
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ayushma/utils/speech_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def speech_to_text(engine_id, audio, language_code):

try:
engine = engine_class(api_key, language_code)
return engine.recognize(audio)
recognized_text = engine.recognize(audio)
if not recognized_text:
raise ValueError("Failed to detect any speech in provided audio")
except Exception as e:
print(f"Failed to recognize speech with {engine_name} engine: {e}")
raise e

0 comments on commit c4cf731

Please sign in to comment.