Skip to content

Commit

Permalink
Merge pull request #181 from aaronchantrill/passive_listen
Browse files Browse the repository at this point in the history
Passive Listen
  • Loading branch information
AustinCasteel authored May 9, 2019
2 parents 3bd3fcf + 081113d commit 8ab9087
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions naomi/mic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from . import alteration
from . import paths
from . import profile


class Mic(object):
Expand Down Expand Up @@ -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("< <noise>")
Expand All @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit 8ab9087

Please sign in to comment.