From 576baeddbf18dda15b8ae0996c9eeb8fae052047 Mon Sep 17 00:00:00 2001 From: NeonJarbas <59943014+NeonJarbas@users.noreply.github.com> Date: Thu, 28 Jul 2022 20:39:55 +0100 Subject: [PATCH] feat/play_audio (#23) * feat/play_audio companion PR for https://github.com/OpenVoiceOS/ovos-core/pull/180 * version * ovos-core >= 0.0.4a45 Co-authored-by: jarbasai --- ovos_workshop/skills/__init__.py | 2 +- ovos_workshop/skills/ovos.py | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ovos_workshop/skills/__init__.py b/ovos_workshop/skills/__init__.py index 470d0356..c9c6619e 100644 --- a/ovos_workshop/skills/__init__.py +++ b/ovos_workshop/skills/__init__.py @@ -1,5 +1,5 @@ try: - from ovos_workshop.skills.ovos import MycroftSkill, OVOSSkill, OVOSFallbackSkill + from ovos_workshop.skills.ovos import MycroftSkill, OVOSSkill, OVOSFallbackSkill from ovos_workshop.skills.idle_display_skill import IdleDisplaySkill except ImportError: pass diff --git a/ovos_workshop/skills/ovos.py b/ovos_workshop/skills/ovos.py index e7a33d9e..692c81f1 100644 --- a/ovos_workshop/skills/ovos.py +++ b/ovos_workshop/skills/ovos.py @@ -4,7 +4,7 @@ # ensure mycroft can be imported from ovos_utils import ensure_mycroft_import from ovos_utils.log import LOG -from ovos_utils.messagebus import Message +from ovos_utils.messagebus import Message, dig_for_message, get_message_lang from ovos_utils.skills.settings import PrivateSettings ensure_mycroft_import() @@ -13,11 +13,11 @@ from mycroft.skills.mycroft_skill.event_container import create_wrapper from ovos_utils.skills import get_non_properties from ovos_utils.intents import IntentBuilder, Intent, AdaptIntent +from ovos_utils.sound import play_audio from ovos_workshop.patches.base_skill import MycroftSkill, FallbackSkill from ovos_workshop.decorators.killable import killable_event, \ AbortEvent, AbortQuestion from ovos_workshop.skills.layers import IntentLayers -from ovos_utils.messagebus import dig_for_message, get_message_lang class OVOSSkill(MycroftSkill): @@ -43,6 +43,19 @@ def bind(self, bus): self.private_settings = PrivateSettings(self.skill_id) self.intent_layers.bind(self) + def play_audio(self, filename): + try: + from mycroft.version import OVOS_VERSION_BUILD, OVOS_VERSION_MINOR, OVOS_VERSION_MAJOR + if OVOS_VERSION_MAJOR >= 1 or \ + OVOS_VERSION_MINOR > 0 or \ + OVOS_VERSION_BUILD >= 4: + self.bus.emit(Message("mycroft.audio.queue", + {"filename": filename})) + except: + pass + LOG.warning("self.play_audio requires ovos-core >= 0.0.4a45, falling back to local skill playback") + play_audio(filename).wait() + # lang support @property def lang(self):