Stop google stream after finish (or rather, prevent google stream from restarting after finish) - Fix #29

This commit is contained in:
Ruben van de Ven 2019-05-17 20:47:33 +02:00
parent d61f1db70e
commit 126c10b5ce
2 changed files with 28 additions and 2 deletions

View file

@ -37,6 +37,7 @@ class GoogleVoiceClient(object):
# Create a thread-safe buffer of audio data
self.buffer = queue.Queue()
self.isRunning = threading.Event()
self.isStarted = threading.Event()
self.toBeShutdown = False
self.target_rate = 16000
self.cv_laststate = None
@ -57,6 +58,25 @@ class GoogleVoiceClient(object):
def resume(self):
self.buffer = queue.Queue() # have a clear queue when resuming
self.isRunning.set()
def start(self):
"""
Pause/resume are used within a story to create a break/restart in the recording
eacht time hugvey speaks. however, this caused issues with the mics that stay on after
a story finishes (it cause Google to resume). Hence, we add another layer to its running
state: start/stop. This is not influenced by the resume and triggered by starting and
stopping the story only.
A bit messy but it should work ;-)
"""
self.logger.info("Start STT")
self.resume()
self.isStarted.set()
def stop(self):
self.logger.info("Stop STT")
self.pause()
self.isStarted.clear()
def generator(self):
self.logger.debug('start generator')
@ -207,12 +227,16 @@ class GoogleVoiceClient(object):
return
self.subsequentMutedFrames = 0
if not self.isStarted.is_set():
# Stopped state, so resume is not triggered
return
# self.logger.debug("We have mic!")
if not self.isRunning.is_set():
self.logger.info("Resume voice")
self.resume()
if not self.isRunning.is_set():
# logger.log(LOG_BS, "Don't put to queue if google is paused")
return
@ -228,7 +252,7 @@ class GoogleVoiceClient(object):
self.hugvey = None
def triggerStart(self):
pass
self.start()
def __del__(self):
self.logger.warn("Destroyed google object")

View file

@ -1659,6 +1659,8 @@ class Story(object):
self.stop()
self.finish_time = time.time()
self.timer.pause()
if self.hugvey.google:
self.hugvey.google.stop()
def calculateFinishesForMsg(self, msgId, depth = 0, checked = []):
# if msgId in checked: