AwesomeTTS / awesometts-anki-addon

AwesomeTTS text-to-speech add-on for Anki
GNU General Public License v3.0
480 stars 100 forks source link

Add hook for service registration by other addons #22

Closed wizzwizz4 closed 4 years ago

wizzwizz4 commented 7 years ago

I would like to customise AwesomeTTS in a way that can't be done through the preferences menu without having my changes overwritten when AwesomeTTS updates. A relatively simple way of doing this would be to add a hook handler to awesometts/services/__init__.py:

def _service(name, obj):
    __dict__[name] = obj
    __all__.append(name)
_addHook("AwesomeTTS_register_service", _service)
_runHook("AwesomeTTS_loaded_services")

I am not very familiar with the code, so I don't know what else would need changing. From what I can tell, this and perhaps the service list "cache"(s) (if there is / are one(s)) would need changing (perhaps with an AwesomeTTS_flush_services hook). In order to use this, another addon would simply have to include:

def register_my_service():
    runHook("AwesomeTTS_register_service", "my_service", my_service_object)
addHook("AwesomeTTS_loaded_services", register_my_service)  # Iff I load before AwesomeTTS
register_my_service()  # Iff I load after AwesomeTTS

which would work assuming that nobody else wants to use the hook name AwesomeTTS_register_service, in which case their hook would run twice if they load before both AwesomeTTS and the target add-on. But who's going to do that?

wizzwizz4 commented 7 years ago

I assume that Feature Requests are allowed.

krassowski commented 7 years ago

to customise AwesomeTTS in a way that can't be done through the preferences menu without having my changes overwritten when AwesomeTTS updates

What's the customization you would like to perform that causes such troubles?

wizzwizz4 commented 6 years ago

I'd like to add support for breaking up spacedelimited phrases into separate words in order to pass them through Duden, then join those to make a final audio phrase. Then, as needs changed, I might add support for fallbacks (e.g. Wiktionary).

krassowski commented 6 years ago

Sounds like as an useful feature to me. Really, I thought about such a thing too, but I would like to separate words by other delimiter, pipe: |, just to get better pronunciation for two words I compare. Maybe you could share your changes and contribute a patch upstream, instead of running it with a hook/filter?

wizzwizz4 commented 6 years ago

I might, if my code is sane. However, I think that adding support for some other service registration method (preferably a better one than my suggestion) would be preferable to in-place allow other add-ons to interface with AwesomeTTS - essentially allowing AwesomeTTS addons to exist. This would drastically increase the features available for AwesomeTTS as Anki addons an drastically increase the features available for Anki.

luc-vocab commented 4 years ago

@wizzwizz4 can you describe your use case in more details ? are you trying to generate audio for a full sentence from TTS services which only support individual words ? Can your needs be met by using a more advanced TTS service which supports full sentences ?

wizzwizz4 commented 4 years ago

are you trying to generate audio for a full sentence from TTS services which only support individual words ?

Yes – or, at least, I was. I've dropped the project.

Can your needs be met by using a more advanced TTS service which supports full sentences ?

I vaguely remember that no such service was available at the time – but if one did, then yes. I wanted something not synthesised, because the synthesisers were getting it wrong and I didn't want to learn wrong.

In retrospect, I think I should've made an Anki feature request for allowing add-ons to "depend" on others, so they loaded after them.

luc-vocab commented 4 years ago

Understood. A lot of people have a separate field which contains pronounciation-only text, which is sometimes distorted to help the TTS system.