Stop google stream after finish (or rather, prevent google stream from restarting after finish) - Fix #29
This commit is contained in:
parent
d61f1db70e
commit
126c10b5ce
2 changed files with 28 additions and 2 deletions
|
@ -37,6 +37,7 @@ class GoogleVoiceClient(object):
|
||||||
# Create a thread-safe buffer of audio data
|
# Create a thread-safe buffer of audio data
|
||||||
self.buffer = queue.Queue()
|
self.buffer = queue.Queue()
|
||||||
self.isRunning = threading.Event()
|
self.isRunning = threading.Event()
|
||||||
|
self.isStarted = threading.Event()
|
||||||
self.toBeShutdown = False
|
self.toBeShutdown = False
|
||||||
self.target_rate = 16000
|
self.target_rate = 16000
|
||||||
self.cv_laststate = None
|
self.cv_laststate = None
|
||||||
|
@ -58,6 +59,25 @@ class GoogleVoiceClient(object):
|
||||||
self.buffer = queue.Queue() # have a clear queue when resuming
|
self.buffer = queue.Queue() # have a clear queue when resuming
|
||||||
self.isRunning.set()
|
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):
|
def generator(self):
|
||||||
self.logger.debug('start generator')
|
self.logger.debug('start generator')
|
||||||
while not self.toBeShutdown and self.isRunning.is_set():
|
while not self.toBeShutdown and self.isRunning.is_set():
|
||||||
|
@ -207,12 +227,16 @@ class GoogleVoiceClient(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.subsequentMutedFrames = 0
|
self.subsequentMutedFrames = 0
|
||||||
|
|
||||||
|
if not self.isStarted.is_set():
|
||||||
|
# Stopped state, so resume is not triggered
|
||||||
|
return
|
||||||
|
|
||||||
# self.logger.debug("We have mic!")
|
# self.logger.debug("We have mic!")
|
||||||
if not self.isRunning.is_set():
|
if not self.isRunning.is_set():
|
||||||
self.logger.info("Resume voice")
|
self.logger.info("Resume voice")
|
||||||
self.resume()
|
self.resume()
|
||||||
|
|
||||||
|
|
||||||
if not self.isRunning.is_set():
|
if not self.isRunning.is_set():
|
||||||
# logger.log(LOG_BS, "Don't put to queue if google is paused")
|
# logger.log(LOG_BS, "Don't put to queue if google is paused")
|
||||||
return
|
return
|
||||||
|
@ -228,7 +252,7 @@ class GoogleVoiceClient(object):
|
||||||
self.hugvey = None
|
self.hugvey = None
|
||||||
|
|
||||||
def triggerStart(self):
|
def triggerStart(self):
|
||||||
pass
|
self.start()
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.logger.warn("Destroyed google object")
|
self.logger.warn("Destroyed google object")
|
||||||
|
|
|
@ -1659,6 +1659,8 @@ class Story(object):
|
||||||
self.stop()
|
self.stop()
|
||||||
self.finish_time = time.time()
|
self.finish_time = time.time()
|
||||||
self.timer.pause()
|
self.timer.pause()
|
||||||
|
if self.hugvey.google:
|
||||||
|
self.hugvey.google.stop()
|
||||||
|
|
||||||
def calculateFinishesForMsg(self, msgId, depth = 0, checked = []):
|
def calculateFinishesForMsg(self, msgId, depth = 0, checked = []):
|
||||||
# if msgId in checked:
|
# if msgId in checked:
|
||||||
|
|
Loading…
Reference in a new issue