Skip to content

Commit

Permalink
feat: cli interface
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Dec 21, 2024
1 parent 246525b commit d506c18
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
42 changes: 33 additions & 9 deletions hivemind_mic_sat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
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
from ovos_utils.fakebus import FakeBus
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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()


Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
hivemind_bus_client>=0.1.0,<1.0.0
ovos-plugin-manager<1.0.0
ovos-audio<1.0.0
ovos-audio<1.0.0
click

0 comments on commit d506c18

Please sign in to comment.