Skip to content

Commit

Permalink
Using /share for persistance of snowboy/precise models
Browse files Browse the repository at this point in the history
  • Loading branch information
synesthesiam committed Feb 25, 2019
1 parent 204ab34 commit 0dc0dde
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
18 changes: 11 additions & 7 deletions mycroft-precise/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,35 @@
import json
from uuid import uuid4

from flask import Flask, request, send_file, render_template
from flask import Flask, request, send_file, render_template, safe_join

app = Flask('mycroft-precise', template_folder='.')
app.secret_key = str(uuid4())

config_path = os.environ.get('CONFIG_PATH', '/data/options.json')
model_path = os.environ.get('MODEL_PATH', '/models')
models_dir = os.environ.get('MODEL_PATH', '/share/precise')

@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
if 'delete' in request.form:
model_name = request.form['model']
os.unlink(os.path.join(model_path, model_name))
model_path = safe_join(models_dir, model_name)
if os.path.exists(model_path):
os.unlink(model_path)
elif 'file' in request.files:
file = request.files['file']
model_name = file.filename
file.save(os.path.join(model_path, model_name))
model_path = safe_join(models_dir, model_name)
os.makedirs(models_dir, exist_ok=True)
file.save(model_path)

with open(config_path, 'r') as config_file:
config = json.load(config_file)

models = []
if os.path.exists(model_path):
for model_name in os.listdir(model_path):
models.append(os.path.join(model_path, model_name))
if os.path.exists(models_dir):
for model_name in os.listdir(models_dir):
models.append(os.path.join(models_dir, model_name))

return render_template('index.html', config=config, models=models)
5 changes: 3 additions & 2 deletions mycroft-precise/config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "Mycroft Precise Wake System for Rhasspy",
"slug": "precise-rhasspy",
"version": "0.2.0-2",
"version": "0.2.0-3",
"description": "Mycroft Precise wake word detection (Mycroft.ai) for Rhasspy voice assistant",
"startup": "application",
"boot": "auto",
"map": ["share:rw"],
"options": {
"host": "localhost",
"port": 1883,
Expand All @@ -13,7 +14,7 @@
"reconnect": 5,
"site_id": "default",
"wakeword_id": "default",
"model": "/models/okay-rhasspy.pb",
"model": "/share/precise/okay-rhasspy.pb",
"sensitivity": 0.5,
"trigger_level": 3
},
Expand Down
2 changes: 1 addition & 1 deletion snowboy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Snowboy Wake Listener
=========================

Small service that listens for a wake word with [snowboy](https://snowboy.kitt.ai).
Audio data is streamed in from [Rhasspy](https://github.com/synesthesiam/rhasspy-hassio-addon) via [MQTT](http://mqtt.org/).
Audio data is streamed in from [Rhasspy](https://github.com/synesthesiam/rhasspy) via [MQTT](http://mqtt.org/).


Building
Expand Down
18 changes: 11 additions & 7 deletions snowboy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,35 @@
import json
from uuid import uuid4

from flask import Flask, request, send_file, render_template
from flask import Flask, request, send_file, render_template, safe_join

app = Flask('mycroft-precise', template_folder='.')
app.secret_key = str(uuid4())

config_path = os.environ.get('CONFIG_PATH', '/data/options.json')
model_path = os.environ.get('MODEL_PATH', '/models')
models_dir = os.environ.get('MODEL_PATH', '/share/snowboy')

@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
if 'delete' in request.form:
model_name = request.form['model']
os.unlink(os.path.join(model_path, model_name))
model_path = safe_join(models_dir, model_name)
if os.path.exists(model_path):
os.unlink(model_path)
elif 'file' in request.files:
file = request.files['file']
model_name = file.filename
file.save(os.path.join(model_path, model_name))
model_path = safe_join(models_dir, model_name)
os.makedirs(models_dir, exist_ok=True)
file.save(model_path)

with open(config_path, 'r') as config_file:
config = json.load(config_file)

models = []
if os.path.exists(model_path):
for model_name in os.listdir(model_path):
models.append(os.path.join(model_path, model_name))
if os.path.exists(models_dir):
for model_name in os.listdir(models_dir):
models.append(os.path.join(models_dir, model_name))

return render_template('index.html', config=config, models=models)
3 changes: 2 additions & 1 deletion snowboy/config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "Snowboy Wake System for Rhasspy",
"slug": "snowboy-rhasspy",
"version": "1.3.0-1",
"version": "1.3.0-2",
"description": "Snowboy wake word detection (Kitt.ai) for Rhasspy voice assistant",
"startup": "application",
"boot": "auto",
"map": ["share:rw"],
"options": {
"host": "localhost",
"port": 1883,
Expand Down

0 comments on commit 0dc0dde

Please sign in to comment.