Skip to content

Commit

Permalink
feat/ovos_dialog_tts_transformers (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl authored Oct 7, 2023
1 parent 159d2cd commit 53be943
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 281 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ dist

# Created by unit tests
.pytest_cache/
/.gtm/
6 changes: 3 additions & 3 deletions ovos_plugin_manager/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def setup_audio_service(service_module, config=None, bus=None):
Arguments:
service_module: Python module to run
config (dict): Mycroft configuration dict
config (dict): OpenVoiceOS configuration dict
bus (MessageBusClient): Messagebus interface
Returns:
(list) List of created services.
Expand All @@ -72,8 +72,8 @@ def load_audio_service_plugins(config=None, bus=None):
"""Load installed audioservice plugins.
Arguments:
config: Mycroft core configuration
bus: Mycroft messagebus
config: OpenVoiceOS core configuration
bus: OpenVoiceOS messagebus
Returns:
List of started services
Expand Down
2 changes: 1 addition & 1 deletion ovos_plugin_manager/audio_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def load_audio_transformer_plugin(module_name: str) -> type(AudioTransformer):
"""Wrapper function for loading audio_transformer plugin.
Arguments:
(str) Mycroft audio_transformer module name from config
(str) OpenVoiceOS audio_transformer module name from config
Returns:
class: found audio_transformer plugin class
"""
Expand Down
41 changes: 41 additions & 0 deletions ovos_plugin_manager/dialog_transformers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from ovos_plugin_manager.templates.transformers import DialogTransformer, TTSTransformer
from ovos_plugin_manager.utils import PluginTypes
from ovos_plugin_manager.utils import load_plugin, find_plugins


def find_dialog_transformer_plugins() -> dict:
"""
Find all installed plugins
@return: dict plugin names to entrypoints
"""
return find_plugins(PluginTypes.DIALOG_TRANSFORMER)


def load_dialog_transformer_plugin(module_name: str) -> type(DialogTransformer):
"""Wrapper function for loading dialog_transformer plugin.
Arguments:
(str) OpenVoiceOS dialog_transformer module name from config
Returns:
class: found dialog_transformer plugin class
"""
return load_plugin(module_name, PluginTypes.DIALOG_TRANSFORMER)


def find_tts_transformer_plugins() -> dict:
"""
Find all installed plugins
@return: dict plugin names to entrypoints
"""
return find_plugins(PluginTypes.TTS_TRANSFORMER)


def load_tts_transformer_plugin(module_name: str) -> type(TTSTransformer):
"""Wrapper function for loading dialog_transformer plugin.
Arguments:
(str) OpenVoiceOS dialog_transformer module name from config
Returns:
class: found dialog_transformer plugin class
"""
return load_plugin(module_name, PluginTypes.TTS_TRANSFORMER)
8 changes: 4 additions & 4 deletions ovos_plugin_manager/templates/audio.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Definition of the audio service backends base classes.
These classes can be used to create an Audioservice plugin extending
Mycroft's media playback options.
OpenVoiceOS's media playback options.
"""
from abc import ABCMeta, abstractmethod

Expand All @@ -15,7 +15,7 @@ class AudioBackend(metaclass=ABCMeta):
Arguments:
config (dict): configuration dict for the instance
bus (MessageBusClient): Mycroft messagebus emitter
bus (MessageBusClient): OpenVoiceOS messagebus emitter
"""

def __init__(self, config=None, bus=None):
Expand Down Expand Up @@ -134,15 +134,15 @@ def lower_volume(self):
"""Lower volume.
This method is used to implement audio ducking. It will be called when
Mycroft is listening or speaking to make sure the media playing isn't
OpenVoiceOS is listening or speaking to make sure the media playing isn't
interfering.
"""

def restore_volume(self):
"""Restore normal volume.
Called when to restore the playback volume to previous level after
Mycroft has lowered it using lower_volume().
OpenVoiceOS has lowered it using lower_volume().
"""

def get_track_length(self):
Expand Down
4 changes: 2 additions & 2 deletions ovos_plugin_manager/templates/phal.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def validate(config: dict = None) -> bool:
class PHALPlugin(Thread):
"""
This base class is intended to be used to interface with the hardware
that is running Mycroft. It exposes all possible commands which
that is running OpenVoiceOS. It exposes all possible commands which
are expected be sent to a PHAL plugin.
All of the handlers are optional and for convenience only
"""
Expand Down Expand Up @@ -65,7 +65,7 @@ def register_enclosure_namespace(self):
self.bus.on("enclosure.notify.no_internet", self.on_no_internet)
self.bus.on("enclosure.reset", self.on_reset)

# enclosure commands for Mycroft's Hardware.
# enclosure commands for OpenVoiceOS's Hardware.
self.bus.on("enclosure.system.reset", self.on_system_reset)
self.bus.on("enclosure.system.mute", self.on_system_mute)
self.bus.on("enclosure.system.unmute", self.on_system_unmute)
Expand Down
70 changes: 69 additions & 1 deletion ovos_plugin_manager/templates/transformers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import List, Tuple

from ovos_config.config import Configuration
from ovos_utils.messagebus import get_mycroft_bus
Expand All @@ -7,6 +7,7 @@


class MetadataTransformer:
""" runs after utterance transformers and before intent service"""

def __init__(self, name, priority=50, config=None):
self.name = name
Expand Down Expand Up @@ -41,6 +42,7 @@ def default_shutdown(self):


class UtteranceTransformer:
""" runs before metadata transformers and intent service"""

def __init__(self, name, priority=50, config=None):
self.name = name
Expand Down Expand Up @@ -165,3 +167,69 @@ def transform(self, audio_data):
def default_shutdown(self):
""" perform any shutdown actions """
pass


class DialogTransformer:
""" runs before TTS stage"""

def __init__(self, name, priority=50, config=None):
self.name = name
self.bus = None
self.priority = priority
if not config:
config_core = dict(Configuration())
config = config_core.get("dialog_transformers", {}).get(self.name)
self.config = config or {}

def bind(self, bus=None):
""" attach messagebus """
self.bus = bus or get_mycroft_bus()

def initialize(self):
""" perform any initialization actions """
pass

def transform(self, dialog: str, context: dict = None) -> Tuple[str, dict]:
"""
Optionally transform passed dialog and/or return additional context
:param dialog: str utterance to mutate before TTS
:returns: str mutated dialog
"""
return dialog, context

def default_shutdown(self):
""" perform any shutdown actions """
pass


class TTSTransformer:
""" runs after TTS stage but before playback"""

def __init__(self, name, priority=50, config=None):
self.name = name
self.bus = None
self.priority = priority
if not config:
config_core = dict(Configuration())
config = config_core.get("dialog_transformers", {}).get(self.name)
self.config = config or {}

def bind(self, bus=None):
""" attach messagebus """
self.bus = bus or get_mycroft_bus()

def initialize(self):
""" perform any initialization actions """
pass

def transform(self, wav_file: str, context: dict = None) -> Tuple[str, dict]:
"""
Optionally transform passed wav_file and return path to transformed file
:param wav_file: path to wav file generated in TTS stage
:returns: path to transformed wav file for playback
"""
return wav_file, context

def default_shutdown(self):
""" perform any shutdown actions """
pass
Loading

0 comments on commit 53be943

Please sign in to comment.