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

STT class init with wrong config #132

Closed
emphasize opened this issue Mar 21, 2023 · 4 comments · Fixed by #187
Closed

STT class init with wrong config #132

emphasize opened this issue Mar 21, 2023 · 4 comments · Fixed by #187
Assignees
Labels
bug Something isn't working

Comments

@emphasize
Copy link
Member

emphasize commented Mar 21, 2023

config passed:

{
        "module": "ovos-stt-plugin-server",
        "ovos-stt-plugin-server": {
            "url": "https://stt.openvoiceos.com/stt",
            "lang": "de-de"
}

get_stt_config will now mangle the config and returns (as config)

{
            "url": "https://stt.openvoiceos.com/stt",
            "lang": "de-de",
            "module": "ovos-stt-plugin-server"
}

since it has its own definitions.

but plugin_config = config.get(plugin) or {} will produce an empty dict and the class will get initialized with this empty dict

config = get_stt_config(config)
plugin = config["module"]
plugin_config = config.get(plugin) or {}
try:
clazz = OVOSSTTFactory.get_class(config)
return clazz(plugin_config)


Because it (the module) has its own definition it's irrelevant if you pass

{ "stt":
      {
        "module": "ovos-stt-plugin-server",
        "ovos-stt-plugin-server": {
            "url": "https://stt.openvoiceos.com/stt",
            "lang": "de-de"
      }
}

The result will be the same.


Reproduce with:

from ovos_plugin_manager.stt import OVOSSTTFactory
config={"module": "ovos-stt-plugin-server",
        "ovos-stt-plugin-server": {
        "url": "https://stt.openvoiceos.com/stt",
        "lang": "de-de"}}
engine = OVOSSTTFactory.create(config)
print(engine.url)
# https://stt.strongthany.cc/stt
@emphasize
Copy link
Member Author

My suggestion:

@staticmethod
    def get_class(config=None):

        # config = config or get_stt_config()
        config = get_stt_config(config)                                                
        stt_module = config["module"]
        if stt_module in OVOSSTTFactory.MAPPINGS:
            stt_module = OVOSSTTFactory.MAPPINGS[stt_module]
        return load_stt_plugin(stt_module)

    @staticmethod
    def create(config=None):
        
        # config = get_stt_config(config)
        # plugin = config["module"]
        # plugin_config = config.get(plugin) or {}
        try:
            clazz = OVOSSTTFactory.get_class(config)
            return clazz(config)
        except Exception:
            LOG.exception('The selected STT plugin could not be loaded!')
            raise

works with whole config or section. But you have the bigger picture.

@ChanceNCounter ChanceNCounter added the bug Something isn't working label Mar 21, 2023
@emphasize
Copy link
Member Author

emphasize commented Mar 22, 2023

Imagine my head exploding when realizing this is not reproducable on another machine.

But - in my estimation - the "fix" made along the way covers the initial problem: that the class is initiated with an emtpy dict,
although it is configured with the intended structure.

{
    "module": "xxx",
    "xxx": {module_config}
}

@NeonDaniel
Copy link
Member

I think this may be related to #161 . In general, the get_config methods should do minimal parsing to ensure the factory gets:
module, lang, and module_config; the most specific lang should be used, only falling back to global lang if there isn't a plugin-specific one.

The main purpose of the method here is to make sure lang is read from global config (if not in the plugin-specific config) and passed to plugin init

@mikejgray
Copy link
Contributor

I can confirm similar issues with TTS.

mycroft.conf loaded to both /etc/mycroft/mycroft.conf and /root/.config/mycroft/mycroft.conf in a container running tts-server:

{
  "lang": "de-de",
  "tts": {
    "module": "ovos_tts_plugin_espeakng",
    "ovos_tts_plugin_espeakng": {
      "lang": "de-de",
      "voice": "german-mbrola-5",
      "speed": "135",
      "amplitude": "80",
      "pitch": "20"
    }
  }
}

Output from logging into the container:

root@c6d9a23498f8:/# ovos-config get -k tts
Value: {'pulse_duck': False, 'module': 'ovos_tts_plugin_espeakng', 'fallback_module': '', 'ovos-tts-plugin-mimic': {'voice': 'ap'}, 
'ovos-tts-plugin-mimic3-server': {'voice': 'en_UK/apope_low'}, 'ovos_tts_plugin_espeakng': {'lang': 'de-de', 'voice': 'german-mbrola-5', 'speed': '135', 
'amplitude': '80', 'pitch': '20'}}, found in /tts
Value: {'voice': 'ap'}, found in /tts/ovos-tts-plugin-mimic
Value: {'voice': 'en_UK/apope_low'}, found in /tts/ovos-tts-plugin-mimic3-server
Value: {'lang': 'de-de', 'voice': 'german-mbrola-5', 'speed': '135', 'amplitude': '80', 'pitch': '20'}, found in /tts/ovos_tts_plugin_espeakng

Log of self.config from older version of ovos-plugin-manager that didn't swallow LOG messages:

2023-09-01 21:18:39.977 - OVOS - ovos_tts_plugin_espeakng:__init__:30 - DEBUG - {'persist_cache': False, 'lang': 'de-de'}

Most recent alpha does not show messages from LOG on stdout, so I can't verify the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants