Skip to content

Commit

Permalink
🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Jun 28, 2023
1 parent 2e5d3a2 commit 49ddc99
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 208 deletions.
81 changes: 25 additions & 56 deletions hivemind_voice_satellite/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
164 changes: 15 additions & 149 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,180 +1,46 @@
# 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

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

```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
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
}
)

0 comments on commit 49ddc99

Please sign in to comment.