Temporarily disable recording while playing audio

This commit is contained in:
Ruben van de Ven 2019-02-22 14:45:36 +01:00
parent 02eac88560
commit 58b977f5df
2 changed files with 18 additions and 2 deletions

View file

@ -16,6 +16,7 @@ import asyncio
import threading import threading
import queue import queue
import uuid import uuid
from hugvey.communication import LOG_BS
logger = logging.getLogger("speech") logger = logging.getLogger("speech")
@ -48,10 +49,11 @@ class GoogleVoiceClient(object):
self.restart = True self.restart = True
def resume(self): def resume(self):
self.buffer = queue.Queue() # have a clear queue when resuming
self.isRunning.set() self.isRunning.set()
def generator(self): def generator(self):
while not self.toBeShutdown: while not self.toBeShutdown and self.isRunning.is_set():
yield self.buffer.get() yield self.buffer.get()
def setLanguage(self, language_code): def setLanguage(self, language_code):
@ -147,6 +149,10 @@ class GoogleVoiceClient(object):
if not self.task.isAlive(): if not self.task.isAlive():
raise Exception("Voice thread died") 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: if self.src_rate == self.target_rate:
data = chunk data = chunk
else: else:

View file

@ -528,7 +528,12 @@ class Story(object):
if e['msgId'] == self.currentMessage.id: if e['msgId'] == self.currentMessage.id:
#TODO: migrate value to Messagage instead of Story #TODO: migrate value to Messagage instead of Story
self.lastMsgFinishTime = self.timer.getElapsed() 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: if self.currentMessage.id not in self.directionsPerMsg:
logger.info("THE END!") logger.info("THE END!")
self.stop() self.stop()
@ -637,6 +642,11 @@ class Story(object):
'file': await message.getAudioFilePath(self), 'file': await message.getAudioFilePath(self),
'id': message.id, '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: ") logger.debug("Pending directions: ")