Skip to content

Commit

Permalink
feat/sounds_playback in ovos-audio (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl authored Sep 19, 2023
1 parent 3f61564 commit 8027bda
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 28 deletions.
11 changes: 0 additions & 11 deletions ovos_workshop/skills/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1878,17 +1878,6 @@ def speak_dialog(self, key: str, data: Optional[dict] = None,
)
self.speak(key, expect_response, wait, {})

@staticmethod
def acknowledge():
"""
Acknowledge a successful request.
This method plays a sound to acknowledge a request that does not
require a verbal response. This is intended to provide simple feedback
to the user that their request was handled successfully.
"""
return play_acknowledge_sound()

# method named init_dialog in mycroft-core
def load_dialog_files(self, root_directory: Optional[str] = None):
"""
Expand Down
14 changes: 14 additions & 0 deletions ovos_workshop/skills/mycroft_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ovos_bus_client import MessageBusClient, Message
from ovos_utils.log import LOG, log_deprecation, deprecated
from ovos_workshop.skills.base import BaseSkill, is_classic_core
from ovos_utils.sound import play_acknowledge_sound


class _SkillMetaclass(ABCMeta):
Expand Down Expand Up @@ -166,6 +167,19 @@ def _init_settings_manager(self):
except ImportError:
pass # standalone skill, skip backwards compat property

@staticmethod
def acknowledge():
"""
Acknowledge a successful request.
This method plays a sound to acknowledge a request that does not
require a verbal response. This is intended to provide simple feedback
to the user that their request was handled successfully.
"""
# DEPRECATED - note that this is a staticmethod and uses the old endpoint
# the OVOSSkill class does things properly
return play_acknowledge_sound()

def _init_settings(self):
"""Setup skill settings."""
if is_classic_core():
Expand Down
74 changes: 57 additions & 17 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,40 @@ def __instancecheck__(self, instance):
issubclass(instance.__class__, MycroftSkill)


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(BaseSkill, metaclass=_OVOSSkillMetaclass):
"""
New features:
Expand Down Expand Up @@ -140,28 +174,34 @@ def deactivate(self):
"""
self._deactivate()

def play_audio(self, filename: str):
def acknowledge(self):
"""
Acknowledge a successful request.
This method plays a sound to acknowledge a request that does not
require a verbal response. This is intended to provide simple feedback
to the user that their request was handled successfully.
"""
audio_file = self.config_core.get('sounds', {}).get('acknowledge',
'snd/acknowledge.mp3')
self.play_audio(audio_file, instant=True)

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 8027bda

Please sign in to comment.