Try catch audio error

This commit is contained in:
Ruben van de Ven 2019-05-11 18:12:25 +02:00
parent 484542de8d
commit 23471e4ec0
3 changed files with 17 additions and 6 deletions

View File

@ -536,7 +536,8 @@ class HugveyState(object):
# detect missing heartbeat:
if self.isConfigured and time.time() - self.isConfigured > 15:
self.logger.error("Hugvey did not send heartbeat.")
self.gone()
# self.gone()
self.shutdown()
continue
self.logger.debug("Received: {}".format(event))
@ -762,4 +763,4 @@ class HugveyState(object):
self.logger.critical(f"stream has left the building from {self.ip}")
self.eventLogger.critical(f"error: stream has left the building from {self.ip}")
# if we end up here, the streamer finished, probably meaning hte hugvey shutdown
self.gone()
# self.gone()

View File

@ -18,6 +18,7 @@ import queue
import uuid
from hugvey.communication import LOG_BS
import audioop
import gc
mainLogger = logging.getLogger("hugvey")
logger = mainLogger.getChild("google")
@ -181,6 +182,10 @@ class GoogleVoiceClient(object):
self.hugvey.queueEvent(msg)
self.logger.warn("Stop google run()") # finish means wrapping of hugvey#3v thread
# time.sleep(1)
# for i in gc.get_referrers(self):
# print(i)
def receive(self, chunk):
if not self.task.isAlive():

View File

@ -1418,10 +1418,15 @@ class Story(object):
fn = await message.getAudioFilePath()
# get duration of audio file, so the client can detect a hang of 'play'
with wave.open(fn,'r') as fp:
frames = fp.getnframes()
rate = fp.getframerate()
duration = frames/float(rate)
try:
with wave.open(fn,'r') as fp:
frames = fp.getnframes()
rate = fp.getframerate()
duration = frames/float(rate)
except Exception as e:
self.hugvey.eventLogger.critical(f"error: crash when reading wave file: {fn}")
self.logger.critical(f"error: crash when reading wave file: {fn}")
duration = 10 # some default duration to have something to fall back to
# self.hugvey.google.pause() # pause STT to avoid text events while decision is made
self.hugvey.sendCommand({