implement support for predefinced announcements

This commit is contained in:
2025-02-25 14:39:15 +01:00
parent a9acfd2d2c
commit a8879a299e
2 changed files with 34 additions and 16 deletions

View File

@@ -4,6 +4,7 @@ list prompt example
"""
from __future__ import print_function, unicode_literals
from dataclasses import asdict
import asyncio
from copy import copy
import time
@@ -16,7 +17,8 @@ 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
from config import LANG_CONFIG, SAMPLING_RATE_HZ
from translator.test_content import TESTSENTENCE
# TODO: look for a end to end translation solution
@@ -63,10 +65,15 @@ async def announcement_from_german_text(caster:multicast_control.Multicaster, te
log.info("Starting all broadcasts took %s s", round(time.time() - start, 3))
async def command_line_ui(caster: multicast_control.Multicaster):
while True:
command = await aioconsole.ainput("\nEnter your Announcement|quit] > ")
# make a list of all available testsentence
sentence_list = list(asdict(TESTSENTENCE).values())
prompt = "Enter your Announcement|quit or choose:] > \n"
prompt += "\n".join([f"{i}: {s}" for i,s in enumerate(sentence_list)])
prompt += "\n"
command = await aioconsole.ainput(prompt)
if command.strip().lower() == "quit":
print("👋 Exiting...")
@@ -74,12 +81,17 @@ async def command_line_ui(caster: multicast_control.Multicaster):
caster.stop_streaming()
await caster.shutdown()
break # Exit loop
# TODO: Implement predefined announcements
elif command.strip() == '':
print('Nothing to Announce')
# Check if command is a single number
elif command.strip().isdigit():
ind = int(command.strip())
await announcement_from_german_text(caster, sentence_list[ind])
await asyncio.wait([caster.streamer.task])
# Interpret the command as announcement
else:
await announcement_from_german_text(caster, command)
await asyncio.wait([caster.streamer.task])
async def main():
log.basicConfig(
@@ -91,7 +103,7 @@ async def main():
#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, better: make a hirachry of dataclasses
big_conf = [
auracast_config.broadcast_de,
auracast_config.broadcast_en,
auracast_config.broadcast_fr,
@@ -112,4 +124,8 @@ async def main():
#await asyncio.wait([caster.streamer.task])
if __name__ == '__main__':
asyncio.run(main())
asyncio.run(main())
# TODO: integrate this in the LANG_CONFIG dict, better: make a hierachy of dataclasses
# TODO: remove the nececcity for files
# TODO: add support for multiple radios