Skip to content

Commit

Permalink
Removed the use of the PTT button
Browse files Browse the repository at this point in the history
  • Loading branch information
pneumaticdeath committed Jun 12, 2020
1 parent 20680ea commit d55d015
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
6 changes: 3 additions & 3 deletions client/conversation.py
Expand Up @@ -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()
Expand Down
39 changes: 29 additions & 10 deletions client/mic.py
Expand Up @@ -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()

Expand All @@ -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):

Expand All @@ -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'))
Expand Down

0 comments on commit d55d015

Please sign in to comment.