mirror of
https://github.com/aljazceru/addons.git
synced 2025-12-17 13:14:21 +01:00
WIP: Snips (#138)
* Initial commit snips * Update config.json * Update config.json * Update run.sh * Create mosquitto.conf * Update mosquitto.conf * Update run.sh * Update Dockerfile * Update run.sh * Update run.sh * finish it * fix spell * fix lint * Update config.json * Update config.json * Update run.sh * fix link * Update config.json * fix copy * map share into * fix unzip * fix run * fix port * fix shell
This commit is contained in:
11
snips/Dockerfile
Normal file
11
snips/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
#armhf:FROM snipsdocker/platform:arm-0.4.3
|
||||
#amd64:FROM snipsdocker/platform:x86-0.4.3
|
||||
|
||||
# Copy data
|
||||
COPY run.sh /
|
||||
COPY mosquitto.conf /etc/
|
||||
COPY asoundrc /root/.asoundrc
|
||||
|
||||
RUN chmod a+x /run.sh
|
||||
|
||||
ENTRYPOINT [ "/run.sh" ]
|
||||
17
snips/asoundrc
Normal file
17
snips/asoundrc
Normal file
@@ -0,0 +1,17 @@
|
||||
pcm.!default {
|
||||
type asym
|
||||
capture.pcm "mic"
|
||||
playback.pcm "speaker"
|
||||
}
|
||||
pcm.mic {
|
||||
type plug
|
||||
slave {
|
||||
pcm "hw:%%MIC%%"
|
||||
}
|
||||
}
|
||||
pcm.speaker {
|
||||
type plug
|
||||
slave {
|
||||
pcm "hw:%%SPEAKER%%"
|
||||
}
|
||||
}
|
||||
40
snips/config.json
Normal file
40
snips/config.json
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "Snips.AI",
|
||||
"version": "0.4.3",
|
||||
"slug": "snips",
|
||||
"description": "The first on-device voice platform",
|
||||
"url": "https://home-assistant.io/addons/snips/",
|
||||
"startup": "application",
|
||||
"boot": "auto",
|
||||
"arch": ["armhf", "amd64"],
|
||||
"ports": {
|
||||
"1883/tcp": 9898
|
||||
},
|
||||
"map": ["share"],
|
||||
"devices": ["/dev/snd:/dev/snd:rwm"],
|
||||
"options": {
|
||||
"mqtt_bridge": {
|
||||
"active": true,
|
||||
"host": "172.17.0.1",
|
||||
"port": 1883,
|
||||
"user": "",
|
||||
"password": ""
|
||||
},
|
||||
"mic": "0,0",
|
||||
"speaker": "1,0",
|
||||
"assistant": "assistant.zip"
|
||||
},
|
||||
"schema": {
|
||||
"mqtt_bridge": {
|
||||
"active": "bool",
|
||||
"host": "str",
|
||||
"port": "port",
|
||||
"user": "str",
|
||||
"password": "str"
|
||||
},
|
||||
"mic": "str",
|
||||
"speaker": "str",
|
||||
"assistant": "str"
|
||||
},
|
||||
"image": "homeassistant/{arch}-addon-snips"
|
||||
}
|
||||
13
snips/mosquitto.conf
Normal file
13
snips/mosquitto.conf
Normal file
@@ -0,0 +1,13 @@
|
||||
##
|
||||
# defaults
|
||||
listener 1883
|
||||
user root
|
||||
|
||||
##
|
||||
# logging
|
||||
log_dest stdout
|
||||
|
||||
##
|
||||
# datastore
|
||||
persistence true
|
||||
persistence_location /data/
|
||||
56
snips/run.sh
Normal file
56
snips/run.sh
Normal file
@@ -0,0 +1,56 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
CONFIG_PATH=/data/options.json
|
||||
SNIPS_CONFIG=/data/config
|
||||
|
||||
MQTT_BRIDGE=$(jq --raw-output '.mqtt_bridge.active' $CONFIG_PATH)
|
||||
ASSISTANT=$(jq --raw-output '.assistant' $CONFIG_PATH)
|
||||
SPEAKER=$(jq --raw-output '.speaker' $CONFIG_PATH)
|
||||
MIC=$(jq --raw-output '.mic' $CONFIG_PATH)
|
||||
|
||||
echo "[Info] Show audio device"
|
||||
aplay -l
|
||||
|
||||
echo "[Info] Setup audio device"
|
||||
sed -i "s/%%SPEAKER%%/$SPEAKER/g" /root/.asoundrc
|
||||
sed -i "s/%%MIC%%/$MIC/g" /root/.asoundrc
|
||||
|
||||
# mqtt bridge
|
||||
if [ "$MQTT_BRIDGE" == "true" ]; then
|
||||
HOST=$(jq --raw-output '.mqtt_bridge.host' $CONFIG_PATH)
|
||||
PORT=$(jq --raw-output '.mqtt_bridge.port' $CONFIG_PATH)
|
||||
USER=$(jq --raw-output '.mqtt_bridge.user' $CONFIG_PATH)
|
||||
PASSWORD=$(jq --raw-output '.mqtt_bridge.password' $CONFIG_PATH)
|
||||
|
||||
echo "[Info] Setup internal mqtt bridge"
|
||||
|
||||
{
|
||||
echo "connection main-mqtt"
|
||||
echo "address $HOST:$PORT"
|
||||
} >> /etc/mosquitto.conf
|
||||
|
||||
if [ ! -z "$USER" ]; then
|
||||
{
|
||||
echo "username $USER"
|
||||
echo "password $PASSWORD"
|
||||
} >> /etc/mosquitto.conf
|
||||
fi
|
||||
|
||||
echo "topic # OUT" >> /etc/mosquitto.conf
|
||||
fi
|
||||
|
||||
echo "[Info] Start internal mqtt broaker"
|
||||
mosquitto -c /etc/mosquitto.conf &
|
||||
|
||||
# init snips config
|
||||
mkdir -p "$SNIPS_CONFIG"
|
||||
ln -s "$SNIPS_CONFIG/" "/opt/snips/config"
|
||||
|
||||
# check if a new assistant file exists
|
||||
if [ -f "/share/$ASSISTANT" ]; then
|
||||
echo "[Info] Install/Update snips assistant"
|
||||
unzip -u "/share/$ASSISTANT" -d "$SNIPS_CONFIG"
|
||||
fi
|
||||
|
||||
/opt/snips/snips-entrypoint.sh --mqtt localhost:1883
|
||||
Reference in New Issue
Block a user