From 9715166ede4e9722ec5ca70be4774c8c6e8f5686 Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Sat, 10 Sep 2022 14:09:25 +0100 Subject: [PATCH] Feat/precise upload v2 (#30) * feat/precise_upload_v2 adds support for the new precise upload endpoint - https://github.com/MycroftAI/mycroft-core/pull/2753 * bump selene_api --- ovos_local_backend/backend/precise.py | 18 ++++++++++++++++++ ovos_local_backend/utils/selene.py | 22 ++++++++++++++++++++-- requirements/requirements.txt | 2 +- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/ovos_local_backend/backend/precise.py b/ovos_local_backend/backend/precise.py index fba3d70..c5cd461 100644 --- a/ovos_local_backend/backend/precise.py +++ b/ovos_local_backend/backend/precise.py @@ -27,4 +27,22 @@ def precise_upload(): "sent_to_mycroft": uploaded, "saved": CONFIGURATION["record_wakewords"]} + @app.route('/device//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 diff --git a/ovos_local_backend/utils/selene.py b/ovos_local_backend/utils/selene.py index 411d95c..209a006 100644 --- a/ovos_local_backend/utils/selene.py +++ b/ovos_local_backend/utils/selene.py @@ -1,3 +1,4 @@ +import json from uuid import uuid4 from flask import request @@ -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 diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 5270a78..9c2fca1 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -8,4 +8,4 @@ ovos-stt-plugin-server geocoder timezonefinder requests_cache -selene_api>=0.0.1 \ No newline at end of file +selene_api>=0.0.2 \ No newline at end of file