|
@@ -2,18 +2,6 @@ import logging
|
|
|
from core import ConfigurationManager
|
|
|
|
|
|
|
|
|
-class DefaultSpeechToTextNotFound(Exception):
|
|
|
- pass
|
|
|
-
|
|
|
-
|
|
|
-class DefaultSpeechNull(Exception):
|
|
|
- pass
|
|
|
-
|
|
|
-
|
|
|
-class NoSpeechToTextConfiguration(Exception):
|
|
|
- pass
|
|
|
-
|
|
|
-
|
|
|
class OrderListener:
|
|
|
|
|
|
def __init__(self, main_controller=None):
|
|
@@ -29,60 +17,14 @@ class OrderListener:
|
|
|
self.settings = ConfigurationManager().get_settings()
|
|
|
|
|
|
def load_stt_plugin(self):
|
|
|
- default_stt_plugin = self._get_stt_plugins()
|
|
|
+ default_stt_plugin = ConfigurationManager.get_default_speech_to_text()
|
|
|
|
|
|
- stt_args = self._get_stt_args(default_stt_plugin)
|
|
|
+ stt_args = ConfigurationManager.get_stt_args(default_stt_plugin)
|
|
|
|
|
|
# capitalizes the first letter (because classes have first letter upper case)
|
|
|
default_stt_plugin = default_stt_plugin.capitalize()
|
|
|
self._run_stt_plugin(default_stt_plugin, stt_args)
|
|
|
|
|
|
- def _get_stt_plugins(self):
|
|
|
- try:
|
|
|
- default_speech_to_text = self.settings["default_speech_to_text"]
|
|
|
- if default_speech_to_text is None:
|
|
|
- raise DefaultSpeechNull("Attribute default_speech_to_text is null")
|
|
|
- logging.info("Default STT: %s" % default_speech_to_text)
|
|
|
- return default_speech_to_text
|
|
|
- except KeyError:
|
|
|
- raise DefaultSpeechToTextNotFound("Attribute default_speech_to_text not found in settings")
|
|
|
-
|
|
|
- def _get_stt_args(self, default_stt_plugin_name):
|
|
|
- """
|
|
|
- Return argument set for the current STT engine
|
|
|
- :param default_stt_plugin: Name of the STT engine
|
|
|
- :return:
|
|
|
- """
|
|
|
- def find(lst, key):
|
|
|
- """
|
|
|
- Find a key name in a list
|
|
|
- :param lst: list()
|
|
|
- :param key: key name to find i the list
|
|
|
- :return: Return the dict
|
|
|
- """
|
|
|
- for el in lst:
|
|
|
- try:
|
|
|
- if el[key]:
|
|
|
- return el[key]
|
|
|
- except TypeError:
|
|
|
- pass
|
|
|
- except KeyError:
|
|
|
- pass
|
|
|
- return None
|
|
|
-
|
|
|
- try:
|
|
|
- speechs_to_text = self.settings["speech_to_text"]
|
|
|
- except KeyError:
|
|
|
- raise NoSpeechToTextConfiguration("No speech_to_text in settings")
|
|
|
-
|
|
|
- logging.debug("Settings file content: %s" % speechs_to_text)
|
|
|
- # get args
|
|
|
- args = find(speechs_to_text, default_stt_plugin_name)
|
|
|
-
|
|
|
- logging.debug("Args for %s STT: %s" % (default_stt_plugin_name, args))
|
|
|
-
|
|
|
- return args
|
|
|
-
|
|
|
def _run_stt_plugin(self, stt_plugin, parameters=None):
|
|
|
"""
|
|
|
Dynamic loading of a STT module
|
|
@@ -90,7 +32,7 @@ class OrderListener:
|
|
|
:param parameters: Parameter of the module
|
|
|
:return:
|
|
|
"""
|
|
|
- print "Running STT %s with parameter %s" % (stt_plugin, parameters)
|
|
|
+ logging.debug("Running STT %s with parameter %s" % (stt_plugin, parameters))
|
|
|
mod = __import__('stt', fromlist=[stt_plugin])
|
|
|
|
|
|
klass = getattr(mod, stt_plugin)
|