Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/ovos_dialog_tts_transformers #179

Merged
merged 10 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/
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) Mycroft dialog_transformer module name from config
JarbasAl marked this conversation as resolved.
Show resolved Hide resolved
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) Mycroft dialog_transformer module name from config
Returns:
class: found dialog_transformer plugin class
"""
return load_plugin(module_name, PluginTypes.TTS_TRANSFORMER)
68 changes: 66 additions & 2 deletions ovos_plugin_manager/templates/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class MetadataTransformer:

""" runs after utterance transformers and before intent service"""
def __init__(self, name, priority=50, config=None):
self.name = name
self.bus = None
Expand Down Expand Up @@ -41,7 +41,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
self.bus = None
Expand Down Expand Up @@ -165,3 +165,67 @@ 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) -> str:
"""
Optionally transform passed dialog and/or return additional context
:param dialog: str utterance to mutate before TTS
:returns: str mutated dialog
"""
return dialog, context
JarbasAl marked this conversation as resolved.
Show resolved Hide resolved

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) -> str:
"""
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
JarbasAl marked this conversation as resolved.
Show resolved Hide resolved

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