diff --git a/naomi/mic.py b/naomi/mic.py index f70c3b65..5745c2fc 100644 --- a/naomi/mic.py +++ b/naomi/mic.py @@ -7,6 +7,7 @@ from . import alteration from . import paths +from . import profile class Mic(object): @@ -114,7 +115,20 @@ def wait_for_keyword(self, keyword=None): keyword.lower() in t.lower() for t in transcribed if t ]): - return + if(profile.get_profile_flag(["passive_listen"])): + # Take the same block of audio and put it + # through the active listener + try: + transcribed = self.active_stt_engine.transcribe(f) + except Exception: + dbg = (self._logger.getEffectiveLevel() == logging.DEBUG) + self._logger.error("Active transcription failed!", exc_info=dbg) + else: + if(self._print_transcript): + print("<< {}".format(transcribed)) + return transcribed + else: + return False else: if(self._print_transcript): print("< ") @@ -132,11 +146,11 @@ def active_listen(self, timeout=3): self.active_stt_engine._samplerate, self.active_stt_engine._volume_normalization ) as f: - if self._active_stt_reply: - self.say(self._active_stt_reply) + if self._active_stt_response: + self.say(self._active_stt_response) else: self._logger.debug("No text to respond with using beep") - self.play_file(paths.data('audio', 'beep_hi.wav')) + self.play_file(paths.data('audio', 'beep_lo.wav')) try: transcribed = self.active_stt_engine.transcribe(f) except Exception: @@ -148,8 +162,12 @@ def active_listen(self, timeout=3): return transcribed def listen(self): - self.wait_for_keyword(self._keyword) - return self.active_listen() + if(profile.get_profile_flag(["passive_listen"])): + self._logger.info("[passive_listen]") + return self.wait_for_keyword(self._keyword) + else: + self.wait_for_keyword(self._keyword) + return self.active_listen() # Output methods def play_file(self, filename):