Skip to content

Commit

Permalink
Initial version of porcupine1
Browse files Browse the repository at this point in the history
  • Loading branch information
synesthesiam committed Sep 28, 2023
1 parent f786bc8 commit ceda62d
Show file tree
Hide file tree
Showing 84 changed files with 469 additions and 0 deletions.
16 changes: 16 additions & 0 deletions porcupine1/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Changelog

## 1.5.0

- Remove webrtc (done in core now)
- Remove audio options related to webrtc
- Remove wake word option (dynamic loading)
- Dynamically load wake word models

## 1.4.0

- Add noise suppression/auto gain with webrtc

## 1.1.0

- Initial release
50 changes: 50 additions & 0 deletions porcupine1/DOCS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Home Assistant Add-on: porcupine1

## Installation

Follow these steps to get the add-on installed on your system:

1. Navigate in your Home Assistant frontend to **Settings** -> **Add-ons** -> **Add-on store**.
2. Add the store https://github.com/rhasspy/hassio-addons
2. Find the "porcupine1" add-on and click it.
3. Click on the "INSTALL" button.

## How to use

After this add-on is installed and running, it will be automatically discovered
by the Wyoming integration in Home Assistant. To finish the setup,
click the following my button:

[![Open your Home Assistant instance and start setting up a new integration.](https://my.home-assistant.io/badges/config_flow_start.svg)](https://my.home-assistant.io/redirect/config_flow_start/?domain=wyoming)

Alternatively, you can install the Wyoming integration manually, see the
[Wyoming integration documentation](https://www.home-assistant.io/integrations/wyoming/)
for more information.

## Configuration

### Option: `sensitivity`

Activation threshold (0-1), where higher means fewer activations.

### Option: `debug_logging`

Enable debug logging. Useful for seeing satellite connections and each wake word detection in the logs.

## Support

Got questions?

You have several options to get them answered:

- The [Home Assistant Discord Chat Server][discord].
- The Home Assistant [Community Forum][forum].
- Join the [Reddit subreddit][reddit] in [/r/homeassistant][reddit]

In case you've found an bug, please [open an issue on our GitHub][issue].

[discord]: https://discord.gg/c5DvZ4e
[forum]: https://community.home-assistant.io
[issue]: https://github.com/home-assistant/addons/issues
[reddit]: https://reddit.com/r/homeassistant
[repository]: https://github.com/hassio-addons/repository
37 changes: 37 additions & 0 deletions porcupine1/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ARG BUILD_FROM
FROM ${BUILD_FROM}

# Set shell
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Install porcupine1
WORKDIR /usr/src
ENV PIP_BREAK_SYSTEM_PACKAGES=1

COPY ./src/ ./

RUN \
apt-get update \
&& apt-get install -y --no-install-recommends \
netcat-traditional \
python3 \
python3-pip \
\
&& pip3 install --no-cache-dir -U \
setuptools \
wheel \
&& pip3 install --no-cache-dir \
--extra-index-url https://www.piwheels.org/simple \
'numpy<1.26' \
-r requirements.txt \
\
&& rm -rf /var/lib/apt/lists/*

WORKDIR /
COPY rootfs /

HEALTHCHECK --start-period=10m \
CMD echo '{ "type": "describe" }' \
| nc -w 1 localhost 10400 \
| grep -iq "porcupine1" \
|| exit 1
15 changes: 15 additions & 0 deletions porcupine1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Home Assistant Add-on: porcupine1

![Supports aarch64 Architecture][aarch64-shield] ![Supports amd64 Architecture][amd64-shield] ![Supports armv7 Architecture][armv7-shield]

Home Assistant add-on that uses [porcupine1](https://github.com/Picovoice/porcupine) for wake word detection.

Part of the [Year of Voice](https://www.home-assistant.io/blog/2022/12/20/year-of-voice/).

Requires Home Assistant 2023.9 or later.

[aarch64-shield]: https://img.shields.io/badge/aarch64-yes-green.svg
[amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg
[armv7-shield]: https://img.shields.io/badge/armv7-yes-green.svg
[armhf-shield]: https://img.shields.io/badge/armhf-no-red.svg
[i386-shield]: https://img.shields.io/badge/i386-no-red.svg
7 changes: 7 additions & 0 deletions porcupine1/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
build_from:
amd64: ghcr.io/home-assistant/amd64-base-debian:bookworm
aarch64: ghcr.io/home-assistant/aarch64-base-debian:bookworm
codenotary:
signer: notary@home-assistant.io
base_image: notary@home-assistant.io
22 changes: 22 additions & 0 deletions porcupine1/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
version: 1.0.0
slug: porcupine1
name: porcupine1
description: porcupine1 using the Wyoming protocol
url: https://github.com/rhasspy/hassio-addons/tree/master/porcupine1
arch:
- amd64
- aarch64
- armv7
init: false
discovery:
- wyoming
options:
sensitivity: 0.5
debug_logging: false
schema:
sensitivity: float
debug_logging: bool
ports:
"10400/tcp": null
homeassistant: 2023.9.0
Empty file.
24 changes: 24 additions & 0 deletions porcupine1/rootfs/etc/s6-overlay/s6-rc.d/discovery/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Sends discovery information to Home Assistant.
# ==============================================================================
declare config

# Wait for porcupine1 to become available
bash -c \
"until
echo '{ \"type\": \"describe\" }'
> /dev/tcp/localhost/10400; do sleep 0.5;
done" > /dev/null 2>&1 || true;

config=$(\
bashio::var.json \
uri "tcp://$(hostname):10400" \
)

if bashio::discovery "wyoming" "${config}" > /dev/null; then
bashio::log.info "Successfully sent discovery information to Home Assistant."
else
bashio::log.error "Discovery message to Home Assistant failed!"
fi
1 change: 1 addition & 0 deletions porcupine1/rootfs/etc/s6-overlay/s6-rc.d/discovery/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions porcupine1/rootfs/etc/s6-overlay/s6-rc.d/discovery/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/discovery/run
Empty file.
26 changes: 26 additions & 0 deletions porcupine1/rootfs/etc/s6-overlay/s6-rc.d/porcupine1/finish
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Take down the S6 supervision tree when service fails
# s6-overlay docs: https://github.com/just-containers/s6-overlay
# ==============================================================================
declare exit_code
readonly exit_code_container=$(</run/s6-linux-init-container-results/exitcode)
readonly exit_code_service="${1}"
readonly exit_code_signal="${2}"

bashio::log.info \
"Service exited with code ${exit_code_service}" \
"(by signal ${exit_code_signal})"

if [[ "${exit_code_service}" -eq 256 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then
echo $((128 + $exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
fi
[[ "${exit_code_signal}" -eq 15 ]] && exec /run/s6/basedir/bin/halt
elif [[ "${exit_code_service}" -ne 0 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then
echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode
fi
exec /run/s6/basedir/bin/halt
fi
14 changes: 14 additions & 0 deletions porcupine1/rootfs/etc/s6-overlay/s6-rc.d/porcupine1/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Start porcupine1 service
# ==============================================================================
flags=()

if bashio::config.true 'debug_logging'; then
flags+=('--debug')
fi

exec python3 /usr/src/server.py \
--uri 'tcp://0.0.0.0:10400' \
--sensitivity "$(bashio::config 'sensitivity')" ${flags[@]}
1 change: 1 addition & 0 deletions porcupine1/rootfs/etc/s6-overlay/s6-rc.d/porcupine1/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions porcupine1/src/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pvporcupine~=1.9.0
wyoming==1.2.0
Loading

0 comments on commit ceda62d

Please sign in to comment.