From 49ddc995b93b67277d376d21aa63bba6d63e4428 Mon Sep 17 00:00:00 2001 From: JarbasAi Date: Wed, 28 Jun 2023 16:29:26 +0100 Subject: [PATCH] :tada: --- hivemind_voice_satellite/__main__.py | 81 ++++--------- readme.md | 164 +++------------------------ requirements.txt | 3 +- setup.py | 2 +- 4 files changed, 42 insertions(+), 208 deletions(-) diff --git a/hivemind_voice_satellite/__main__.py b/hivemind_voice_satellite/__main__.py index dec6ec5..7c2ae8d 100644 --- a/hivemind_voice_satellite/__main__.py +++ b/hivemind_voice_satellite/__main__.py @@ -2,78 +2,47 @@ from hivemind_presence import LocalDiscovery from ovos_audio.service import PlaybackService from ovos_utils import wait_for_exit_signal - +import click from hivemind_voice_satellite import VoiceClient -def main(access_key=None, - host="wss://127.0.0.1", - port=5678, - password=None, - self_signed=False, - bus=None): +@click.command(help="connect to HiveMind") +@click.option("--host", help="hivemind host", type=str, default="wss://127.0.0.1") +@click.option("--key", help="Access Key", type=str) +@click.option("--password", help="Password for key derivation", type=str) +@click.option("--port", help="HiveMind port number", type=int, default=5678) +@click.option("--selfsigned", help="accept self signed certificates", is_flag=True) +def connect(host, key, password, port, selfsigned): + + if not host.startswith("ws"): + print("Invalid host, please specify a protocol") + print(f"ws://{host} or wss://{host}") + exit(1) + # connect to hivemind - if not bus: - bus = HiveMessageBusClient(key=access_key, - password=password, - port=port, - host=host, - useragent="VoiceSatelliteV0.3.0", - self_signed=self_signed) - bus.connect() + bus = HiveMessageBusClient(key=key, + password=password, + port=port, + host=host, + useragent="VoiceSatelliteV0.3.0", + self_signed=selfsigned) + bus.connect() # create Audio Output interface (TTS/Music) audio = PlaybackService(bus=bus, disable_ocp=True, validate_source=False) - audio.setDaemon(True) + audio.daemon = True audio.start() # STT listener thread service = VoiceClient(bus=bus) - service.setDaemon(True) + service.daemon = True service.start() wait_for_exit_signal() - service.shutdown() + service.stop() audio.shutdown() if __name__ == '__main__': - import argparse - - parser = argparse.ArgumentParser() - parser.add_argument("--access-key", help="access key", required=True) - parser.add_argument("--password", help="password", default=None) - parser.add_argument("--host", help="HiveMind host") - parser.add_argument("--port", help="HiveMind port number", default=5678) - parser.add_argument("--self-signed", help="accept self signed ssl certificates", action="store_true") - - args = parser.parse_args() - - if not args.host: - print("You did not specify a host to connect") - scan = input("scan for node and attempt to connect? y/n: ") - if not scan.lower().startswith("y"): - print("Scan aborted and host not specified, exiting") - exit(2) - scanner = LocalDiscovery() - for node in scanner.scan(): - print("Found HiveMind node: ", node.address) - try: - bus = node.connect(args.access_key, args.crypto_key, - useragent="VoiceSatelliteV0.2.0", - self_signed=args.self_signed) - scanner.stop() - main(bus=bus) - except: - print("failed to connect!") - exit(2) - elif not args.host.startswith("ws"): - print("Invalid host, please specify a protocol") - print(f"ws://{args.host} or wss://{args.host}") - exit(1) - - main(host=args.host, - port=args.port, - access_key=args.access_key, - password=args.password) + connect() diff --git a/readme.md b/readme.md index 4ec979b..2102401 100644 --- a/readme.md +++ b/readme.md @@ -1,20 +1,10 @@ # HiveMind Voice Satellite -Mycroft Voice Satellite, connect to [Mycroft HiveMind](https://github.com/JarbasSkills/skill-hivemind) +OpenVoiceOS Satellite, connect to [HiveMind](https://github.com/JarbasHiveMind/HiveMind-core) ![](./voice_terminal.png) -* [Setup](#setup) -* [Usage](#usage) -* [Configuration](#configuration) - - [configure speech to text](#configure-speech-to-text) - - [configure text to speech](#configure-text-to-speech) - - [configure hotwords](#configure-hotwords) - - [configure listener](#configure-listener) - - [configure audio playback](#configure-audio-playback) - - ![](./voice_sat.png) ## Install @@ -22,7 +12,7 @@ Mycroft Voice Satellite, connect to [Mycroft HiveMind](https://github.com/Jarba Install dependencies (if needed) ```bash -sudo apt-get install -y python-pyaudio swig libpulse-dev libasound2-dev +sudo apt-get install -y libpulse-dev libasound2-dev ``` Install with pip @@ -30,151 +20,27 @@ Install with pip ```bash $ pip install HiveMind-voice-sat ``` -## Usage -If host is not provided auto discovery will be used +## Usage ```bash -$ HiveMind-voice-sat --help - -usage: HiveMind-voice-sat [-h] [--access_key ACCESS_KEY] [--crypto_key CRYPTO_KEY] [--name NAME] [--host HOST] [--port PORT] - -optional arguments: - -h, --help show this help message and exit - --access_key ACCESS_KEY - access key - --crypto_key CRYPTO_KEY - payload encryption key - --name NAME human readable device name - --host HOST HiveMind host - --port PORT HiveMind port number -``` +Usage: hivemind-voice-sat [OPTIONS] -Default values are + connect to HiveMind -``` ---access_key - "RESISTENCEisFUTILE" ---crypto_key - "resistanceISfutile" ---name - "JarbasVoiceTerminal" ---port" - 5678 +Options: + --host TEXT hivemind host + --key TEXT Access Key + --password TEXT Password for key derivation + --port INTEGER HiveMind port number + --selfsigned accept self signed certificates + --help Show this message and exit. ``` + ## Configuration -You can set the configuration at +Voice satellite uses the default OpenVoiceOS configuration `~/.config/mycroft/mycroft.conf` - ~/.config/hivemind/hivemind.conf - -Otherwise default configuration will be used, check below for defaults - -### configure speech to text -```json -{ - "lang": "en-us", - "stt": { - "module": "google" - } -} -``` - -### configure text to speech -```json -{ - "lang": "en-us", - "tts": { - "module": "mimic2" - } -} -``` - -### Configure hotwords - -add any number of hot words to config -- hot word can be any engine (snowboy/pocketsphinx/precise) -- hot word can trigger listening or not -- hot word can play a sound or not -- hot word can be treated as full utterance or not - -```json -{ - "hotwords": { - "hey mycroft": { - "module": "pocketsphinx", - "phonemes": "HH EY . M AY K R AO F T", - "threshold": 1e-90, - "lang": "en-us", - "sound": "snd/start_listening.wav", - "listen": true - }, - "thank you": { - "module": "pocketsphinx", - "phonemes": "TH AE NG K . Y UW .", - "threshold": 0.1, - "listen": false, - "utterance": "thank you", - "active": false, - "sound": "", - "lang": "en-us" - }, - "wake up": { - "module": "pocketsphinx", - "phonemes": "W EY K . AH P", - "threshold": 1e-20, - "lang": "en-us" - } - } -} -``` - -### configure listener - -```json -{ - "listener": { - "sample_rate": 16000, - "channels": 1, - "multiplier": 1.0, - "energy_ratio": 1.5 - } -} -``` - -you can optionally set device_index -```json -{ - "listener": { - "device_index": 0 - } -} -``` -or device_name, which is a name or regex pattern -```json -{ - "listener": { - "device_name": "respeaker" - } -} -``` - -To trigger listening without a wakeword you can use an external signal - -```bash - touch {ipc_path}/signal/startListening -``` - -ipc_path can be set in config, default is ```/tmp/hivemind/ipc``` - -### Configure audio playback - -you shouldn"t need to change this, a common change is replacing ```aplay``` with ```paplay``` when using pulseaudio, or use sox for everything - -```json -{ - - "play_wav_cmd": "aplay %1", - "play_mp3_cmd": "mpg123 %1", - "play_ogg_cmd": "ogg123 -q %1" -} - -``` +See configuration from [ovos-dinkum-listener](https://github.com/OpenVoiceOS/ovos-dinkum-listener) for default values \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 1b4d0b0..a645835 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,7 @@ hivemind_bus_client~=0.0.3a2 -ovos-plugin-manager~=0.0.3a3 ovos-audio ovos-stt-plugin-server - +click ovos-dinkum-listener>=0.0.2a34, < 0.1.0 ovos-vad-plugin-silero ovos-config>=0.0.10 diff --git a/setup.py b/setup.py index ebb94bd..4fe2a31 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ def required(requirements_file): description='Hivemind Voice Satellite', entry_points={ 'console_scripts': [ - 'hivemind-voice-sat=hivemind_voice_satellite.__main__:main' + 'hivemind-voice-sat=hivemind_voice_satellite.__main__:connect' ] } )