diff --git a/ovos_workshop/skills/ovos.py b/ovos_workshop/skills/ovos.py index 8fa7c5cb..4658c36f 100644 --- a/ovos_workshop/skills/ovos.py +++ b/ovos_workshop/skills/ovos.py @@ -17,6 +17,40 @@ from ovos_workshop.skills.mycroft_skill import MycroftSkill, is_classic_core +def _can_play_audio(instant=False): + """ helper method to ensure skills keep working on old versions of ovos/mycroft""" + # TODO - completely drop support for older core versions in 0.1.0 release + try: + import mycroft + except ImportError: + # skills don't require core anymore, running standalone + return True + + if instant: + try: + from ovos_core.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 >= 8: + return True # min version of ovos-core - 0.0.8 + except ImportError: + pass + else: + try: + # feature introduced before ovos_core module + 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: + return True # min version of ovos-core - 0.0.4 + except ImportError: + pass + + return False + + class OVOSSkill(MycroftSkill): """ New features: @@ -124,28 +158,23 @@ def deactivate(self): """ self._deactivate() - def play_audio(self, filename: str): + def play_audio(self, filename: str, instant: bool = False): """ Queue and audio file for playback @param filename: File to play + @param instant: if True audio will be played instantly instead of queued with TTS """ - core_supported = False - if not is_classic_core(): - 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: - core_supported = True # min version of ovos-core - except ImportError: - # skills don't require core anymore, running standalone - core_supported = True - - if core_supported: + if _can_play_audio(instant): message = dig_for_message() or Message("") - self.bus.emit(message.forward("mycroft.audio.queue", - {"filename": filename})) + if instant: + self.bus.emit(message.forward("mycroft.audio.play_sound", + {"uri": filename + })) + else: + self.bus.emit(message.forward("mycroft.audio.queue", + {"filename": filename, # TODO - deprecate filename in ovos-audio + "uri": filename # new namespace + })) else: LOG.warning("self.play_audio requires ovos-core >= 0.0.4a45, " "falling back to local skill playback")