Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passive Listen #181

Merged
merged 2 commits into from
May 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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