瀏覽代碼

replace configuration manager by SettingLoader

nico 8 年之前
父節點
當前提交
9e50100e5a

+ 2 - 0
core/ConfigurationManager/SettingLoader.py

@@ -185,3 +185,5 @@ class SettingLoader(object):
         # The list cannot be empty
         if random_wake_up_answers_list is None:
             raise NullSettingException("random_wake_up_answers settings is null")
+
+        return random_wake_up_answers_list

+ 0 - 1
core/ConfigurationManager/__init__.py

@@ -1,3 +1,2 @@
 from YAMLLoader import YAMLLoader
-from .ConfigurationManager import ConfigurationManager
 from .SettingLoader import SettingLoader

+ 4 - 5
core/MainController.py

@@ -1,7 +1,7 @@
+from core.ConfigurationManager import SettingLoader
 from core.JarvisTrigger import JarvisTrigger
 from core.OrderAnalyser import OrderAnalyser
 from core.OrderListener import OrderListener
-from core.ConfigurationManager.ConfigurationManager import ConfigurationManager
 
 from neurons import Say
 
@@ -9,8 +9,8 @@ from neurons import Say
 class MainController:
     def __init__(self, brain_file=None):
         self.brain_file = brain_file
-        # Manage Global Configuration
-        self.conf = ConfigurationManager().get_settings()
+        # get global configuration
+        self.settings = SettingLoader.get_settings()
 
         # create an order listener object
         self.order_listener = OrderListener(self.get_analyse_order_callback())
@@ -38,8 +38,7 @@ class MainController:
         """
         # pause the snowboy process
         self.pause_jarvis_trigger()
-        random_answers = self.conf["random_wake_up_answers"]
-        Say(message=random_answers)
+        Say(message=self.settings.random_wake_up_answers)
         self.order_listener.load_stt_plugin()
 
     def analyse_order(self, order):

+ 8 - 2
core/NeuronModule.py

@@ -41,11 +41,13 @@ class NeuronModule(object):
         child_name = self.__class__.__name__
         logger.debug("NeuronModule called from class %s with parameters: %s" % (child_name, kwargs))
 
+        self.settings = SettingLoader.get_settings()
+
         # check if the user has overrider the TTS
         tts = kwargs.get('tts', None)
         if tts is None:
             # No tts provided,  we load the default one
-            self.tts = SettingLoader().get_default_text_to_speech()
+            self.tts = self.settings.default_tts_name
         else:
             self.tts = tts
 
@@ -87,7 +89,11 @@ class NeuronModule(object):
         if message is not None:
             # get an instance of the target TTS
             tts_instance = self._get_tts_instance(self.tts)
-            tts_args = SettingLoader().get_tts_args(self.tts)
+            tts_args = None
+            for tts_object in self.settings.ttss:
+                if tts_object.name == self.tts:
+                    tts_args = tts_object.parameters
+
             # change the cache settings with the one precised for the current neuron
             if self.override_cache:
                 tts_args = self._update_cache_var(self.override_cache, tts_args)

+ 6 - 6
core/OrderListener.py

@@ -1,9 +1,8 @@
 import logging
 import os
 from cffi import FFI as _FFI
-import sys
 
-from core import ConfigurationManager
+from core.ConfigurationManager import SettingLoader
 
 logging.basicConfig()
 logger = logging.getLogger("jarvis")
@@ -25,14 +24,15 @@ class OrderListener:
         self._ignore_stderr()
         self.stt = stt
         self.callback = callback
-        # self.settings = main_controller.conf.settingLoader.get_config()
-        self.settings = ConfigurationManager().get_settings()
+        self.settings = SettingLoader.get_settings()
 
     def load_stt_plugin(self):
         if self.stt is None:
-            self.stt = ConfigurationManager.get_default_speech_to_text()
+            self.stt = self.settings.default_stt_name
 
-        stt_args = ConfigurationManager.get_stt_args(self.stt)
+        for stt_object in self.settings.stts:
+            if stt_object.name == self.stt:
+                stt_args = stt_object.parameters
 
         # capitalizes the first letter (because classes have first letter upper case)
         default_stt_plugin = self.stt.capitalize()

+ 8 - 15
core/ShellGui.py

@@ -3,8 +3,8 @@ import logging
 from dialog import Dialog
 import locale
 
-from core import ConfigurationManager
 from core import OrderListener
+from core.ConfigurationManager import SettingLoader
 from neurons import Say
 
 logging.basicConfig()
@@ -14,7 +14,7 @@ logger = logging.getLogger("jarvis")
 class ShellGui:
     def __init__(self):
         # get settings
-        self.conf = ConfigurationManager().get_settings()
+        self.settings = SettingLoader.get_settings()
         locale.setlocale(locale.LC_ALL, '')
 
         self.d = Dialog(dialog="dialog")
@@ -42,7 +42,7 @@ class ShellGui:
 
     def show_stt_test_menu(self):
         # we get STT from settings
-        stt_list = ConfigurationManager.get_stt_list()
+        stt_list = self.settings.stts
         logger.debug("Loaded stt list: %s" % str(stt_list))
         choices = self._get_choices_tuple_from_list(stt_list)
 
@@ -76,7 +76,7 @@ class ShellGui:
 
         if continue_bool:
             # we get TTS from settings
-            tts_list = ConfigurationManager.get_tts_list()
+            tts_list = self.settings.ttss
 
             # create a list of tuple that can be used by the dialog menu
             choices = self._get_choices_tuple_from_list(tts_list)
@@ -104,22 +104,15 @@ class ShellGui:
     def _get_choices_tuple_from_list(list_to_convert):
         """
         Return a list of tup that can be used in Dialog menu
