From d55d015988315b21bf2dd6a463af50dd819e8f03 Mon Sep 17 00:00:00 2001 From: Mitch Patenaude Date: Fri, 12 Jun 2020 16:24:27 -0700 Subject: [PATCH] Removed the use of the PTT button --- client/conversation.py | 6 +++--- client/mic.py | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/client/conversation.py b/client/conversation.py index d03138fbc..1844922da 100644 --- a/client/conversation.py +++ b/client/conversation.py @@ -38,9 +38,9 @@ def handleForever(self): while self.phone.off_hook(): - if not self.phone.ptt_pressed(): - time.sleep(0.1) - continue + #if not self.phone.ptt_pressed(): + #time.sleep(0.1) + #continue try: input = self.mic.activeListenToAllOptions() diff --git a/client/mic.py b/client/mic.py index 1db84c937..11a24fcaa 100644 --- a/client/mic.py +++ b/client/mic.py @@ -299,15 +299,15 @@ def activeListenToAllOptions(self, THRESHOLD=None, LISTEN=True, if THRESHOLD is None: THRESHOLD = self.fetchThreshold() - wait_count = 0 - while not self.phone.ptt_pressed() and wait_count < 120: - wait_count += 1 - time.sleep(0.1) - if self.phone.on_hook(): - raise phone.Hangup() + #wait_count = 0 + #while not self.phone.ptt_pressed() and wait_count < 120: + #wait_count += 1 + #time.sleep(0.1) + #if self.phone.on_hook(): + #raise phone.Hangup() - if not self.phone.ptt_pressed(): - return ['',] + #if not self.phone.ptt_pressed(): + #return ['',] cls.lock.acquire() @@ -327,6 +327,14 @@ def activeListenToAllOptions(self, THRESHOLD=None, LISTEN=True, # increasing the range # results in longer pause after command # generation lastN = [THRESHOLD * 1.2 for i in range(int(30720/CHUNK))] + # States: + # 0 -- before utterance + # 1 -- during utterance + # 2 -- after utterance + state = 0 + utterances = 0 + post_utterance_frames = 0 + silence_frames_threshold = int(0.25*RATE/CHUNK) # 1/4 of a second for i in range(0, RATE / CHUNK * LISTEN_TIME): @@ -342,8 +350,19 @@ def activeListenToAllOptions(self, THRESHOLD=None, LISTEN=True, average = sum(lastN) / float(len(lastN)) # TODO: 0.8 should not be a MAGIC NUMBER! - # if average < THRESHOLD * 0.8: - if not self.phone.ptt_pressed() and average < THRESHOLD * 0.8: + # if not self.phone.ptt_pressed() and average < THRESHOLD * 0.8: + if average > THRESHOLD * 1.25: + if state != 1: + self._logger.debug('Begin utterance') + utterances += 1 + state = 1 + elif state > 0 and average < THRESHOLD * 0.8: + if state != 2: + self._logger.debug('End utterance') + post_utterance_frames += 1 + state = 2 + if state == 2 and post_utterance_frames >= silence_frames_threshold: + self._logger.debug('Enough post-utterance silnce') break self.speaker.play(jasperpath.data('audio', 'beep_lo.wav'))