Improve playFileOnRequest: add file existence check, better logging, catch all exceptions

pull/26/head
Joaquin Madrid Belando 3 weeks ago
parent ffe105b430
commit 0d466a3291

@ -766,14 +766,27 @@ def playFileOnRequest(self,fileNumber):
_lang = CONFIG['SYSTEMS'][system]['ANNOUNCEMENT_LANGUAGE'] _lang = CONFIG['SYSTEMS'][system]['ANNOUNCEMENT_LANGUAGE']
_nine = bytes_3(9) _nine = bytes_3(9)
_source_id = bytes_3(5000) _source_id = bytes_3(5000)
logger.debug('(%s) Sending contents of AMBE file: %s',system,fileNumber)
_ambe_file = '/{}/ondemand/{}.ambe'.format(_lang, fileNumber)
_full_path = os.path.join('./Audio', _lang, 'ondemand', '{}.ambe'.format(fileNumber))
if not os.path.isfile(_full_path):
logger.warning('(%s) AMBE file not found: %s', system, _full_path)
return
logger.info('(%s) Playing on-demand AMBE file: %s (ID: %s)', system, _full_path, fileNumber)
sleep(1) sleep(1)
_say = [] _say = []
try: try:
_say.append(AMBEobj.readSingleFile(''.join(['/',_lang,'/ondemand/',str(fileNumber),'.ambe']))) _say.append(AMBEobj.readSingleFile(_ambe_file))
except IOError: except Exception as e:
logger.warning('(%s) cannot read file for number %s',system,fileNumber) logger.warning('(%s) Error reading AMBE file %s: %s', system, _full_path, e)
return
if not _say or not _say[0]:
logger.warning('(%s) AMBE file empty or invalid: %s', system, _full_path)
return return
speech = pkt_gen(_source_id, _nine, bytes_4(9), 1, _say) speech = pkt_gen(_source_id, _nine, bytes_4(9), 1, _say)
sleep(1) sleep(1)
_slot = systems[system].STATUS[2] _slot = systems[system].STATUS[2]
@ -782,12 +795,11 @@ def playFileOnRequest(self,fileNumber):
pkt = next(speech) pkt = next(speech)
except StopIteration: except StopIteration:
break break
#Packet every 60ms
sleep(0.058) sleep(0.058)
_stream_id = pkt[16:20] _stream_id = pkt[16:20]
_pkt_time = time() _pkt_time = time()
reactor.callFromThread(sendVoicePacket,self,pkt,_source_id,_nine,_slot) reactor.callFromThread(sendVoicePacket,self,pkt,_source_id,_nine,_slot)
logger.debug('(%s) Sending AMBE file %s end',system,fileNumber) logger.info('(%s) On-demand playback complete: %s', system, fileNumber)
def threadIdent(): def threadIdent():
logger.debug('(IDENT) starting ident thread') logger.debug('(IDENT) starting ident thread')

Loading…
Cancel
Save

Powered by TurnKey Linux.