I'm working with the speech_recognition
library in Python, and my script is getting stuck on the recognizer.listen()
call. I want to continuously listen for commands after detecting the wake word but am encountering issues. Here’s a snippet of my code:
import speech_recognition as srrecognizer = sr.Recognizer()if __name__ == "__main__": print("Initialize Jarvis......") while True: try: with sr.Microphone() as source: print("\nListening...") audio = recognizer.listen(source, timeout=2, phrase_time_limit=2) Word = recognizer.recognize_google(audio) if Word.lower() == "jarvis": print("Wake word detected!") with sr.Microphone() as source: print("\nListening...") audio = recognizer.listen(source) command = recognizer.recognize_google(audio) print(command) except Exception as x: print(f"Error : {x}")
Issue:When running the script, it successfully detects the wake word but then gets stuck on the second recognizer.listen()
call. I would like to continuously listen for commands without using the phrase_time_limit
parameter.
Environment:
- OS: Ubuntu 22.04 LTS
How can I fix this issue?
When running the script, it successfully detects the wake word but then gets stuck on the second recognizer.listen()
call. I would like to continuously listen for commands without using the phrase_time_limit
parameter.