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/neon_transformers #163

Merged
merged 6 commits into from
May 3, 2023
Merged

Conversation

NeonJarbas
Copy link

@NeonJarbas NeonJarbas commented Jun 17, 2022

integrates https://github.com/NeonGeckoCom/neon-transformers

functionality originally developed over at neon-core

to use add a section to your mycroft.conf, any plugin present will be loaded, config options depend on the plugin itself

example utterance plugins

sample config

{
    "utterance_transformers": {
            "neon_utterance_cancel_plugin": {},
            "ovos-utterance-normalizer": {}
     }
}

utterance transformer plugins base class

from ovos_plugin_manager.templates.transformers import UtteranceTransformer

class MyUtteranceHandler(UtteranceTransformer):

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

    def transform(self, utterances: List[str],
                  context: dict = None) -> (list, dict):
        """
        Optionally transform passed utterances and/or return additional context
        :param utterances: List of str utterances to parse
        :param context: existing Message context associated with utterances
        :returns: tuple of (possibly modified utterances, additional context)
        """
        return utterances, {}

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

metadata transformer plugin template

from ovos_plugin_manager.templates.transformers import MetadataTransformer

class MyMessageContextHandler(MetadataTransformer):

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

    def transform(self, context: dict = None) -> (dict):
        """
        Optionally transform passed context
        eg. inject default values or convert metadata format
        :param context: existing Message context from all previous transformers
        :returns: dict of possibly modified or additional context
        """
        context = context or {}
        return context

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

an equivalent for audio is already available in ovos-dinkum-listener, a PR is needed in ovos-listener

audio transformer plugin template

from ovos_plugin_manager.templates.transformers import AudioTransformer


class MyAudioHandler(AudioTransformer):
    """process audio data and optionally transform it before STT stage"""

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

    def on_audio(self, audio_data):
        """ Take any action you want, audio_data is a non-speech chunk
        """
        return audio_data

    def on_hotword(self, audio_data):
        """ Take any action you want, audio_data is a full wake/hotword
        Common action would be to prepare to received speech chunks
        NOTE: this might be a hotword or a wakeword, listening is not assured
        """
        return audio_data

    def on_speech(self, audio_data):
        """ Take any action you want, audio_data is a speech chunk (NOT a
        full utterance) during recording
        """
        return audio_data

    def on_speech_end(self, audio_data):
        """ Take any action you want, audio_data is the full speech audio
        """
        return audio_data

    def transform(self, audio_data):
        """ return any additional message context to be passed in
        recognize_loop:utterance message, usually a streaming prediction
        Optionally make the prediction here with saved chunks from other handlers
        """
        return audio_data, {}

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

@JarbasAl JarbasAl requested a review from NeonDaniel June 17, 2022 18:14
@codecov
Copy link

codecov bot commented Jun 17, 2022

Codecov Report

Merging #163 (41e160e) into dev (6ceb058) will decrease coverage by 36.22%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##              dev     #163       +/-   ##
===========================================
- Coverage   50.35%   14.13%   -36.22%     
===========================================
  Files         119       11      -108     
  Lines       10077     1493     -8584     
===========================================
- Hits         5074      211     -4863     
+ Misses       5003     1282     -3721     

see 93 files with indirect coverage changes

@JarbasAl JarbasAl added enhancement New feature or request neon-core ported from neon-core labels Jun 17, 2022
mycroft/skills/intent_service.py Outdated Show resolved Hide resolved
mycroft/skills/intent_service.py Outdated Show resolved Hide resolved
mycroft/skills/intent_service.py Outdated Show resolved Hide resolved
@JarbasAl
Copy link
Member

JarbasAl commented May 2, 2023

JarbasAl added a commit to OpenVoiceOS/ovos-lingua-franca that referenced this pull request May 2, 2023
JarbasAl added a commit to OpenVoiceOS/ovos-classifiers that referenced this pull request May 2, 2023
ovos_core/transformers.py Outdated Show resolved Hide resolved
@JarbasAl JarbasAl requested a review from a team May 3, 2023 02:00
@JarbasAl JarbasAl requested a review from goldyfruit May 3, 2023 17:01
@JarbasAl JarbasAl requested review from emphasize, builderjer and a team May 3, 2023 17:01
@JarbasAl JarbasAl merged commit 79185d3 into OpenVoiceOS:dev May 3, 2023
@NeonJarbas NeonJarbas deleted the feat/neon_transformers branch January 6, 2024 01:38
@JarbasAl JarbasAl modified the milestones: 0.0.7, 0.0.8 Feb 22, 2024
JarbasAl added a commit to OpenVoiceOS/ovos-lingua-franca that referenced this pull request May 12, 2024
* feat/utterance_plugin

companion to OpenVoiceOS/ovos-core#163

* rm comment

* rm try except
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request neon-core ported from neon-core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants