From 17e36983981c8e8dbd076c7ef25e83ff2c72c9ba Mon Sep 17 00:00:00 2001 From: JarbasAi Date: Tue, 17 Oct 2023 00:29:56 +0100 Subject: [PATCH 1/3] feat/handle_hex_audiodata companion to https://github.com/OpenVoiceOS/ovos-audio/pull/34 --- ovos_workshop/skills/ovos.py | 46 ++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/ovos_workshop/skills/ovos.py b/ovos_workshop/skills/ovos.py index 281d504e..1678068f 100644 --- a/ovos_workshop/skills/ovos.py +++ b/ovos_workshop/skills/ovos.py @@ -1,4 +1,6 @@ +import binascii import datetime +import os import re import sys import time @@ -15,12 +17,13 @@ from json_database import JsonStorage from lingua_franca.format import pronounce_number, join_list from lingua_franca.parse import yes_or_no, extract_number +from ovos_config.config import Configuration +from ovos_config.locations import get_xdg_config_save_path + from ovos_backend_client.api import EmailApi, MetricsApi from ovos_bus_client import MessageBusClient from ovos_bus_client.message import Message, dig_for_message from ovos_bus_client.session import SessionManager, Session -from ovos_config.config import Configuration -from ovos_config.locations import get_xdg_config_save_path from ovos_plugin_manager.language import OVOSLangTranslationFactory, OVOSLangDetectionFactory from ovos_utils import camel_case_split, classproperty from ovos_utils.dialog import get_dialog, MustacheDialogRenderer @@ -1056,7 +1059,8 @@ def _handle_converse_ack(self, message: Message): @param message: `{self.skill_id}.converse.ping` Message """ if message.msg_type == "skill.converse.ping": - log_deprecation("Support for message type `skill.converse.ping` is deprecated, use `{skill_id}.converse.ping`", "0.0.9") + log_deprecation( + "Support for message type `skill.converse.ping` is deprecated, use `{skill_id}.converse.ping`", "0.0.9") if message.data.get("skill_id") != self.skill_id: return # not for us! @@ -1073,7 +1077,9 @@ def _handle_converse_request(self, message: Message): @param message: `{self.skill_id}.converse.request` Message """ if message.msg_type == "skill.converse.request": - log_deprecation("Support for message type `skill.converse.request` is deprecated, use `{skill_id}.converse.request`", "0.0.9") + log_deprecation( + "Support for message type `skill.converse.request` is deprecated, use `{skill_id}.converse.request`", + "0.0.9") if message.data.get("skill_id") != self.skill_id: return # not for us! @@ -1081,18 +1087,18 @@ def _handle_converse_request(self, message: Message): # converse can have multiple signatures params = signature(self.converse).parameters kwargs = {"message": message, - "utterances": message.data['utterances'], - "lang": message.data['lang']} + "utterances": message.data['utterances'], + "lang": message.data['lang']} kwargs = {k: v for k, v in kwargs.items() if k in params} result = self.converse(**kwargs) self.bus.emit(message.reply('skill.converse.response', {"skill_id": self.skill_id, - "result": result})) + "result": result})) except Exception as e: LOG.error(e) self.bus.emit(message.reply('skill.converse.response', {"skill_id": self.skill_id, - "result": False})) + "result": False})) def _handle_collect_resting(self, message: Optional[Message] = None): """ @@ -1534,12 +1540,24 @@ def play_audio(self, filename: str, instant: bool = False): @param instant: if True audio will be played instantly instead of queued with TTS """ message = dig_for_message() or Message("") + # if running in docker we need to send binary data to the ovos-audio container + # if sessions is not default we also need to do it since + # it likely is a remote client such as hivemind + send_binary = os.environ.get("IS_OVOS_CONTAINER") or \ + SessionManager.get(message).session_id != "default" + if instant: - self.bus.emit(message.forward("mycroft.audio.play_sound", - {"uri": filename})) + mtype = "mycroft.audio.play_sound" else: - self.bus.emit(message.forward("mycroft.audio.queue", - {"uri": filename})) + mtype = "mycroft.audio.queue" + if send_binary: + data = {"uri": filename} + else: + with open(filename, "rb") as f: + data = {"audio_ext": filename.split(".")[-1], + "binary_data": binascii.hexlify(f.read())} + + self.bus.emit(message.forward(mtype, data)) def __get_response_v1(self, session=None): """Helper to get a response from the user @@ -1594,7 +1612,9 @@ def __handle_get_response(self, message): sent from the intent service """ if message.msg_type == "skill.converse.get_response": - log_deprecation("Support for message type `skill.converse.get_response` is deprecated, use `{skill_id}.converse.get_response`", "0.0.9") + log_deprecation( + "Support for message type `skill.converse.get_response` is deprecated, use `{skill_id}.converse.get_response`", + "0.0.9") if message.data.get("skill_id") != self.skill_id: return # not for us! From 2838a901ab95168f4b77a914d81f12803917b2e5 Mon Sep 17 00:00:00 2001 From: JarbasAi Date: Tue, 17 Oct 2023 00:31:20 +0100 Subject: [PATCH 2/3] feat/handle_hex_audiodata companion to https://github.com/OpenVoiceOS/ovos-audio/pull/34 --- ovos_workshop/skills/ovos.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ovos_workshop/skills/ovos.py b/ovos_workshop/skills/ovos.py index 1678068f..95e36759 100644 --- a/ovos_workshop/skills/ovos.py +++ b/ovos_workshop/skills/ovos.py @@ -1550,7 +1550,8 @@ def play_audio(self, filename: str, instant: bool = False): mtype = "mycroft.audio.play_sound" else: mtype = "mycroft.audio.queue" - if send_binary: + + if not send_binary: data = {"uri": filename} else: with open(filename, "rb") as f: From a7322331d608ae5f12a3be0e808e72ac3f16fa06 Mon Sep 17 00:00:00 2001 From: JarbasAi Date: Tue, 17 Oct 2023 00:36:10 +0100 Subject: [PATCH 3/3] feat/handle_hex_audiodata companion to https://github.com/OpenVoiceOS/ovos-audio/pull/34 --- ovos_workshop/skills/ovos.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ovos_workshop/skills/ovos.py b/ovos_workshop/skills/ovos.py index 95e36759..87f467a0 100644 --- a/ovos_workshop/skills/ovos.py +++ b/ovos_workshop/skills/ovos.py @@ -1555,8 +1555,9 @@ def play_audio(self, filename: str, instant: bool = False): data = {"uri": filename} else: with open(filename, "rb") as f: - data = {"audio_ext": filename.split(".")[-1], - "binary_data": binascii.hexlify(f.read())} + bindata = binascii.hexlify(f.read()).decode('utf-8') + data = {"audio_ext": filename.split(".")[-1], + "binary_data": bindata} self.bus.emit(message.forward(mtype, data))