• This repository has been archived on 19/Dec/2023
  • Stars
    star
    187
  • Rank 206,464 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created about 1 year ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Streaming audio satellite for Home Assistant

Deprecation Notice

NOTE: Work has moved to the wyoming-satellite project. This has better integration with Home Assistant, and is more modular with audio services.


[DEPRECATED] Home Assistant Satellite

Python-based satellite for Assist that streams audio to Home Assistant from a microphone.

You must have the openWakeWord add-on installed.

Requirements

  • Python 3.9 or higher
  • ffmpeg
  • alsa-utils (for arecord and aplay)

Installation

Install Python and the required system dependencies:

sudo apt-get update
sudo apt-get install python3 python3-pip python3-venv \
                     alsa-utils git

sudo apt-get install --no-install-recommends \
                     ffmpeg

Clone the repository and run the setup script:

git clone https://github.com/synesthesiam/homeassistant-satellite.git
cd homeassistant-satellite
script/setup

This will create a virtual environment and install the package.

Long-Lived Access Token

You must create a long-lived access token in Home Assistant for the satellite to access the websocket API.

  1. Go to your profile page in Home Assistant
  2. Scroll down to "Long-lived access tokens"
  3. Click "Create token"
  4. Enter a name and click "OK"
  5. Copy the entire token using the copy button provided
  6. Save the token somewhere you can paste from later

Running

script/run --host <IP> --token <TOKEN>

where <IP> is the IP address of your Home Assistant server and <TOKEN> is the long-lived access token.

This will stream audio from the default microphone to your preferred pipeline in Home Assistant.

See --help for more options

Feedback Sounds

Use --awake-sound <WAV> and --done-sound <WAV> to play sounds when the wake word is detected and when a voice command is finished.

For example:

script/run ... --awake-sound sounds/awake.wav --done-sound sounds/done.wav

Pipeline Name

The preferred pipeline will be run by default, but you change this with --pipeline <NAME> where <NAME> is the name of the pipeline you'd like to run instead.

Change Microphone/Speaker

Run arecord -L to list available input devices. Pick devices that start with plughw: because they will perform software audio conversions. Use --mic-device plughw:... to use a specific input device.

Run aplay -L to list available output devices. Pick devices that start with plughw: because they will perform software audio conversions. Use --snd-device plughw:... to use a specific output device.

Voice Activity Detection

For fast but inaccurate speech detection:

.venv/bin/pip3 install .[webrtc]

and

script/run ... --vad webrtcvad

For much better (but slower) speech detection, use silero VAD with:

.venv/bin/pip3 install \
  --find-links https://synesthesiam.github.io/prebuilt-apps/ \
  .[silerovad]

and

script/run ... --vad silero

NOTE: The --find-links option is only necessary on 32-bit ARM systems because Microsoft does not build onnxruntime wheels for them.

Audio Enhancements

Make use of webrtc-noise-gain with:

.venv/bin/pip3 install .[webrtc]

Use --noise-suppression <NS> suppress background noise, such as fans (0-4 with 4 being max suppression, default: 0).

Use--auto-gain <AG> to automatically increase the microphone volume (0-31 with 31 being the loudest, default: 0).

Use--volume-multiplier <VM> to multiply volume by <VM> so 2.0 would be twice as loud (default: 1.0).

Wake word detection via a direct wyoming connection

By default wake word detection is performed by forwarding audio to Home Assistant. It is also possible to perform wake word detection using a wyoming server, possibly (but not necessarily) running on the same machine as the satellite.

To enable:

.venv/bin/pip3 install .[wyoming]

script/run ... --wake-word wyoming

Use --wyoming-host <host> to set the host of the wyoming server (default localhost).

Use --wyoming-port <port> to set the port of the wyoming server (default 10400).

Use --wake-word-id <id> to detect a specific wake word instead of the server's default.

HTTPS

If your Home Assistant server uses https, you will need to add --protocol https to your command.

PulseAudio / PipeWire

Enable PulseAudio / PipeWire support with:

sudo apt-get install libpulse0

.venv/bin/pip3 install .[pulseaudio]

