jasperproject/jasper-client — pull request #219 by Holzhaus (2014-10-09 14:08:04+00:00)
Title: Remove transcription mode

This a follow-up PR to #181 (Rewrite of vocabcompiler).

If you look at `jasper.py` and `client/mic.py`, we're using the `Mic` class like this:
```Python
class Mic:
def__init__(self, speaker, passive_stt_engine, active_stt_engine):
```
So we pass in two different STT Engine instances:
1. An STT Engine instance for passive listen
2. An STT Engine Instance for active listen

But PocketsphinxSTT takes up to 3 lm/dict pairs:
1. A pair for passive listen
2. A pair for active listen
3 A pair for active listen (musicmode)

This is a lot duplication, because in `jasper.py`, we're creating two separate SST Engine Instances for active listen and passive listen, so that the active listen STT Engine instance will only use the second lm/dict pair and the passive listen STT instance will only use the first pair.
In MusicMode, a third STT instance will be created that only uses the third pair.

Given the case that someone wants to write a new module that also has the ability to start a mode like the MusicMode, he'd either have to hijack the music lm/dict pair, or he'd need to add a new mode to STT Engines and change the PocketsphinxSTTEngine code.

Thus, I'd like to simplify the STT engine dramatically by removing two of the three dict pairs (or rather Vocabulary Instances) from the PocketsphinxSTT engine and the `mode` parameter in `transcribe` accordingly.

Also, there's no need to case about custom engine-specific settings, because the `get_engine()` classmethod takes care of that for you.

This vastly simplifies how STT engines are instantiated. Basically, you only need these steps:
```Python
import stt
engine = stt.get_engine_by_slug('sphinx')

# Convenience method: Instance for passive listen
stt_instance_passive = engine.get_passive_instance()
# Convenience method: Instance for active listen
stt_instance_active = engine.get_active_instance()

# Generic method (e.g. used by MusicMode (MPDControl.py)
stt_instance_custom = engine.get_instance('my_vocab', ['SOME', 'PHRASES', 'TO', 'RECOGNIZE'])

# Now create a mic:
mic1 = Mic(tts_instance, stt_instance_passive, stt_instance_active)

# A module like musicmode now can simply do this:
mic2 = Mic(mic1.speaker, mic.passive_stt_engine, stt_instance_custom)
```

What happends inside `get_instance()` (which is also called by the convenience methods `get_passive_instance()`/`get_active_instance()`)?
- the configuration for this STT engine is retrieved
- if this STT engine needs a vocabulary ('sphinx' does, but 'google' does not):
- it will be initialized with the name `my_vocab`.
- it is checked if it matches all phrases and recompiled if neccessary
- an STT engine instance is created with config (and vocabulary if neccessary) and returned

Because every STT engine only has one vocabulary, the `transcribe()` method becomes less complex, because it doesn't need the `mode` argument anymore.