From ce70b4480feae53641c53565e27f3f721bbcd7ca Mon Sep 17 00:00:00 2001 From: miro Date: Fri, 16 Aug 2024 05:12:27 +0100 Subject: [PATCH 1/2] performance/real_websocket --- hivemind_voice_satellite/__main__.py | 29 +++++++++++++++++++++++++--- requirements.txt | 3 ++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/hivemind_voice_satellite/__main__.py b/hivemind_voice_satellite/__main__.py index 3ed4134..9916375 100644 --- a/hivemind_voice_satellite/__main__.py +++ b/hivemind_voice_satellite/__main__.py @@ -5,12 +5,31 @@ from hivemind_bus_client.identity import NodeIdentity from hivemind_ggwave import GGWaveSlave from ovos_audio.service import PlaybackService +from ovos_bus_client.client import MessageBusClient from ovos_utils import wait_for_exit_signal from ovos_utils.log import init_service_logger, LOG - +from ovos_utils.fakebus import FakeBus from hivemind_voice_satellite import VoiceClient +def launch_bus_daemon() -> MessageBusClient: + from ovos_utils import create_daemon + from tornado import web, ioloop + from ovos_messagebus.event_handler import MessageBusEventHandler + + INTERNAL_PORT = 9987 # can be anything, wanted to differentiate from standard ovos-bus + + routes = [("/core", MessageBusEventHandler)] + application = web.Application(routes) + application.listen(INTERNAL_PORT, "127.0.0.1") + create_daemon(ioloop.IOLoop.instance().start) + + bus = MessageBusClient(host="127.0.0.1", port=INTERNAL_PORT) + bus.run_in_thread() + return bus + + +# TODO - add a flag to use FakeBus instead of real websocket @click.command(help="connect to HiveMind") @click.option("--host", help="hivemind host", type=str, default="") @click.option("--key", help="Access Key", type=str, default="") @@ -67,13 +86,17 @@ def handle_complete(message): LOG.error(f"ws://{host} or wss://{host}") exit(1) + # TODO - flag for fakebus + internal_bus = launch_bus_daemon() or FakeBus() + # connect to hivemind bus = HiveMessageBusClient(key=key, password=password, port=port, host=host, - useragent="VoiceSatelliteV0.3.0", - self_signed=selfsigned) + useragent="VoiceSatelliteV0.3.1", + self_signed=selfsigned, + internal_bus=internal_bus) bus.connect(site_id=siteid) # create Audio Output interface (TTS/Music) diff --git a/requirements.txt b/requirements.txt index 7e2db83..21f2f97 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,5 @@ ovos-stt-plugin-server ovos-tts-plugin-server ovos-ww-plugin-vosk click -hivemind-ggwave \ No newline at end of file +hivemind-ggwave +ovos-messagebus \ No newline at end of file From f1f80dc156eb198b8b8c4a3bbcf2775dc6112c34 Mon Sep 17 00:00:00 2001 From: miro Date: Fri, 16 Aug 2024 05:18:50 +0100 Subject: [PATCH 2/2] performance/real_websocket --- hivemind_voice_satellite/__main__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hivemind_voice_satellite/__main__.py b/hivemind_voice_satellite/__main__.py index 9916375..c6ea092 100644 --- a/hivemind_voice_satellite/__main__.py +++ b/hivemind_voice_satellite/__main__.py @@ -37,7 +37,8 @@ def launch_bus_daemon() -> MessageBusClient: @click.option("--port", help="HiveMind port number", type=int, default=5678) @click.option("--selfsigned", help="accept self signed certificates", is_flag=True) @click.option("--siteid", help="location identifier for message.context", type=str, default="") -def connect(host, key, password, port, selfsigned, siteid): +@click.option("--fakebus", help="use FakeBus instead of real websocket", is_flag=True) +def connect(host, key, password, port, selfsigned, siteid, fakebus): init_service_logger("HiveMind-voice-sat") identity = NodeIdentity() @@ -49,7 +50,6 @@ def connect(host, key, password, port, selfsigned, siteid): if not password: LOG.info("starting hivemind-ggwave, waiting for audio password") try: - ggwave = GGWaveSlave(key=key) # reuse existing key ready = Event() @@ -86,8 +86,11 @@ def handle_complete(message): LOG.error(f"ws://{host} or wss://{host}") exit(1) - # TODO - flag for fakebus - internal_bus = launch_bus_daemon() or FakeBus() + # Check for fakebus flag + if fakebus: + internal_bus = FakeBus() + else: + internal_bus = launch_bus_daemon() or FakeBus() # connect to hivemind bus = HiveMessageBusClient(key=key,