From b045a9cea6ecb1c6eee81cf7374d0c032f0e673e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Forslund?= Date: Tue, 7 Apr 2020 11:59:05 +0200 Subject: [PATCH 1/4] Add snapcraft packaging recipe Also adds a SNAPCRAFT.md with some info of the specifics of the snap --- SNAPCRAFT.md | 29 ++++++++++ snap/snapcraft.yaml | 130 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 SNAPCRAFT.md create mode 100644 snap/snapcraft.yaml diff --git a/SNAPCRAFT.md b/SNAPCRAFT.md new file mode 100644 index 0000000..6a122ba --- /dev/null +++ b/SNAPCRAFT.md @@ -0,0 +1,29 @@ +# Mycroft-Precise Snap package + +## Package details + +The package is farily standard package using the Snap [Python Plugin](https://snapcraft.io/docs/python-plugin). + +The package version is extracted from the setup.py script to remain consistent with the pip information. In addition a comparison with the repo is made to see if this is commit matches the latest release commit, if it doesn't match _-dev_ is applied to the version info. + +Since Precise uses pyaudio, ALSA is required for things to work. This requires the [alsa-mixin](https://snapcraft-alsa.readthedocs.io/en/latest/snapcraft_usage.html) and results in some minor issues that needs to be handled. Library conflicts may occur if audio packages are included as part of the main application part, making them appear twice in conflicting versions. This is the reason that libportaudio2 and pulseaudio are in the stage-packages for the alsa-mixin part. + +## Plugs +Plugs allows connecting the snap to the rest of the system, without any specified plugs the application will run without being able to access the system outside of the snap container, a read-only file system dedicated to the application. + +**Plugs used:** +- home: access to the user's home directory (excluding hidden files) +- audio-record: Access to the system's audio input devices +- audio-playback: Access to the system's audio output devices + +## Entry points +Below are some of the entry-points of interest. + +- mycroft-precise +Alias for the mycroft-precise.engine, run precise against a data stream over stdio. + +- mycroft-precise.listen +Run a model on microphone audio input. + +- mycroft-precise.train +Train a new model on a dataset. diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 0000000..00c6612 --- /dev/null +++ b/snap/snapcraft.yaml @@ -0,0 +1,130 @@ +name: mycroft-precise +adopt-info: mycroft-precise +summary: Mycroft Precise +description: Mycroft Precise, a wake word spotter. +base: core18 +grade: stable +confinement: strict +build-packages: [python3-dev, python3-setuptools, libtool, libffi-dev, libssl-dev, autoconf, build-essential] +parts: + alsa-mixin: + build-packages: + - libasound2-dev + plugin: dump + source: https://github.com/diddlesnaps/snapcraft-alsa.git + source-subdir: snapcraft-assets + stage-packages: + - libslang2 + - libasound2 + - libasound2-plugins + - libportaudio2 + - pulseaudio + - alsa-utils + mycroft-precise: + after: [alsa-mixin] + plugin: python + python-version: python3 + source: https://github.com/MycroftAI/mycroft-precise.git + source-type: git + source-branch: dev + override-pull: | + snapcraftctl pull + # Set version to setup.py version if current commit is the latest + # tag, otherwise append "-dev" to the version string. + set +e + if [[ git describe --exact-match --tags $(git log -n1 --pretty='%h') ]] + then + VERSION=$(/usr/bin/python3 setup.py --version) + else + VERSION="$(/usr/bin/python3 setup.py --version)-dev" + fi + set -e + snapcraftctl set-version $VERSION + build-packages: + - python-setuptools + - python3-pip + - curl + - libopenblas-dev + - python3-scipy + - cython + - libhdf5-dev + - python3-h5py + - portaudio19-dev + - swig + - libatlas-base-dev + stage-packages: + - libopenblas-base + - python3 + - python3-scipy + - cython + - libhdf5-100 + - libhdf5-cpp-100 + - python3-h5py + - swig + - libatlas3-base + +layout: + /usr/lib/$SNAPCRAFT_ARCH_TRIPLET/alsa-lib: + bind: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/alsa-lib + +apps: + mycroft-precise: + plugs: [home] + command: bin/precise-engine + add-noise: + plugs: [home] + command: bin/precise-add-noise + calc-threshold: + plugs: [home] + command: bin/precise-calc-threshold + collect: + plugs: [home, audio-record, audio-playback] + command-chain: + - snap/command-chain/alsa-launch + command: bin/precise-collect + convert: + plugs: [home] + command: bin/precise-convert + eval: + plugs: [home] + command: bin/precise-eval + engine: + plugs: [home] + command: bin/precise-engine + graph: + plugs: [home] + command: bin/precise-graph + listen: + command-chain: + - snap/command-chain/alsa-launch + plugs: [home, audio-record, audio-playback] + command: bin/precise-listen + listen-pocketsphinx: + command-chain: + - snap/command-chain/alsa-launch + plugs: [home, audio-record, audio-playback] + command: bin/precise-listen-pocketsphinx + simulate: + plugs: [home] + command: bin/precise-simulate + test: + plugs: [home] + command: bin/precise-test + test-pocketsphinx: + plugs: [home] + command: bin/precise-test-pocketsphinx + train: + plugs: [home] + command: bin/precise-train + train-generated: + plugs: [home] + command: bin/precise-train-generated + train-incremental: + plugs: [home] + command: bin/precise-train-incremental + train-optimize: + plugs: [home] + command: bin/precise-train-optimize + train-sampled: + plugs: [home] + command: bin/precise-train-sampled From 89fc7b9dd9855f81f6c668b1554fb840ed157707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Forslund?= Date: Tue, 14 Apr 2020 09:52:28 +0200 Subject: [PATCH 2/4] Add hey-mycroft model to snap --- SNAPCRAFT.md | 2 ++ snap/snapcraft.yaml | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/SNAPCRAFT.md b/SNAPCRAFT.md index 6a122ba..1772f7a 100644 --- a/SNAPCRAFT.md +++ b/SNAPCRAFT.md @@ -8,6 +8,8 @@ The package version is extracted from the setup.py script to remain consistent w Since Precise uses pyaudio, ALSA is required for things to work. This requires the [alsa-mixin](https://snapcraft-alsa.readthedocs.io/en/latest/snapcraft_usage.html) and results in some minor issues that needs to be handled. Library conflicts may occur if audio packages are included as part of the main application part, making them appear twice in conflicting versions. This is the reason that libportaudio2 and pulseaudio are in the stage-packages for the alsa-mixin part. +The snap package also includes a the current pretrained "hey mycroft" model accessed through `/snap/mycroft-precise/current/hey-mycroft/hey-mycroft.pb` + ## Plugs Plugs allows connecting the snap to the rest of the system, without any specified plugs the application will run without being able to access the system outside of the snap container, a read-only file system dedicated to the application. diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 00c6612..6c46fc0 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -62,6 +62,12 @@ parts: - python3-h5py - swig - libatlas3-base + hey-mycroft: + plugin: dump + source: https://github.com/MycroftAI/precise-data/raw/models/hey-mycroft.tar.gz + source-type: tar + organize: + '*': /hey-mycroft/ layout: /usr/lib/$SNAPCRAFT_ARCH_TRIPLET/alsa-lib: From 475fa5629440c33f3348bd4a3415d9959350acb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Forslund?= Date: Tue, 14 Apr 2020 15:52:20 +0200 Subject: [PATCH 3/4] Update SNAPCRAFT.md wording --- SNAPCRAFT.md | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/SNAPCRAFT.md b/SNAPCRAFT.md index 1772f7a..29a574b 100644 --- a/SNAPCRAFT.md +++ b/SNAPCRAFT.md @@ -1,31 +1,18 @@ # Mycroft-Precise Snap package ## Package details +The package is a fairly standard configuration using the Snap [Python Plugin](https://snapcraft.io/docs/python-plugin). -The package is farily standard package using the Snap [Python Plugin](https://snapcraft.io/docs/python-plugin). +The package version is extracted from the `setup.py` script to remain consistent with the pip information. In addition a comparison with the repo is made to see if this commit matches the latest release commit. If it doesn't match _-dev_ is appended to the version info. -The package version is extracted from the setup.py script to remain consistent with the pip information. In addition a comparison with the repo is made to see if this is commit matches the latest release commit, if it doesn't match _-dev_ is applied to the version info. +Since Precise uses pyaudio, ALSA is required for the audio to work. This Snap uses the [alsa-mixin](https://snapcraft-alsa.readthedocs.io/en/latest/snapcraft_usage.html) to setup the ALSA components. This results in some minor issues that need to be handled. Library conflicts may occur if audio packages are included as part of the main application part, making them appear twice in conflicting versions. This is the reason that libportaudio2 and pulseaudio are in the stage-packages for the alsa-mixin part. -Since Precise uses pyaudio, ALSA is required for things to work. This requires the [alsa-mixin](https://snapcraft-alsa.readthedocs.io/en/latest/snapcraft_usage.html) and results in some minor issues that needs to be handled. Library conflicts may occur if audio packages are included as part of the main application part, making them appear twice in conflicting versions. This is the reason that libportaudio2 and pulseaudio are in the stage-packages for the alsa-mixin part. - -The snap package also includes a the current pretrained "hey mycroft" model accessed through `/snap/mycroft-precise/current/hey-mycroft/hey-mycroft.pb` +This package also includes the current pretrained "hey mycroft" model accessed through `/snap/mycroft-precise/current/hey-mycroft/hey-mycroft.pb`. ## Plugs -Plugs allows connecting the snap to the rest of the system, without any specified plugs the application will run without being able to access the system outside of the snap container, a read-only file system dedicated to the application. +Plugs allow the Snap to connect to specific aspects of the host system. Without any specified plugs the application will run entirely within a read-only file system dedicated to the application. It will not be able to access the system, including audio devices, that are outside of the Snap container. **Plugs used:** - home: access to the user's home directory (excluding hidden files) - audio-record: Access to the system's audio input devices - audio-playback: Access to the system's audio output devices - -## Entry points -Below are some of the entry-points of interest. - -- mycroft-precise -Alias for the mycroft-precise.engine, run precise against a data stream over stdio. - -- mycroft-precise.listen -Run a model on microphone audio input. - -- mycroft-precise.train -Train a new model on a dataset. From dd0fff52ce9d2fda0eb8e16dee9866e487a4cd01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Forslund?= Date: Tue, 14 Apr 2020 20:27:37 +0200 Subject: [PATCH 4/4] Add proper global meta data This is heavily based upon a draft by Kris Gesling, any errors are of course my own. --- snap/snapcraft.yaml | 50 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 6c46fc0..4470b84 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,7 +1,53 @@ name: mycroft-precise adopt-info: mycroft-precise -summary: Mycroft Precise -description: Mycroft Precise, a wake word spotter. +license: Apache-2.0 +summary: A wake word listener from Mycroft AI +description: > + A lightweight, simple-to-use, RNN wake word listener, including all the tools to train your own custom wake word. + + Mycroft Precise monitors an audio stream (usually a microphone) and when it recognizes a specific phrase it triggers an event. For example, by default users of the Mycroft Voice Assistant are using a Precise model trained to spot the phrase "Hey Mycroft". When Precise recognizes this phrase it puts the Mycroft Voice Assistant into command mode performing speech recognition on whatever is next said by the person using the device. + + Mycroft Precise is fully open source and can be trained to recognize any short-phrase or sound, from a name to a cough. + + The default "Hey Mycroft" model is included, to test it, try: + `mycroft-precise.listen /snap/mycroft-precise/current/hey-mycroft/hey-mycroft.pb` + + + **USAGE** + + + Running the listener + + mycroft-precise - Alias for mycroft-precise.engine + mycroft-precise.engine - Run a model on raw audio data from stdin + mycroft-precise.listen - Run a model on microphone audio input + mycroft-precise.listen-pocketsphinx - Run the PocketSphinx listener + + Data collection + + mycroft-precise.collect - Record audio samples for use with Precise + mycroft-precise.add-noise - Create a duplicate dataset with added noise + + Training + + mycroft-precise.train - Train a new model on a dataset + mycroft-precise.train-generated - Train a model on infinitely generated batches + mycroft-precise.train-incremental - Train a model to inhibit activation by marking false activations and retraining + mycroft-precise.train-optimize - Use black box optimization to tune model hyperparameters + mycroft-precise.train-sampled - Train a model, sampling data points with the highest loss from a larger dataset + + Evaluation and analysis + + mycroft-precise.test - Test a model against a dataset + mycroft-precise.test-pocketsphinx - Test PocketSphinx against a dataset + mycroft-precise.eval - Evaluate a list of models on a dataset + mycroft-precise.calc-threshold - Update the threshold values of a model for a dataset to make the sensitivity more accurate and linear + mycroft-precise.graph - Show ROC curves for a series of models + mycroft-precise.simulate - Simulate listening to long chunks of audio to find unbiased false positive metrics + + Model conversion + + mycroft-precise.convert - Convert wake-word model from Keras to TensorFlow base: core18 grade: stable confinement: strict