refractoring to use ghe global config.py
This commit is contained in:
@@ -19,54 +19,27 @@ from .text_to_speech import text_to_speech, resample
|
||||
from .backend_controller.broadcaster_config import broadcaster_config
|
||||
from .backend_controller.broadcaster_play_once import broadcaster_play_file
|
||||
from .backend_controller.broadcaster_copy_files import copy_to_broadcaster
|
||||
|
||||
from .encode import encode_lc3
|
||||
|
||||
ANNOUNCEMENT_DIR = os.path.join(os.path.dirname(__file__), 'announcements')
|
||||
SAMPLING_RATE = int(16e3)
|
||||
FRAME_DUR_MS = 10
|
||||
BPS = int(32e3) # TODO test 16khz 16kbps
|
||||
CONFIG = {
|
||||
"de": {
|
||||
"file": f"{ANNOUNCEMENT_DIR}/announcement_{SAMPLING_RATE//1000}_{FRAME_DUR_MS}_{BPS//1000}_de",
|
||||
"tts": 'de_DE-kerstin-low',
|
||||
},
|
||||
"en": {
|
||||
"file": f"{ANNOUNCEMENT_DIR}/announcement_{SAMPLING_RATE//1000}_{FRAME_DUR_MS}_{BPS//1000}_en",
|
||||
"tts": 'en_US-lessac-medium'
|
||||
},
|
||||
"fr": {
|
||||
"file": f"{ANNOUNCEMENT_DIR}/announcement_{SAMPLING_RATE//1000}_{FRAME_DUR_MS}_{BPS//1000}_fr",
|
||||
"tts": 'fr_FR-siwis-medium'
|
||||
},
|
||||
"es": {
|
||||
"file": f"{ANNOUNCEMENT_DIR}/announcement_{SAMPLING_RATE//1000}_{FRAME_DUR_MS}_{BPS//1000}_es",
|
||||
"tts": 'es_ES-sharvard-medium'
|
||||
},
|
||||
"it": {
|
||||
"file": f"{ANNOUNCEMENT_DIR}/announcement_{SAMPLING_RATE//1000}_{FRAME_DUR_MS}_{BPS//1000}_it",
|
||||
"tts": 'it_IT-paola-medium'
|
||||
}
|
||||
}
|
||||
from .config import LANG_CONFIG, BITRATE_BPS, SAMPLING_RATE_HZ, FRAME_DUR_MS
|
||||
|
||||
os.makedirs(ANNOUNCEMENT_DIR, exist_ok=True)
|
||||
|
||||
def synthesize_resample_encode(text, tts_model, output_file):
|
||||
audio_dur = text_to_speech.synthesize(text, tts_model, output_file)
|
||||
resample.resample(output_file, output_file, target_rate=SAMPLING_RATE)
|
||||
encode_lc3.encode_lc3(output_file, bps=BPS, frame_dur_ms=FRAME_DUR_MS)
|
||||
resample.resample(output_file, output_file, target_rate=SAMPLING_RATE_HZ)
|
||||
encode_lc3.encode_lc3(output_file, bps=BITRATE_BPS, frame_dur_ms=FRAME_DUR_MS)
|
||||
return audio_dur
|
||||
|
||||
def translate_from_german_and_encode(text_de):
|
||||
config = copy(CONFIG)
|
||||
config = copy(LANG_CONFIG)
|
||||
base_lang = "de"
|
||||
|
||||
file = config[base_lang]["file"]
|
||||
audio_dur_s = {}
|
||||
audio_dur_s [base_lang] = synthesize_resample_encode(text_de, config['de']["tts"], f'{file}.wav')
|
||||
|
||||
del config[base_lang]
|
||||
|
||||
audio_dur_s = {}
|
||||
for key, val in config.items():
|
||||
text = llm_translator.translate_de_to_x(key, text_de)
|
||||
file = val['file']
|
||||
@@ -78,15 +51,17 @@ def announcement_from_german_text(text_de):
|
||||
audio_durs = translate_from_german_and_encode(text_de)
|
||||
# Transfer the files to broadcaster memory
|
||||
start = time.time()
|
||||
for val in CONFIG.values():
|
||||
for val in LANG_CONFIG.values():
|
||||
copy_to_broadcaster(f'{val["file"]}.lc3')
|
||||
log.info("Transfering files to broadcaster took %s s", round(time.time() - start, 3))
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
# Instruct the broadcaster to stream the files
|
||||
for i, d in enumerate(list(CONFIG.items())):
|
||||
for i, d in enumerate(list(LANG_CONFIG.items())):
|
||||
key, val = d
|
||||
broadcaster_play_file(i, f'{os.path.basename(val["file"])}.lc3')
|
||||
time.sleep(audio_durs[key] + 1)
|
||||
time.sleep(audio_durs[key])
|
||||
|
||||
log.info("Starting all broadcasts %s s", round(time.time() - start, 3))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user