96 lines
3.2 KiB
Python
96 lines
3.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
list prompt example
|
|
"""
|
|
from __future__ import print_function, unicode_literals
|
|
|
|
import asyncio
|
|
from copy import copy
|
|
import time
|
|
import logging as log
|
|
from translator import llm_translator, test_content
|
|
from text_to_speech import text_to_speech
|
|
from encode import encode_lc3
|
|
from auracast import multicast_control
|
|
from auracast import auracast_config
|
|
from config import LANG_CONFIG, BITRATE_BPS, SAMPLING_RATE_HZ, FRAME_DUR_MS
|
|
|
|
|
|
def transcribe():
|
|
pass
|
|
|
|
|
|
def syntesize(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_HZ)
|
|
#encode_lc3.encode_lc3(output_file, bps=BITRATE_BPS, frame_dur_ms=FRAME_DUR_MS)
|
|
return audio_dur
|
|
|
|
def translate_from_german(text_de):
|
|
config = copy(LANG_CONFIG)
|
|
base_lang = "de"
|
|
|
|
file = config[base_lang]["file"]
|
|
audio_dur_s = {}
|
|
audio_dur_s [base_lang] = syntesize(text_de, config['de']["tts"], f'{file}.wav')
|
|
|
|
del config[base_lang]
|
|
|
|
for key, val in config.items():
|
|
text = llm_translator.translate_de_to_x(text_de, key)
|
|
file = val['file']
|
|
audio_dur_s[key] = syntesize(text, val['tts'], f'{file}.wav')
|
|
return audio_dur_s
|
|
|
|
async def announcement_from_german_text(caster:multicast_control.Multicaster, text_de):
|
|
|
|
translate_from_german(text_de)
|
|
# Transfer the files to broadcaster memory
|
|
start = time.time()
|
|
|
|
await caster.init_audio()
|
|
await caster.start_streaming()
|
|
|
|
#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(LANG_CONFIG.items())):
|
|
# key, val = d
|
|
# broadcaster_play_file(i, f'{os.path.basename(val["file"])}.lc3')
|
|
# time.sleep(audio_durs[key])
|
|
|
|
log.info("Starting all broadcasts took %s s", round(time.time() - start, 3))
|
|
|
|
|
|
async def main():
|
|
global_conf = auracast_config.global_base_config
|
|
#global_conf.transport='serial:/dev/serial/by-id/usb-SEGGER_J-Link_001057705357-if02,1000000,rtscts' # transport for nrf54l15dk
|
|
global_conf.transport='serial:/dev/serial/by-id/usb-ZEPHYR_Zephyr_HCI_UART_sample_81BD14B8D71B5662-if00,115200,rtscts' #nrf52dongle hci_uart usb cdc
|
|
|
|
big_conf = [ # TODO: integrate this in the LANG_CONFIG dict
|
|
auracast_config.broadcast_de,
|
|
auracast_config.broadcast_en,
|
|
auracast_config.broadcast_fr,
|
|
#auracast_config.broadcast_es,
|
|
#auracast_config.broadcast_it,
|
|
]
|
|
files = [v['file'] for v in LANG_CONFIG.values()]
|
|
for i, conf in enumerate(big_conf):
|
|
conf.loop_wav = False
|
|
conf.audio_source = f'file:{files[i]}'
|
|
conf.input_format = 'int16le,48000,1' # TODO: Use actual samplint rate from piper
|
|
|
|
caster = multicast_control.Multicaster(global_conf, big_conf)
|
|
await caster.init_broadcast()
|
|
|
|
#await command_line_ui(caster)
|
|
|
|
await announcement_from_german_text(caster, test_content.TESTSENTENCE_DE_HELLO)
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(main()) |