Generic parent class for all STT engines
| 18 | |
| 19 | |
| 20 | class AbstractSTTEngine(object): |
| 21 | """ |
| 22 | Generic parent class for all STT engines |
| 23 | """ |
| 24 | |
| 25 | __metaclass__ = ABCMeta |
| 26 | VOCABULARY_TYPE = None |
| 27 | |
| 28 | @classmethod |
| 29 | def get_config(cls): |
| 30 | return {} |
| 31 | |
| 32 | @classmethod |
| 33 | def get_instance(cls, vocabulary_name, phrases): |
| 34 | config = cls.get_config() |
| 35 | if cls.VOCABULARY_TYPE: |
| 36 | vocabulary = cls.VOCABULARY_TYPE(vocabulary_name, |
| 37 | path=jasperpath.config( |
| 38 | 'vocabularies')) |
| 39 | if not vocabulary.matches_phrases(phrases): |
| 40 | vocabulary.compile(phrases) |
| 41 | config['vocabulary'] = vocabulary |
| 42 | instance = cls(**config) |
| 43 | return instance |
| 44 | |
| 45 | @classmethod |
| 46 | def get_passive_instance(cls): |
| 47 | phrases = vocabcompiler.get_keyword_phrases() |
| 48 | return cls.get_instance('keyword', phrases) |
| 49 | |
| 50 | @classmethod |
| 51 | def get_active_instance(cls): |
| 52 | phrases = vocabcompiler.get_all_phrases() |
| 53 | return cls.get_instance('default', phrases) |
| 54 | |
| 55 | @classmethod |
| 56 | @abstractmethod |
| 57 | def is_available(cls): |
| 58 | return True |
| 59 | |
| 60 | @abstractmethod |
| 61 | def transcribe(self, fp): |
| 62 | pass |
| 63 | |
| 64 | |
| 65 | class PocketSphinxSTT(AbstractSTTEngine): |
nothing calls this directly
no outgoing calls
no test coverage detected