From a389a5ea77c981de6fd728984f729465c5008daf Mon Sep 17 00:00:00 2001 From: Aaron Chantrill Date: Sat, 13 Apr 2019 17:12:18 +0100 Subject: [PATCH 1/2] Passive Listen This allows the user to set an "active_listen" value in profile.yml to True (or "Yes") in order to change Naomi's listening behavior. Normally, you speak Naomi's keyphrase, Naomi responds with a high beep noise, then you speak your query, Naomi response with a low beep noise, then processes the request. Using passive listen, Naomi listens for your voice, then scans the entire block of audio for the keyword. If it detects the keyword, it passes the audio to the active listener, then finally returns the transcription. This pull request also fixes the issue that at some point the low beep got replaced with the high beep. I think it was when I was working on the Voice Activity Detector plugin. --- naomi/mic.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/naomi/mic.py b/naomi/mic.py index f70c3b65..67b14316 100644 --- a/naomi/mic.py +++ b/naomi/mic.py @@ -7,7 +7,7 @@ from . import alteration from . import paths - +from . import profile class Mic(object): """ @@ -114,7 +114,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 +145,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 +161,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): From 081113dee940d2bd2405dab5be259d8c76ca2d1f Mon Sep 17 00:00:00 2001 From: Aaron Chantrill Date: Thu, 18 Apr 2019 17:45:22 +0100 Subject: [PATCH 2/2] Flake8 issue This just adds an additional blank line between the import statements and the first function declaration to resolve a flake8 requirement (E302 - Surround top-level function and class definitions with two blank lines.) --- naomi/mic.py | 1 + 1 file changed, 1 insertion(+) diff --git a/naomi/mic.py b/naomi/mic.py index 67b14316..5745c2fc 100644 --- a/naomi/mic.py +++ b/naomi/mic.py @@ -9,6 +9,7 @@ from . import paths from . import profile + class Mic(object): """ The Mic class handles all interactions with the microphone and speaker.