@ -66,7 +66,7 @@ from hblink import HBSYSTEM, OPENBRIDGE, systems, hblink_handler, reportFactory,
from dmr_utils3 . utils import bytes_3 , int_id , get_alias , bytes_4
from dmr_utils3 import decode , bptc , const
import config
from config import acl_build
from config import acl_build , reload_voice_config
import log
from const import *
from mk_voice import pkt_gen
@ -881,6 +881,12 @@ _announcement_running = {1: False, 2: False, 3: False, 4: False}
_tts_last_hour = { 1 : - 1 , 2 : - 1 , 3 : - 1 , 4 : - 1 }
_tts_running = { 1 : False , 2 : False , 3 : False , 4 : False }
_voice_cfg_mtime = 0
_voice_cfg_file = ' '
_voice_cfg_config_file = ' '
_ann_tasks = { }
_tts_tasks = { }
_FRAME_INTERVAL = 0.054
_RECORDING_MAX_FRAMES = 2750
@ -1110,6 +1116,83 @@ def scheduledAnnouncement(_ann_num=1):
_announcement_running [ _ann_num ] = True
reactor . callLater ( 1.0 , _announcementSendBroadcast , _targets , _pkts , 0 , _source_id , _dst_id , _tg , _timeslot , _ann_num )
def _checkVoiceConfigReload ( ) :
global _voice_cfg_mtime , _ann_tasks , _tts_tasks
if not _voice_cfg_file or not os . path . isfile ( _voice_cfg_file ) :
return
try :
_current_mtime = os . path . getmtime ( _voice_cfg_file )
except OSError :
return
if _current_mtime == _voice_cfg_mtime :
return
_voice_cfg_mtime = _current_mtime
logger . info ( ' (VOICE-RELOAD) Detectado cambio en voice.cfg, recargando configuracion... ' )
if not reload_voice_config ( CONFIG , _voice_cfg_config_file ) :
logger . error ( ' (VOICE-RELOAD) Error recargando voice.cfg ' )
return
for _ann_num in range ( 1 , 5 ) :
_prefix = ' ANNOUNCEMENT ' if _ann_num == 1 else ' ANNOUNCEMENT {} ' . format ( _ann_num )
_label = ' LOCUCION ' if _ann_num == 1 else ' LOCUCION- {} ' . format ( _ann_num )
_enabled = CONFIG [ ' GLOBAL ' ] . get ( ' {} _ENABLED ' . format ( _prefix ) , False )
if _ann_num in _ann_tasks and _ann_tasks [ _ann_num ] . running :
_ann_tasks [ _ann_num ] . stop ( )
logger . info ( ' (VOICE-RELOAD) %s detenida ' , _label )
del _ann_tasks [ _ann_num ]
if _enabled :
_ann_mode = CONFIG [ ' GLOBAL ' ] [ ' {} _MODE ' . format ( _prefix ) ]
if _ann_mode == ' hourly ' :
_ann_check_interval = 30
else :
_ann_check_interval = CONFIG [ ' GLOBAL ' ] [ ' {} _INTERVAL ' . format ( _prefix ) ]
_ann_task = task . LoopingCall ( scheduledAnnouncement , _ann_num )
_ann_def = _ann_task . start ( _ann_check_interval , now = False )
_ann_def . addErrback ( loopingErrHandle )
_ann_tasks [ _ann_num ] = _ann_task
logger . info ( ' (VOICE-RELOAD) %s activada - mode: %s , file: %s , TG: %s , TS: %s ' ,
_label , _ann_mode ,
CONFIG [ ' GLOBAL ' ] [ ' {} _FILE ' . format ( _prefix ) ] ,
CONFIG [ ' GLOBAL ' ] [ ' {} _TG ' . format ( _prefix ) ] ,
CONFIG [ ' GLOBAL ' ] [ ' {} _TIMESLOT ' . format ( _prefix ) ] )
for _tts_num in range ( 1 , 5 ) :
_prefix = ' TTS_ANNOUNCEMENT {} ' . format ( _tts_num )
_label = ' TTS- {} ' . format ( _tts_num )
_enabled = CONFIG [ ' GLOBAL ' ] . get ( ' {} _ENABLED ' . format ( _prefix ) , False )
if _tts_num in _tts_tasks and _tts_tasks [ _tts_num ] . running :
_tts_tasks [ _tts_num ] . stop ( )
logger . info ( ' (VOICE-RELOAD) %s detenida ' , _label )
del _tts_tasks [ _tts_num ]
if _enabled :
_tts_mode = CONFIG [ ' GLOBAL ' ] [ ' {} _MODE ' . format ( _prefix ) ]
if _tts_mode == ' hourly ' :
_tts_check_interval = 30
else :
_tts_check_interval = CONFIG [ ' GLOBAL ' ] [ ' {} _INTERVAL ' . format ( _prefix ) ]
_tts_task = task . LoopingCall ( scheduledTTSAnnouncement , _tts_num )
_tts_def = _tts_task . start ( _tts_check_interval , now = False )
_tts_def . addErrback ( loopingErrHandle )
_tts_tasks [ _tts_num ] = _tts_task
logger . info ( ' (VOICE-RELOAD) %s activada - mode: %s , file: %s , TG: %s , TS: %s ' ,
_label , _tts_mode ,
CONFIG [ ' GLOBAL ' ] [ ' {} _FILE ' . format ( _prefix ) ] ,
CONFIG [ ' GLOBAL ' ] [ ' {} _TG ' . format ( _prefix ) ] ,
CONFIG [ ' GLOBAL ' ] [ ' {} _TIMESLOT ' . format ( _prefix ) ] )
logger . info ( ' (VOICE-RELOAD) Recarga de voice.cfg completada ' )
def scheduledTTSAnnouncement ( _tts_num = 1 ) :
global _tts_last_hour , _tts_running
@ -3540,6 +3623,7 @@ if __name__ == '__main__':
_ann_task = task . LoopingCall ( scheduledAnnouncement , _ann_num )
_ann_def = _ann_task . start ( _ann_check_interval , now = False )
_ann_def . addErrback ( loopingErrHandle )
_ann_tasks [ _ann_num ] = _ann_task
logger . info ( ' ( %s ) Scheduled announcements enabled - mode: %s , file: %s , TG: %s , TS: %s , lang: %s ' ,
_label ,
_ann_mode ,
@ -3562,6 +3646,7 @@ if __name__ == '__main__':
_tts_task = task . LoopingCall ( scheduledTTSAnnouncement , _tts_num )
_tts_def = _tts_task . start ( _tts_check_interval , now = False )
_tts_def . addErrback ( loopingErrHandle )
_tts_tasks [ _tts_num ] = _tts_task
logger . info ( ' ( %s ) Scheduled TTS announcements enabled - mode: %s , file: %s , TG: %s , TS: %s , lang: %s ' ,
_label ,
_tts_mode ,
@ -3572,6 +3657,19 @@ if __name__ == '__main__':
if _tts_mode == ' interval ' :
logger . info ( ' ( %s ) Interval: every %s seconds ' , _label , _tts_check_interval )
_voice_cfg_config_file = cli_args . CONFIG_FILE
_voice_cfg_dir = os . path . dirname ( os . path . abspath ( cli_args . CONFIG_FILE ) )
_voice_cfg_file = os . path . join ( _voice_cfg_dir , ' voice.cfg ' )
if os . path . isfile ( _voice_cfg_file ) :
try :
_voice_cfg_mtime = os . path . getmtime ( _voice_cfg_file )
except OSError :
_voice_cfg_mtime = 0
voice_reload_task = task . LoopingCall ( _checkVoiceConfigReload )
voice_reload = voice_reload_task . start ( 15 )
voice_reload . addErrback ( loopingErrHandle )
logger . info ( ' (VOICE-RELOAD) Vigilancia de voice.cfg activada (cada 15 segundos) ' )
#Security downloads from central server
init_security_downloads ( CONFIG )