|
|
|
|
@ -92,14 +92,15 @@ def _generate_tts_audio(text, lang, mp3_path):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _convert_to_wav(mp3_path, wav_path):
|
|
|
|
|
def _convert_to_wav(mp3_path, wav_path, volume_db=0):
|
|
|
|
|
_cmd = ['ffmpeg', '-y', '-i', mp3_path,
|
|
|
|
|
'-ar', '8000', '-ac', '1', '-sample_fmt', 's16']
|
|
|
|
|
if volume_db != 0:
|
|
|
|
|
_cmd += ['-af', 'volume={}dB'.format(volume_db)]
|
|
|
|
|
logger.info('(TTS) Aplicando ajuste de volumen: %ddB', volume_db)
|
|
|
|
|
_cmd += ['-f', 'wav', wav_path]
|
|
|
|
|
try:
|
|
|
|
|
result = subprocess.run(
|
|
|
|
|
['ffmpeg', '-y', '-i', mp3_path,
|
|
|
|
|
'-ar', '8000', '-ac', '1', '-sample_fmt', 's16',
|
|
|
|
|
'-f', 'wav', wav_path],
|
|
|
|
|
capture_output=True, timeout=60
|
|
|
|
|
)
|
|
|
|
|
result = subprocess.run(_cmd, capture_output=True, timeout=60)
|
|
|
|
|
if result.returncode != 0:
|
|
|
|
|
logger.error('(TTS) Error ffmpeg: %s', result.stderr.decode('utf-8', errors='ignore')[:500])
|
|
|
|
|
return False
|
|
|
|
|
@ -297,7 +298,7 @@ def _encode_ambe_ambeserver(wav_path, ambe_path, host, port):
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def text_to_ambe(txt_path, ambe_path, language, vocoder_cmd, ambeserver_host='', ambeserver_port=2460):
|
|
|
|
|
def text_to_ambe(txt_path, ambe_path, language, vocoder_cmd, ambeserver_host='', ambeserver_port=2460, volume_db=0):
|
|
|
|
|
if not os.path.isfile(txt_path):
|
|
|
|
|
logger.warning('(TTS) Archivo de texto no encontrado: %s', txt_path)
|
|
|
|
|
return False
|
|
|
|
|
@ -331,7 +332,7 @@ def text_to_ambe(txt_path, ambe_path, language, vocoder_cmd, ambeserver_host='',
|
|
|
|
|
if not _generate_tts_audio(text, _tts_lang, _mp3_path):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
if not _convert_to_wav(_mp3_path, _wav_path):
|
|
|
|
|
if not _convert_to_wav(_mp3_path, _wav_path, volume_db):
|
|
|
|
|
_cleanup([_mp3_path])
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
@ -383,6 +384,7 @@ def ensure_tts_ambe(config, tts_num):
|
|
|
|
|
_vocoder_cmd = config['GLOBAL'].get('TTS_VOCODER_CMD', '')
|
|
|
|
|
_ambeserver_host = config['GLOBAL'].get('TTS_AMBESERVER_HOST', '')
|
|
|
|
|
_ambeserver_port = config['GLOBAL'].get('TTS_AMBESERVER_PORT', 2460)
|
|
|
|
|
_volume_db = config['GLOBAL'].get('TTS_VOLUME', -3)
|
|
|
|
|
|
|
|
|
|
_txt_path = './Audio/{}/ondemand/{}.txt'.format(_lang, _file)
|
|
|
|
|
_ambe_path = './Audio/{}/ondemand/{}.ambe'.format(_lang, _file)
|
|
|
|
|
@ -401,7 +403,7 @@ def ensure_tts_ambe(config, tts_num):
|
|
|
|
|
logger.warning('(TTS-%d) Archivo de texto no encontrado: %s', tts_num, _txt_path)
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
if text_to_ambe(_txt_path, _ambe_path, _lang, _vocoder_cmd, _ambeserver_host, _ambeserver_port):
|
|
|
|
|
if text_to_ambe(_txt_path, _ambe_path, _lang, _vocoder_cmd, _ambeserver_host, _ambeserver_port, _volume_db):
|
|
|
|
|
return _ambe_path
|
|
|
|
|
else:
|
|
|
|
|
if os.path.isfile(_ambe_path):
|
|
|
|
|
|