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 __future__ import print_function, unicode_literals
from dataclasses import asdict
import asyncio import asyncio
from copy import copy from copy import copy
import time import time
@@ -16,7 +17,8 @@ from text_to_speech import text_to_speech
from encode import encode_lc3 from encode import encode_lc3
from auracast import multicast_control from auracast import multicast_control
from auracast import auracast_config 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 # 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)) log.info("Starting all broadcasts took %s s", round(time.time() - start, 3))
async def command_line_ui(caster: multicast_control.Multicaster): async def command_line_ui(caster: multicast_control.Multicaster):
while True: 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": if command.strip().lower() == "quit":
print("👋 Exiting...") print("👋 Exiting...")
@@ -74,12 +81,17 @@ async def command_line_ui(caster: multicast_control.Multicaster):
caster.stop_streaming() caster.stop_streaming()
await caster.shutdown() await caster.shutdown()
break # Exit loop break # Exit loop
# TODO: Implement predefined announcements
elif command.strip() == '': elif command.strip() == '':
print('Nothing to Announce') 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: else:
await announcement_from_german_text(caster, command) await announcement_from_german_text(caster, command)
await asyncio.wait([caster.streamer.task])
async def main(): async def main():
log.basicConfig( 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-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 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_de,
auracast_config.broadcast_en, auracast_config.broadcast_en,
auracast_config.broadcast_fr, auracast_config.broadcast_fr,
@@ -112,4 +124,8 @@ async def main():
#await asyncio.wait([caster.streamer.task]) #await asyncio.wait([caster.streamer.task])
if __name__ == '__main__': 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

View File

@@ -1,9 +1,11 @@
TESTSENTENCE_DE_HELLO = 'Hallo Welt.' from dataclasses import dataclass, fields, asdict
TESTSENTENCE_DE_WAVE_PARTICLE = 'Der Wellen-Teilchen-Dualismus beschreibt die Eigenschaft von Teilchen, sowohl als Wellen auf der Mikroebene zu verhalten und gleichzeitig bestimmte Eigenschaften wie Impuls und Energietrang zu besitzen.'
TESTSENTENCE_DE_BROKER = 'Ein Broker (oder Makler) ist eine Person oder ein Unternehmen, das sich zwischen dem Kauf- und Verkaufsberechtigten einer Wirtschaftsgüter (z.B. Aktien, Optionen, Derivate, Währungen, Rohstoffe usw.) stellt und als Vermittler fungiert. Sein Hauptziel ist es, Transaktionen zu erleichtern und Geld für sich selbst zu verdienen.' @dataclass
TESTSENTENCE_DE_RAINBOW = 'Der Regenbogen ist ein atmosphärisch-optisches Phänomen, das als kreisbogenförmiges farbiges Lichtband in einer von der Sonne beschienenen Regenwand oder wolke wahrgenommen wird.' class TestContent:
TESTSENTENCE_DE_GATE_OPENED = "Please be advised that Gate 23 has opened for boarding." DE_HELLO: str = 'Hallo Welt.'
TESTSENTENCE_DE_TRAIN_DELAYS = "Please note that delays have been reported on the InterCity train route. We apologize for any inconvenience this may cause." DE_GATE_OPENED: str = "Gate 23 ist jetzt geöffnet."
TESTSENTENCE_DE_LOST_LUGGAGE = "Attention passengers! Lost luggage has been reported at Track 4. If you have not yet received your bag, please report to our lost luggage desk for assistance." DE_TRAIN_ARRIVING: str = "Der Zug Nach Wien fährt heute von Gleis 3."
TESTSENTENCE_DE_PLANE_TAKEOFF_DELAYED = "This departing flight's departure time has changed due to weather conditions. The new boarding time will be advised shortly." DE_SECURITY_CHECKPOINT_OPENING: str = "Sicherheitskontrolle 5 ist jetzt geöffnet. Bitte setzen Sie sich in Bewegung, um Ihre Wartezeit während Sicherungsprüfungen zu minimieren."
TESTSENTENCE_DE_SECURITY_CHECKPOINT_OPENING = "Security Checkpoint 5 is now open. Please proceed through the checkpoint to minimize your wait time during security screening." DE_RAINBOW: str = 'Der Regenbogen ist ein atmosphärisch-optisches Phänomen, das als kreisbogenförmiges farbiges Lichtband in einer von der Sonne beschienenen Wolke oder Regenwand wahrgenommen wird und ein großes Farbspektrum anzeigt.'
DE_WAVE_PARTICLE: str = 'Der Wellen-Teilchen-Dualismus ist eine Konzeption, die postuliert, dass Teilchen sowohl als Wellen auf der Mikroebene verhalten sich und genau bestimme Eigenschaften wie Impuls und Energietrang besaßen.'
TESTSENTENCE = TestContent()