Use --pulseaudio to record and play audio via PulseAudio or PipeWire. A socket or hostname can be optionally provided as --pulseaudio=<socket|host>.

When using PulseAudio, ducking and acoustic echo cancelation are available to facilitate cases when the satellite is simultaneously used to play music, movies, etc. Such sounds are captured by the microphone, together with the user's voice, and interfere wake word detection and speech recognition.

--echo-cancel enables PulseAudio's acoustic echo cancelation, which removes playback sounds from the captured audio, making wake word detection easier.

--ducking=<vol> sets the volume of all playback streams to <vol> (e.g., 0.2 for 20%) after the wake word is detected and until the pipeline finishes, making speech recognition easier.

Running as a Service

You can run homeassistant-satellite as a systemd service by first creating a service file:

sudo systemctl edit --force --full homeassistant-satellite.service

Paste in the following template, and change both /home/pi/homeassistant-satellite and the script/run arguments to match your set up:

[Unit]
Description=Home Assistant Satellite
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
ExecStart=/home/pi/homeassistant-satellite/script/run --host <host> --token <token>
WorkingDirectory=/home/pi/homeassistant-satellite
Restart=always
RestartSec=1

[Install]
WantedBy=default.target

Save the file and exit your editor. Next, enable the service to start at boot and run it:

sudo systemctl enable --now homeassistant-satellite.service

(you may need to hit CTRL+C to get back to a shell prompt)

With the service running, you can view logs in real-time with:

journalctl -u homeassistant-satellite.service -f

Disable and stop the service with:

sudo systemctl disable --now homeassistant-satellite.service

Running in Docker

On the command-line:

docker run --rm -it \
    --name 'homeassistant-satellite' \
    --device /dev/snd \
    --group-add=audio \
    ghcr.io/synesthesiam/homeassistant-satellite:latest \
    --host <HOST> \
    --token <TOKEN> \
    ...

Using Docker Compose:

version: "3.8"
services:
  homeassistant-satellite:
    image: "ghcr.io/synesthesiam/homeassistant-satellite:latest"
    devices:
      - /dev/snd:/dev/snd
    group_add:
      - audio
    command:
      - --host
      - <HOST>
      - --token
      - <TOKEN>

It may be necessary to manually specify --mic-device plughw:... and --snd-device plughw:... when using Docker.

Troubleshooting

Add --debug to get more information about the messages being exchanged with Home Assistant.

Add --debug-recording-dir <DIR> to save recorded audio to a directory <DIR>.

More Repositories

1

voice2json

Command-line tools for speech and intent recognition on Linux
Python
1,085
star
2

rhasspy

Rhasspy voice assistant for offline home automation
HTML
942
star
3

opentts

Open Text to Speech Server
Python
893
star
4

docker-mozillatts

Docker image for Mozilla TTS server
Python
179
star
5

old-custom-components

A voice assistant toolkit for Home Assistant
Python
75
star
6

magicpy

An autostereogram (MagicEye) image generator written in Python
Python
70
star
7

coqui-docker

Docker images for Coqui AI
Shell
55
star
8

hassio-addons

My Hass.IO add-ons
Shell
43
star
9

docker-marytts

MaryTTS text to speech server and a collection of voices for various languages
Shell
33
star
10

voice-recorder

Simple tkinter application for recorded voice samples with text prompts
Python
17
star
11

eyecode

Python library for analyzing gaze data from programmers
JavaScript
17
star
12

jsgf-gen

Tool for generating tagged sentences from JSGF grammars
Java
14
star
13

voice2json-profiles

Speech models and artifacts for voice2json
Python
11
star
14

jsgf2fst

Python
9
star
15

pt-br_pocketsphinx-cmu

Portuguese voice2json profile based on Pocketsphinx
Python
7
star
16

zh-cn_pocketsphinx-cmu

Mandarin voice2json profile based on Pocketsphinx
Python
7
star
17

homeassistant-pipeline

Websocket client for Assist audio pipeline
Python
7
star
18

en-us_deepspeech-mozilla

U.S. English profile for Mozilla DeepSpeech
Python
7
star
19

openwakeword-satellite

Basic satellite for Home Assistant running openWakeWord locally
Python
6
star
20

