diff --git a/speech_recognition/__init__.py b/speech_recognition/__init__.py index 66ebc04c..98b1db2c 100644 --- a/speech_recognition/__init__.py +++ b/speech_recognition/__init__.py @@ -740,8 +740,8 @@ def listen_in_background(self, source, callback, phrase_time_limit=None): running = [True] def threaded_listen(): - with source as s: - while running[0]: + while running[0]: + with source as s: try: # listen for 1 second, then check again if the stop function has been called audio = self.listen(s, 1, phrase_time_limit) except WaitTimeoutError: # listening timed out, just try again