Psychokiller1888 / snips-custom-hotword

Using Snowboy to customize the snips hotword
GNU General Public License v3.0
21 stars 5 forks source link

Snowboy service conflicting with snips-audio-server #3

Open bzhmaddog opened 6 years ago

bzhmaddog commented 6 years ago

When the service is started before or too soon after snips-audio-server.service the audio server won't start correctly (Audio Server won't be able to use the default input

Question : Isn't there a way to listen to the audio frame like snips-hotword do ? instead of capturing the microphone to recore what was already recorded by the audio server ?

Wordkaround : Start the hotword service only after the audio server is fully started (meaning it start sending topic audioFrame to the mqtt bus)

Ex:

snips-hotword-loader.service

[Unit] Description=Snips Snowboy Hotword loader After=mosquitto.service Before=snips-audio-server.service [Service] Type=oneshot ExecStart=/usr/bin/hotword-loader.sh WorkingDirectory=/lib/snips-hotword-snowboy/ RemainAfterExit=true StandardOutput=journal [Install] WantedBy=multi-user.target

hotword-loader.sh

!/bin/sh

bash -c "/usr/bin/env python /lib/snips-hotword-snowboy/wait4asr.py &"

wait4asr.py

!/usr/bin/env python

-- coding: utf-8 --

import sys import paho.mqtt.client as mqtt import pytoml from pydbus import SystemBus

def on_connect(client, userdata, flags, rc): print("Connected to MQTT Bus [Wait4ASR]") client.subscribe("hermes/audioServer/#")

def on_frame(client, userdata, msg): print("Audio frame received [Wait4ASR]") bus = SystemBus() systemd = bus.get(".systemd1") job = systemd.StartUnit('snips-hotword-snowboy.service', 'fail') client.disconnect() sys.exit()

Read MQTT connection info from the central snips config.

snips_config = pytoml.loads(open("/etc/snips.toml").read())

Get MQTT bus parameters

mqtt_host, mqtt_port = snips_config["snips-common"]["mqtt"].split(":") mqtt_port = int(mqtt_port)

Build MQTT Client

client = mqtt.Client()

Set on connect callback

client.on_connect = on_connect

MQTT Topics callbacks

client.message_callback_add("hermes/audioServer/#", on_frame)

Connect to MQTT bus

client.connect(mqtt_host, mqtt_port, 60)

Wait for messages

client.loop_forever()

Psychokiller1888 commented 6 years ago

Sure everything is doable :) I'm not using snowboy atm, feel free to PR if you done it

daniele-athome commented 5 years ago

Sure everything is doable :) I'm not using snowboy atm, feel free to PR if you done it

Out of curiosity, may I ask what hotword detection are you using now? Snips' one? Why abandon Snowboy?

Psychokiller1888 commented 5 years ago

Snips personal wakeword and snips universal wakeword also. I chose the personal wakeword road because it allows user identification at the same time