Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

Commit

Permalink
Feat/precise upload v2 (#30)
Browse files Browse the repository at this point in the history
* feat/precise_upload_v2

adds support for the new precise upload endpoint - MycroftAI/mycroft-core#2753

* bump selene_api
  • Loading branch information
JarbasAl authored Sep 10, 2022
1 parent daecda0 commit 9715166
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
18 changes: 18 additions & 0 deletions ovos_local_backend/backend/precise.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,22 @@ def precise_upload():
"sent_to_mycroft": uploaded,
"saved": CONFIGURATION["record_wakewords"]}

@app.route('/device/<uuid>/wake-word-file', methods=['POST'])
@noindex
@check_selene_pairing
@requires_auth
def precise_upload_v2(uuid):
if CONFIGURATION["record_wakewords"]:
save_ww_recording(uuid, request.files)

uploaded = False
selene_cfg = CONFIGURATION.get("selene") or {}
if selene_cfg.get("upload_wakewords"):
# contribute to mycroft open dataset
uploaded = upload_ww(request.files)

return {"success": True,
"sent_to_mycroft": uploaded,
"saved": CONFIGURATION["record_wakewords"]}

return app
22 changes: 20 additions & 2 deletions ovos_local_backend/utils/selene.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from uuid import uuid4

from flask import request
Expand Down Expand Up @@ -127,10 +128,27 @@ def upload_utterance(audio, lang="en-us"):


def upload_ww(files):
audio = None
meta = {}

for precisefile in files:
fn = files[precisefile].filename
if fn == 'audio':
audio = files[precisefile].stream.read()
if fn == 'metadata':
meta = json.load(files[precisefile].stream)

uploaded = False
if selene_opted_in():
if audio and selene_opted_in():
# contribute to mycroft open dataset
pass # TODO add upload endpoint to selene_api package
api = DeviceApi()
try:
# old endpoint - supported by all local backend versions
# not sure if still supported by selene ?
api.upload_wake_word_v1(audio, meta)
except:
# new selene endpoint, not sure if already live ?
api.upload_wake_word(audio, meta)
return uploaded


Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ ovos-stt-plugin-server
geocoder
timezonefinder
requests_cache
selene_api>=0.0.1
selene_api>=0.0.2

0 comments on commit 9715166

Please sign in to comment.