ru_pocketsphinx-cmu

Russian voice2json profile based on Pocketsphinx
Python
6
star
21

eyecode-tools

A collection of tools for analyzing data from my eyeCode experiment
Python
5
star
22

novice

Special Python image submodule for beginners
Python
5
star
23

en-us_kaldi-zamia

U.S. English voice2json profile based on Kaldi
Python
5
star
24

en-us_pocketsphinx-cmu

U.S. English voice2json profile based on Pocketsphinx
Python
5
star
25

de_deepspeech-aashishag

German profile using Mozilla's DeepSpeech and Aashishag Model
Python
5
star
26

el-gr_pocketsphinx-cmu

Greek voice2json profile based on Pocketsphinx
Python
5
star
27

mnemofy

Python utility to convert between words and mnemonic numbers
Python
4
star
28

rhasspy-profiles

Language-specific profiles for Rhasspy Hass.io add-on
Makefile
3
star
29

motion-sensor

Wakes/sleeps a Raspberry Pi display using a PIR sensor
Python
3
star
30

pl_julius-github

Polish voice2json profile based on Julius
Python
3
star
31

de_kaldi-zamia

German voice2json profile based on Kaldi
Python
3
star
32

wav-chunk

Read or write INFO chunks in WAV files
Python
3
star
33

artwork

Some of my art (for some definition of art)
Makefile
3
star
34

fr_kaldi-guyot

French profile for voice2json using Kaldi with Paul Guyot's TDN 250 model
Python
3
star
35

docker-deepvoice3

DeepVoice3 web server with pre-trained English models
Python
2
star
36

rhasspy-asr-kaldi

Automated speech recognition library for Rhasspy using Kaldi
Shell
2
star
37

pt-synesthesiam

CMU Sphinx acoustic model for Portugese (pt-br)
Jupyter Notebook
2
star
38

word2phonemes

Grapheme to phoneme guesser using PyTorch
Python
2
star
39

vi_kaldi-montreal

Vietnamese voice2json profile based on Kaldi
Python
2
star
40

epub3-marytts

MaryTTS voice project builder for pre-aligned EPUB 3 audio e-books
Python
2
star
41

esphome-nabu

C++
2
star
42

nexus

A collection of Cognitive Science experimental games
C#
2
star
43

hi_pocketsphinx-cmu

Hindi voice2json profile based on Pocketsphinx
Python
1
star
44

mycroft-precise-trainer

Text to speech wake word training scripts for Mycroft Precise
Python
1
star
45

sv_kaldi-montreal

Swedish voice2json profile based on Kaldi
Python
1
star
46

public-domain-sounds

Compressed WAV files from Public Domain Sounds
1
star
47

de_pocketsphinx-cmu

German voice2json profile based on Pocketsphinx
Python
1
star
48

pocketsphinx-python

Version of Python Pocketsphinx without sound
Python
1
star
49

es_pocketsphinx-cmu

Spanish voice2json profile based on Pocketsphinx
Python
1
star
50

2014-03-10-uva

Software Carpentry repository for University of Virginia bootcamp
Python
1
star
51

lutz

C++ library to compute Lutz complexity of a graph
C++
1
star
52

coqui-tts-tests

Test sound files for Coqui TTS
HTML
1
star
53

marytts-txt2wav

Command-line utility for text to speech with MaryTTS
Java
1
star
54

nl_kaldi-cgn

Voice2json profile for Dutch based on Kaldi CGN model
Python
1
star
55

rhasspy-nlu

Intent recognition library for Rhasspy
Python
1
star
56

kaldi-docker

Dockerizing a sub-set of Kaldi
Dockerfile
1
star
57

ko-kr_kaldi-montreal

Korean voice2json profile based on Kaldi
Python
1
star
58

ca-es_pocketsphinx-cmu

Catalan voice2json profile based on Pocketsphinx
Python
1
star
59

spatial_entropy

Computes an entropy profile for an image using moving averages
Python
1
star
60

kz_pocketsphinx-cmu

Kazakh voice2json profile based on Pocketsphinx
Python
1
star
61

wav-decoder

Basic WAV file decoder in C++
C++
1
star