Check if mic returned data before putting on queue
Mic may return None when aborted due to a reload of wake-word engine
@@ -77,7 +77,10 @@ class AudioProducer(Thread):
try:
audio = self.recognizer.listen(source, self.emitter,
self.stream_handler)
+ if audio is not None:
self.queue.put((AUDIO_DATA, audio))
+ else:
+ LOG.warning("Audio contains no data.")
except IOError as e:
# NOTE: Audio stack on raspi is slightly different, throws
# IOError every other listen, almost like it can't handle
@@ -134,6 +137,7 @@ class AudioConsumer(Thread):
tag, data = message
if tag == AUDIO_DATA:
+ if data is not None:
if self.state.sleeping:
self.wake_up(data)
else:
@@ -169,9 +173,7 @@ class AudioConsumer(Thread):
}
self.emitter.emit("recognizer_loop:wakeword", payload)
- if self._audio_length(audio) < self.MIN_AUDIO_SIZE:
- LOG.warning("Audio too short to be processed")
- else:
+ if self._audio_length(audio) >= self.MIN_AUDIO_SIZE:
stopwatch = Stopwatch()
with stopwatch:
transcription = self.transcribe(audio)
@@ -193,6 +195,8 @@ class AudioConsumer(Thread):
'stt': self.stt.__class__.__name__})
else:
ident = str(stopwatch.timestamp)
+ else:
+ LOG.warning("Audio too short to be processed")
def transcribe(self, audio):
def send_unknown_intent():