-        :param stt_list:
+        :param list_to_convert: List of object to convert into tuple
         :return:
         """
         # create a list of tuple that can be used by the dialog menu
         choices = list()
         for el in list_to_convert:
-            try:
-                for name, settings in el.iteritems():
-                    tup = (str(name), str(settings))
-                    choices.append(tup)
-                    logger.debug("Add stt to the list: %s with parameters: %s" % (str(el), str(settings)))
-            except AttributeError:
-                logger.debug("Add stt to the list: %s" % str(el))
-                # sometime there is no settings for the STT key
-                tup = (str(el), str("No settings"))
-                choices.append(tup)
+            tup = (str(el.name), str(el.parameters))
+            choices.append(tup)
+            logger.debug("Add el to the list: %s with parameters: %s" % (str(el.name), str(el.parameters)))
         return choices
 
     def callback_stt(self, audio):

+ 1 - 2
core/__init__.py

@@ -1,4 +1,3 @@
-from core.ConfigurationManager.ConfigurationManager import ConfigurationManager
 from core.JarvisTrigger import JarvisTrigger
 from core.OrderAnalyser import OrderAnalyser
 from core.OrderListener import OrderListener
@@ -6,4 +5,4 @@ from core.AudioPlayer import AudioPlayer
 from core.ShellGui import ShellGui
 from core.Cache import Cache
 from core.FileManager import FileManager
-from core.Utils import Utils
+from core.Utils import Utils

+ 7 - 3
settings.yml

@@ -4,10 +4,9 @@
 # Use YAML syntax
 # ---------------------------
 
-# This is the snowboy hotword file used to wake up and listen for a new order
-trigger:
-  name: "jarviss.pmdl"
 
+# This is the trigger that will catch your magic work to wake up JARVIS
+default_trigger: "snowboy"
 # This is the STT that will be used by default
 default_speech_to_text: "google"
 # This is the default TTS that will be used by JARVIS to talk.
@@ -42,3 +41,8 @@ text_to_speech:
       language: "fr"
       voice: "michel"
       cache: True
+
+
+triggers:
+  - snowboy:
+      pmdl_file: "jarviss.pmdl"