jasperproject / jasper-client

Client code for Jasper voice computing platform
MIT License
4.53k stars 1.01k forks source link

Architectural changes for next Jasper version #280

Open Holzhaus opened 9 years ago

Holzhaus commented 9 years ago

While thinking about the design of the next Jasper release I hit some stumble blocks that require architectural changes in Jasper.

Here a some ideas open for discussion. I already created a working sample implementation that covers these points:

Also have a look at this amateurish diagram:

Jasper architecture mockup

What is still missing in my sample implementation:

@crm416 @shbhrsaha Any thoughts/criticism/feedback?

shbhrsaha commented 9 years ago

Haha, love the drawing.

Good overall first impression. Charlie and I'll think about this for a few days and provide some more specific feedback! Thanks for putting a lot of thought into this.

shbhrsaha commented 9 years ago

Thanks for waiting-- we just finished up with exams on this end!

I'm excited about all of these ideas. Here's my quick reactions for discussion:

  1. I love the idea of a config manager and getting rid of populate.py altogether. ~/.jasper/plugins would also be fantastic to have.
  2. Initially the idea of supporting socket-based input struck me as feature creep, but I'm warming up to the idea. I think voice control still defines Jasper-- are there compelling applications for socket-based input?
  3. Open to the idea of command phrases over single words. Even something as simple as mapping words to variables would probably be helpful for module developers.

So generally: I think these are good features! Eager to see the implementation you mentioned

Holzhaus commented 9 years ago

Concerning 2: Instead of using Sockets directly, I used the XMLRPC server built into Python. The usage example would be either to use it for testing or to create an Android App that uses the Google API to transcribe speech directly on the phone, then sends the command to Jasper and then outputs the answer on the phone again.

Concering 3: The good thing: You can still use a phrase consisting only of a single word (like "WEATHER"). So the simple modules will need to change the API calls, but the usage remains the same. More complex modules like MusicMode could stop running in their own "mode" entirely, but register a phrase like "Load playlist {playlist}" globally instead, which would simplify and speed up usage a lot.

I'll upload my example implementation soon.

Holzhaus commented 9 years ago

There it is: https://github.com/Holzhaus/jasper-plugin-draft The localization part is still missing.

Please have a look and tell me what you think.

shbhrsaha commented 9 years ago

Ah, OK. Yes, the applications for XMLRPC seem to be compelling use cases, so let's go forward with that too then.

Good point about global grammar registration-- I too would prefer that MusicMode not steal its own "mode".

The plugin draft looks fantastic. I like the inheritance from SpeechHandlerPlugin and .jasperplugin config files.

(Side note... you might've dealt with this already: I had to cast the slugify arguments in unicode() to get app.py to run) https://github.com/Holzhaus/jasper-plugin-draft/blob/master/core/configmanager.py#L48 https://github.com/Holzhaus/jasper-plugin-draft/blob/master/core/pluginmanager.py#L292

Holzhaus commented 9 years ago

Whoops, I accidently tested with Python3 instead of Python2. In Python3, all strings are unicode. I'll add that as soon as I finished my exams ;-)

What's still missing is a good way to implement the multi-language stuff. I'd like to use a directory structure like this, so that every plugins has the translations stored in it's own folder.

plugins/
   plugin1/
     plugin1.jasperplugin
     plugin1.py
     locale/
       en_US/
         plugin1.mo
       de_DE/
         plugin1.mo
Holzhaus commented 9 years ago

@shbhrsaha @crm416 After I finally finished both my exam period and the massive chillout period that necessarily followed it, I had some time to work on the plugin system draft. I now got multilanguage (based on gettext) working for speech handler plugins. Thus, most basic plugin stuff is finished. Please have a look at the respective git repo.

For testing purposes, you can change the default language in app.py to de_DE: All plugins that do not support that language should be rejected automatically.

The plugin structure has been simplified a bit:

plugins/
   plugin1/
     plugin1.jasperplugin
     plugin1.py
     languages/
       en_US.mo
       de_DE.mo

There still some remaining issues:

Holzhaus commented 9 years ago

Another thing just came to my mind. I'd like to put individual plugin initializiation into the plugin's activate() method, e.g. SpeechHandlerPlugins should register their phrases there, and also STTPlugins should compile their vocabularies inside this method, etc. This raises 2 issues:

  1. Plugins would have to be activated in a particular order, i.e SpeechHandlerPlugins will have to be activated before STTPlugins (because they need the CommandPhrases to be registered to be able to compile their vocabularies).
  2. I really do not know how pass the phrases over to the STTPlugins in order to compile the vocabularies. We could either add an additional method compile_vocabulary to the STTPlugin specs that will be called after activating the SpeechHandlerPlugins, but before activating the STTPlugins - or we add an additional argument to the STTPlugins activate method. Each option is not that clean, but I dislike the latter more than the first. Any thoughts?
shbhrsaha commented 9 years ago

Sorry for the late reply, Jan. Congrats on finishing exams! We're about to start that period on our end.

Your plugin work looks slick. My responses to your plugin issues:

In response to your ideas about SpeechHandlerPlugins/STTPlugins: