From 98f4c4318d9a3d20e51ba8215d89113bb15644ca Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Sat, 21 Dec 2024 23:35:57 +0000 Subject: [PATCH] feat: cli interface (#11) --- hivemind_mic_sat/__init__.py | 42 ++++++++++++++++++++++++++++-------- requirements.txt | 3 ++- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/hivemind_mic_sat/__init__.py b/hivemind_mic_sat/__init__.py index 9bcd35b..e223958 100644 --- a/hivemind_mic_sat/__init__.py +++ b/hivemind_mic_sat/__init__.py @@ -3,13 +3,10 @@ from queue import Queue from typing import Optional, List -from ovos_bus_client.message import Message - -from hivemind_bus_client.client import HiveMessageBusClient, BinaryDataCallbacks -from hivemind_bus_client.message import HiveMessage, HiveMessageType -from hivemind_bus_client.serialization import HiveMindBinaryPayloadType +import click from ovos_audio.audio import AudioService from ovos_audio.playback import PlaybackThread as _PT +from ovos_bus_client.message import Message from ovos_plugin_manager.microphone import OVOSMicrophoneFactory, Microphone from ovos_plugin_manager.utils.tts_cache import hash_sentence from ovos_plugin_manager.vad import OVOSVADFactory, VADEngine @@ -17,6 +14,11 @@ from ovos_utils.log import LOG from ovos_utils.sound import play_audio +from hivemind_bus_client.client import HiveMessageBusClient, BinaryDataCallbacks +from hivemind_bus_client.identity import NodeIdentity +from hivemind_bus_client.message import HiveMessage, HiveMessageType +from hivemind_bus_client.serialization import HiveMindBinaryPayloadType + class PlaybackThread(_PT): # TODO - send PR to ovos-audio adding util method @@ -54,13 +56,13 @@ def handle_receive_tts(self, bin_data: bytes, class HiveMindMicrophoneClient: - def __init__(self, prefer_b64=False, enable_media=True): + def __init__(self, prefer_b64=False, enable_media=True, **kwargs): self.prefer_b64 = prefer_b64 internal = FakeBus() self.playback: PlaybackThread = PlaybackThread(bus=internal, queue=Queue()) self.hm_bus = HiveMessageBusClient(bin_callbacks=TTSHandler(self.playback), - internal_bus=internal) + internal_bus=internal, **kwargs) self.hm_bus.connect(FakeBus()) self.hm_bus.connected_event.wait() LOG.info("== connected to HiveMind") @@ -190,8 +192,30 @@ def stop(self): self.mic.stop() -def run(): - h = HiveMindMicrophoneClient() +@click.command() +@click.option("--key", help="HiveMind access key (default read from identity file)", type=str, default="") +@click.option("--password", help="HiveMind password (default read from identity file)", type=str, default="") +@click.option("--host", help="HiveMind host (default read from identity file)", type=str, default="") +@click.option("--port", help="HiveMind port number (default read from identity file or 5678)", type=int, required=False) +@click.option("--siteid", help="location identifier for message.context (default read from identity file)", type=str, + default="") +def run(key: str, password: str, host: str, port: int, siteid: str): + identity = NodeIdentity() + password = password or identity.password + key = key or identity.access_key + host = host or identity.default_master + identity.siteid = siteid or identity.site_id or "unknown" + port = port or identity.default_port or 5678 + + if not host.startswith("ws://") and not host.startswith("wss://"): + host = "ws://" + host + + if not key or not password or not host: + raise RuntimeError("NodeIdentity not set, please pass key/password/host or " + "call 'hivemind-client set-identity'") + + h = HiveMindMicrophoneClient(key=key, host=host, port=port, + password=password, identity=identity) h.run() diff --git a/requirements.txt b/requirements.txt index 78e353b..182a47d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ hivemind_bus_client>=0.1.0,<1.0.0 ovos-plugin-manager<1.0.0 -ovos-audio<1.0.0 \ No newline at end of file +ovos-audio<1.0.0 +click \ No newline at end of file