diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 43682fb..6f9b75b 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -17,7 +17,8 @@ { "label": "pip install -e auracast", "type": "shell", - "command": "./venv/bin/python -m pip install -e ../bumble-auracast --config-settings editable_mode=compat" + "command": "./venv/bin/python -m pip install -e ../bumble-auracast --config-settings editable_mode=compat", + "problemMatcher": [] } ] } \ No newline at end of file diff --git a/src/multilang_translator/main_cloud.py b/src/multilang_translator/main_cloud.py index e69de29..78359d3 100644 --- a/src/multilang_translator/main_cloud.py +++ b/src/multilang_translator/main_cloud.py @@ -0,0 +1,95 @@ +from typing import List +import time + +import logging as log + +from auracast import multicast_client +from auracast import auracast_config + +import voice_client +import voice_models + +from multilang_translator import translator_config +from multilang_translator.translator import llm_translator +import voice_client.tts_client +import voice_models.request_models + + +def announcement_from_german_text( + global_config: auracast_config.AuracastGlobalConfig, + translator_config: List[translator_config.TranslatorConfigDe], + text_de + ): + base_lang = "deu" + + audio_data_dict = {} + for i, trans in enumerate(translator_config): + if trans.big.language == base_lang: + text = text_de + else: + text = llm_translator.translate_de_to_x( + text_de, + trans.big.language, + model=trans.translator_llm, + client = trans.llm_client, + host=trans.llm_host_url, + token=trans.llm_host_token + ) + + log.info('%s', text) + request_data = voice_models.request_models.SynthesizeRequest( + text=text, + target_sample_rate=global_config.auracast_sampling_rate_hz, + framework=trans.tts_system, + model=trans.tts_model, + return_lc3=True + ) + lc3_audio = voice_client.tts_client.request_synthesis( + request_data + ) + + # lc3_audio = text_to_speech.synthesize( + # text, + # global_config.auracast_sampling_rate_hz, + # trans.tts_system, + # trans.tts_model, + # return_lc3=True + # ) + + audio_data_dict[trans.big.language] = lc3_audio.decode('latin-1') # TODO: should be .hex in the future + + multicast_client.send_audio( + audio_data_dict + ) + + +if __name__ == '__main__': + log.basicConfig( + level=log.INFO, + format='%(module)s.py:%(lineno)d %(levelname)s: %(message)s' + ) + + global_conf = auracast_config.AuracastGlobalConfig() + #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 + + + translator_conf = [ + translator_config.TranslatorConfigDe(), + translator_config.TranslatorConfigEn(), + translator_config.TranslatorConfigFr(), + #auracast_config.broadcast_es, + #auracast_config.broadcast_it, + ] + + for conf in translator_conf: + conf.big.loop = False + conf.llm_client = 'openwebui' # comment out for local llm + conf.llm_host_url = 'https://ollama.pstruebi.xyz' + conf.llm_host_token = 'sk-17124cb84df14cc6ab2d9e17d0724d13' + + + multicast_client.initialize() + + announcement_from_german_text(global_conf, translator_conf, 'Hello') + diff --git a/src/multilang_translator/main_local.py b/src/multilang_translator/main_local.py index 7e00fe1..64e9a58 100644 --- a/src/multilang_translator/main_local.py +++ b/src/multilang_translator/main_local.py @@ -1,9 +1,3 @@ -# -*- coding: utf-8 -*- -""" -list prompt example -""" -from __future__ import print_function, unicode_literals - from typing import List from dataclasses import asdict import asyncio diff --git a/src/voice_client/client.py b/src/voice_client/tts_client.py similarity index 96% rename from src/voice_client/client.py rename to src/voice_client/tts_client.py index f7b05b3..3ee7732 100644 --- a/src/voice_client/client.py +++ b/src/voice_client/tts_client.py @@ -5,6 +5,7 @@ import soundfile as sf from voice_models.request_models import SynthesizeRequest +API_URL = "http://127.0.0.1:8099/synthesize/" def request_synthesis(request_data: SynthesizeRequest): response = requests.post(API_URL, json=request_data.model_dump()) @@ -27,7 +28,6 @@ def request_synthesis(request_data: SynthesizeRequest): print(f"Error: {response.status_code}, {response.text}") if __name__ == "__main__": - API_URL = "http://127.0.0.1:8099/synthesize/" target_rate=16000 diff --git a/src/voice_provider/tts_server.py b/src/voice_provider/tts_server.py index b69504c..15cb75c 100644 --- a/src/voice_provider/tts_server.py +++ b/src/voice_provider/tts_server.py @@ -6,6 +6,8 @@ from voice_provider.text_to_speech import synthesize app = FastAPI() +HOST_PORT = 8099 + @app.post("/synthesize/") async def synthesize_speech(request: SynthesizeRequest): @@ -29,4 +31,4 @@ async def synthesize_speech(request: SynthesizeRequest): if __name__ == "__main__": import uvicorn - uvicorn.run(app, host="127.0.0.1", port=8099) \ No newline at end of file + uvicorn.run(app, host="127.0.0.1", port=HOST_PORT) \ No newline at end of file