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 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:

View file

@ -529,6 +529,11 @@ class Story(object):
#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()
@ -638,6 +643,11 @@ class Story(object):
'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: ")
for direction in self.getCurrentDirections():