Workaround for crash of voice fetch, sox audiodev in config, client waits a sec to allow mics to come up
This commit is contained in:
parent
929b7cb4d1
commit
c4f55c01c7
4 changed files with 21 additions and 8 deletions
|
@ -247,6 +247,10 @@ class CentralCommand(object):
|
||||||
isVariable = bool(r['variable'])
|
isVariable = bool(r['variable'])
|
||||||
text = r['text']
|
text = r['text']
|
||||||
fn = await self.voiceStorage.requestFile(text, isVariable)
|
fn = await self.voiceStorage.requestFile(text, isVariable)
|
||||||
|
if fn is None:
|
||||||
|
eventLogger.getChild(f"{hugvey_id}").critical("error: No voice file fetched, check logs.")
|
||||||
|
fn = 'local/crash.wav'
|
||||||
|
# TODO: trigger a repeat/crash event.
|
||||||
await s.send_string(fn)
|
await s.send_string(fn)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.critical(f"Exception while running voice loop:")
|
logger.critical(f"Exception while running voice loop:")
|
||||||
|
|
|
@ -11,6 +11,7 @@ import zmq
|
||||||
from zmq.asyncio import Context
|
from zmq.asyncio import Context
|
||||||
import sys
|
import sys
|
||||||
from hugvey.communication import LOG_BS
|
from hugvey.communication import LOG_BS
|
||||||
|
import os
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import alsaaudio
|
import alsaaudio
|
||||||
|
@ -85,6 +86,9 @@ class VoiceServer(object):
|
||||||
|
|
||||||
self.p = pyaudio.PyAudio()
|
self.p = pyaudio.PyAudio()
|
||||||
self.stopped = False
|
self.stopped = False
|
||||||
|
|
||||||
|
# wait a sec for the input devices to come up
|
||||||
|
await asyncio.sleep(2)
|
||||||
|
|
||||||
stream = self.p.open(
|
stream = self.p.open(
|
||||||
format=FORMAT,
|
format=FORMAT,
|
||||||
|
@ -127,7 +131,7 @@ class VoiceServer(object):
|
||||||
|
|
||||||
|
|
||||||
class CommandHandler(object):
|
class CommandHandler(object):
|
||||||
def __init__(self, hugvey_id, cmd_address, publish_address, file_address):
|
def __init__(self, hugvey_id, cmd_address, publish_address, file_address, play_audiodev = None):
|
||||||
self.eventQueue = []
|
self.eventQueue = []
|
||||||
self.ctx = Context.instance()
|
self.ctx = Context.instance()
|
||||||
self.hugvey_id = hugvey_id
|
self.hugvey_id = hugvey_id
|
||||||
|
@ -136,6 +140,7 @@ class CommandHandler(object):
|
||||||
self.playPopen = None
|
self.playPopen = None
|
||||||
self.file_address = file_address
|
self.file_address = file_address
|
||||||
self.playingMsgId = None
|
self.playingMsgId = None
|
||||||
|
self.play_audiodev = play_audiodev
|
||||||
# self.showMyself() # queue message for connection request
|
# self.showMyself() # queue message for connection request
|
||||||
|
|
||||||
def handle(self, cmd):
|
def handle(self, cmd):
|
||||||
|
@ -178,10 +183,12 @@ class CommandHandler(object):
|
||||||
if value is True:
|
if value is True:
|
||||||
continue
|
continue
|
||||||
playCmd.append(str(value))
|
playCmd.append(str(value))
|
||||||
|
environment_vars = dict(os.environ)
|
||||||
|
if self.play_audiodev is not None:
|
||||||
|
environment_vars['AUDIODEV'] = self.play_audiodev
|
||||||
logger.debug(playCmd)
|
logger.debug(playCmd)
|
||||||
self.playPopen = subprocess.Popen(
|
self.playPopen = subprocess.Popen(
|
||||||
playCmd, stdout=subprocess.PIPE)
|
playCmd, stdout=subprocess.PIPE, env=environment_vars)
|
||||||
|
|
||||||
returnCode = self.playPopen.wait()
|
returnCode = self.playPopen.wait()
|
||||||
logger.debug('finished')
|
logger.debug('finished')
|
||||||
|
@ -308,7 +315,8 @@ class Hugvey(object):
|
||||||
hugvey_id=self.id,
|
hugvey_id=self.id,
|
||||||
cmd_address=self.config['events']['cmd_address'],
|
cmd_address=self.config['events']['cmd_address'],
|
||||||
publish_address=self.config['events']['publish_address'],
|
publish_address=self.config['events']['publish_address'],
|
||||||
file_address=self.config['voice']['file_address']
|
file_address=self.config['voice']['file_address'],
|
||||||
|
play_audiodev=self.config['voice']['play_audiodev']
|
||||||
)
|
)
|
||||||
self.voice_server = VoiceServer(
|
self.voice_server = VoiceServer(
|
||||||
loop=loop,
|
loop=loop,
|
||||||
|
|
|
@ -889,10 +889,10 @@ class Story(object):
|
||||||
self.hugvey.eventLogger.info(f"message: {message.id} {message.uuid} start \"{message.text}\"")
|
self.hugvey.eventLogger.info(f"message: {message.id} {message.uuid} start \"{message.text}\"")
|
||||||
|
|
||||||
# TODO: prep events & timer etc.
|
# TODO: prep events & timer etc.
|
||||||
# TODO: preload file paths if no variables are set, or once these are loaded
|
fn = await message.getAudioFilePath()
|
||||||
self.hugvey.sendCommand({
|
self.hugvey.sendCommand({
|
||||||
'action': 'play',
|
'action': 'play',
|
||||||
'file': await message.getAudioFilePath(),
|
'file': fn,
|
||||||
'id': message.id,
|
'id': message.id,
|
||||||
'params': message.getParams()
|
'params': message.getParams()
|
||||||
})
|
})
|
||||||
|
|
|
@ -70,6 +70,7 @@ class VoiceStorage(object):
|
||||||
response = await http_client.fetch(request)
|
response = await http_client.fetch(request)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
|
logger.critical(request)
|
||||||
self.pendingRequests[id].set()
|
self.pendingRequests[id].set()
|
||||||
http_client.close()
|
http_client.close()
|
||||||
return None
|
return None
|
||||||
|
@ -80,10 +81,10 @@ class VoiceStorage(object):
|
||||||
http_client.close()
|
http_client.close()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
logger.debug(f"Wrote body: {response.code}")
|
# logger.debug(f"Wrote body: {response.code}")
|
||||||
with open(fn, "wb") as f:
|
with open(fn, "wb") as f:
|
||||||
f.write(response.body)
|
f.write(response.body)
|
||||||
self.pendingRequests[id].set()
|
self.pendingRequests[id].set()
|
||||||
print(type(fn), fn)
|
# print(type(fn), fn)
|
||||||
http_client.close()
|
http_client.close()
|
||||||
return fn
|
return fn
|
||||||
|
|
Loading…
Reference in a new issue