Skip to content

Commit

Permalink
feat/sounds_playback in ovos-audio
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Sep 5, 2023
1 parent e8540c0 commit 977675b
Showing 1 changed file with 46 additions and 17 deletions.
63 changes: 46 additions & 17 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 977675b

Please sign in to comment.