From 58b977f5df601eb143a27372977260b2308d07bf Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Fri, 22 Feb 2019 14:45:36 +0100 Subject: [PATCH] Temporarily disable recording while playing audio --- hugvey/speech/google.py | 8 +++++++- hugvey/story.py | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/hugvey/speech/google.py b/hugvey/speech/google.py index 7af35e2..b84d420 100644 --- a/hugvey/speech/google.py +++ b/hugvey/speech/google.py @@ -16,6 +16,7 @@ import asyncio import threading import queue import uuid +from hugvey.communication import LOG_BS logger = logging.getLogger("speech") @@ -48,10 +49,11 @@ class GoogleVoiceClient(object): self.restart = True def resume(self): + self.buffer = queue.Queue() # have a clear queue when resuming self.isRunning.set() def generator(self): - while not self.toBeShutdown: + while not self.toBeShutdown and self.isRunning.is_set(): yield self.buffer.get() def setLanguage(self, language_code): @@ -147,6 +149,10 @@ class GoogleVoiceClient(object): if not self.task.isAlive(): raise Exception("Voice thread died") + if not self.isRunning.is_set(): +# logger.log(LOG_BS, "Don't put to queue if google is paused") + return + if self.src_rate == self.target_rate: data = chunk else: diff --git a/hugvey/story.py b/hugvey/story.py index e431881..77b0876 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -528,7 +528,12 @@ class Story(object): if e['msgId'] == self.currentMessage.id: #TODO: migrate value to Messagage instead of Story self.lastMsgFinishTime = self.timer.getElapsed() - + + # 2019-02-22 temporary disable listening while playing audio: + if self.hugvey.google is not None: + logger.warn("Temporary 'fix' -> resume recording?") + self.hugvey.google.resume() + if self.currentMessage.id not in self.directionsPerMsg: logger.info("THE END!") self.stop() @@ -637,6 +642,11 @@ class Story(object): 'file': await message.getAudioFilePath(self), 'id': message.id, }) + + # 2019-02-22 temporary disable listening while playing audio: + if self.hugvey.google is not None: + logger.warn("Temporary 'fix' -> stop recording") + self.hugvey.google.pause() logger.debug("Pending directions: ")