-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6fc7eaa
Showing
28 changed files
with
750 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[run] | ||
omit = | ||
# Virtual environment | ||
.venv/* | ||
# Tests | ||
tests/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
name: Tests | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-18.04, macos-latest] | ||
python-version: [3.7, 3.8] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v1 | ||
- name: Install dependencies on macOS | ||
if: startsWith(matrix.os, 'macos') | ||
run: | | ||
brew install fakeroot dpkg coreutils | ||
brew link --force gettext | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install Python dependencies | ||
run: make venv | ||
- name: Check code | ||
run: make check | ||
- name: Test code | ||
run: make test | ||
- name: Make package | ||
run: make dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
__pycache__/ | ||
.mypy_cache/ | ||
.coverage | ||
coverage.xml | ||
.venv/ | ||
dist/ | ||
*.egg-info/ | ||
.vscode/ | ||
debian/rhasspy-hermes* | ||
pyinstaller/ | ||
download/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[settings] | ||
multi_line_output=3 | ||
include_trailing_comma=True | ||
force_grid_wrap=0 | ||
use_parentheses=True | ||
line_length=88 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
extends: default | ||
|
||
ignore: | | ||
.venv/ | ||
src/ | ||
rules: | ||
line-length: disable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Koen Vervloesem | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include requirements.txt | ||
include README.md | ||
include VERSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
SHELL := bash | ||
PACKAGE_NAME = $(shell basename "$$PWD") | ||
PYTHON_NAME = $(shell echo "$(PACKAGE_NAME)" | sed -e 's/-//' | sed -e 's/-/_/g') | ||
PYTHON_FILES = $(PYTHON_NAME)/*.py tests/*.py setup.py | ||
SHELL_FILES = bin/* debian/bin/* | ||
PIP_INSTALL ?= install | ||
|
||
.PHONY: reformat check dist venv test pyinstaller debian deploy | ||
|
||
version := $(shell cat VERSION) | ||
architecture := $(shell dpkg-architecture | grep DEB_BUILD_ARCH= | sed 's/[^=]\+=//') | ||
|
||
all: venv | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Python | ||
# ----------------------------------------------------------------------------- | ||
|
||
reformat: | ||
scripts/format-code.sh $(PYTHON_FILES) | ||
|
||
check: | ||
scripts/check-code.sh $(PYTHON_FILES) | ||
|
||
venv: | ||
scripts/create-venv.sh | ||
|
||
dist: sdist | ||
|
||
sdist: | ||
python3 setup.py sdist | ||
|
||
test: | ||
scripts/run-tests.sh $(PYTHON_NAME) | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Docker | ||
# ----------------------------------------------------------------------------- | ||
|
||
docker: pyinstaller | ||
docker build . -t "rhasspy/$(PACKAGE_NAME):$(version)" -t "rhasspy/$(PACKAGE_NAME):latest" | ||
|
||
deploy: | ||
echo "$$DOCKER_PASSWORD" | docker login -u "$$DOCKER_USERNAME" --password-stdin | ||
docker push "rhasspy/$(PACKAGE_NAME):$(version)" | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Debian | ||
# ----------------------------------------------------------------------------- | ||
|
||
pyinstaller: | ||
scripts/build-pyinstaller.sh "${architecture}" "${version}" | ||
|
||
debian: | ||
scripts/build-debian.sh "${architecture}" "${version}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Rhasspy Hermes App library | ||
|
||
[](https://github.com/rhasspy/rhasspy-hermes-app/actions) | ||
[](https://pypi.org/project/rhasspy-hermes-app) | ||
[](https://www.python.org) | ||
[](https://github.com/rhasspy/rhasspy-hermes-app/blob/master/LICENSE) | ||
|
||
Helper library to create voice apps for [Rhasspy](https://rhasspy.readthedocs.io/) in Python using the [Hermes protocol](https://docs.snips.ai/reference/hermes). | ||
|
||
Warning: Rhasspy Hermes App is currently alpha software, in a very early stage of its development. Anything may change at any time. The public API should not be considered stable. Consider this as a prototype. | ||
|
||
## Rationale | ||
|
||
[Rhasspy Hermes](https://github.com/rhasspy/rhasspy-hermes/) is an extensive library implementing Hermes protocol support in Rhasspy. It implements a lot of the low-level details such as MQTT communication and converting JSON payloads and binary payloads to more usable Python classes. Thanks to the [HermesClient](https://github.com/rhasspy/rhasspy-hermes/blob/master/rhasspyhermes/client.py) class and the [cli](https://github.com/rhasspy/rhasspy-hermes/blob/master/rhasspyhermes/cli.py) module, you can easily implement a Rhasspy 'app'. | ||
|
||
However, the result [still needs a lot of lines of code](time_app_direct.py). If you want to have control over the finer details of the Rhasspy Hermes library, this is fine. But if you just want to create a simple voice app that tells you the time, it should be easier. This is where the Rhasspy Hermes App library comes in. Its lets you write code such as [the following](time_app.py): | ||
|
||
```python | ||
from datetime import datetime | ||
import logging | ||
|
||
from rhasspyhermes_app import HermesApp | ||
|
||
_LOGGER = logging.getLogger("TimeApp") | ||
|
||
app = HermesApp("TimeApp") | ||
|
||
|
||
@app.on_intent("GetTime") | ||
def get_time(intent): | ||
now = datetime.now().strftime("%H %M") | ||
return app.EndSession(f"It's {now}") | ||
|
||
|
||
app.run() | ||
``` | ||
|
||
Ignoring the import lines and the logger, what this code does is: | ||
|
||
* creating a `HermesApp` object; | ||
* defining a function `get_time` that ends a session by telling the time; | ||
* running the app. | ||
|
||
By applying the app's `on_intent` decorator to the function, this function will get executed when the app receives a "GetTime" intent. | ||
|
||
In fact, the code [using Rhasspy Hermes directly](time_app_direct.py) and the one [using Rhasspy Hermes App](time_app.py) are doing exactly the same. Thanks to the extra abstraction layer of the Rhasspy Hermes App library, a few lines of code are enough to start a whole machinery behind the scenes. | ||
|
||
Try the example app [time_app.py](time_app.py) with the `--help` flag to see what settings you can use to start the app (mostly connection settings for the MQTT broker): | ||
|
||
``` | ||
python3 time_app.py --help | ||
``` | ||
|
||
## TODO list | ||
|
||
* Add `ContinueSession` support. | ||
* Add decorators to react to other Hermes messages. | ||
* Improve mypy coverage. | ||
* Write tests. | ||
* Write Documentation. | ||
* Release an installable Python package on PyPI when the API has been stabilised. | ||
* Let the app load its intents/slots/… from a file and re-train Rhasspy on installation/startup of the app. | ||
* Make multi-language apps possible, so the app developer can define example sentences in multiple languages and the app uses the language from your Rhasspy setup's profile. | ||
|
||
## License | ||
|
||
This project is provided by [Koen Vervloesem](mailto:[email protected]) as open source software with the MIT license. See the LICENSE file for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[mypy] | ||
|
||
[mypy-paho.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-setuptools.*] | ||
ignore_missing_imports = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[MESSAGES CONTROL] | ||
disable= | ||
format, | ||
abstract-class-little-used, | ||
abstract-method, | ||
cyclic-import, | ||
duplicate-code, | ||
global-statement, | ||
import-outside-toplevel, | ||
inconsistent-return-statements, | ||
locally-disabled, | ||
not-context-manager, | ||
redefined-variable-type, | ||
too-few-public-methods, | ||
too-many-arguments, | ||
too-many-branches, | ||
too-many-instance-attributes, | ||
too-many-lines, | ||
too-many-locals, | ||
too-many-public-methods, | ||
too-many-return-statements, | ||
too-many-statements, | ||
too-many-boolean-expressions, | ||
unnecessary-pass, | ||
unused-argument, | ||
broad-except, | ||
too-many-nested-blocks, | ||
invalid-name, | ||
too-few-public-methods, | ||
cell-var-from-loop | ||
|
||
[FORMAT] | ||
expected-line-ending-format=LF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
testpaths = tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rhasspy-hermes==0.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
black==19.10b0 | ||
coverage==5.0.4 | ||
flake8==3.7.9 | ||
mypy==0.770 | ||
pyinstaller==3.6 | ||
pylint==2.4.4 | ||
pytest==5.4.1 | ||
pytest-cov==2.8.1 | ||
yamllint==1.21.0 |
Oops, something went wrong.