Explorar el Código

add cache to settings

nico hace 8 años
padre
commit
66c24dc05f
Se han modificado 3 ficheros con 24 adiciones y 2 borrados
  1. 20 1
      core/ConfigurationManager/SettingLoader.py
  2. 2 1
      core/Models/Settings.py
  3. 2 0
      settings.yml

+ 20 - 1
core/ConfigurationManager/SettingLoader.py

@@ -1,6 +1,7 @@
 from YAMLLoader import YAMLLoader
 import logging
 
+from core.FileManager import FileManager
 from core.Models.RestAPI import RestAPI
 from core.Models.Settings import Settings
 from core.Models.Stt import Stt
@@ -52,6 +53,7 @@ class SettingLoader(object):
         random_wake_up_answers = cls._get_random_wake_up_answers(settings)
         random_wake_up_sounds = cls._get_random_wake_up_sounds(settings)
         rest_api = cls._get_rest_api(settings)
+        cache_path = cls._get_cache_path(settings)
 
         # create a setting object
         setting_object = Settings(default_stt_name=default_stt_name,
@@ -62,7 +64,8 @@ class SettingLoader(object):
                                   triggers=triggers,
                                   random_wake_up_answers=random_wake_up_answers,
                                   random_wake_up_sounds=random_wake_up_sounds,
-                                  rest_api=rest_api)
+                                  rest_api=rest_api,
+                                  cache_path=cache_path)
         return setting_object
 
     @staticmethod
@@ -261,3 +264,19 @@ class SettingLoader(object):
             return rest_api_obj
         else:
             raise NullSettingException("rest_api settings cannot be null")
+
+    @classmethod
+    def _get_cache_path(cls, settings):
+        try:
+            cache_path = settings["cache_path"]
+        except KeyError, e:
+            raise SettingNotFound("%s setting not found" % e)
+
+        if cache_path is None:
+            raise NullSettingException("cache_path setting cannot be null")
+
+        # test if that path is usable
+        if FileManager.is_path_exists_or_creatable(cache_path):
+            return cache_path
+        else:
+            raise SettingInvalidException("The cache_path seems to be invalid: %s" % cache_path)

+ 2 - 1
core/Models/Settings.py

@@ -3,7 +3,7 @@
 class Settings(object):
     def __init__(self, default_tts_name=None, default_stt_name=None,
                  default_trigger_name=None, ttss=None, stts=None,
-                 random_wake_up_answers=None, random_wake_up_sounds=None, triggers=None, rest_api=None):
+                 random_wake_up_answers=None, random_wake_up_sounds=None, triggers=None, rest_api=None, cache_path=None):
         self.default_tts_name = default_tts_name
         self.default_stt_name = default_stt_name
         self.default_trigger_name = default_trigger_name
@@ -13,3 +13,4 @@ class Settings(object):
         self.random_wake_up_sounds = random_wake_up_sounds
         self.triggers = triggers
         self.rest_api = rest_api
+        self.cache_path = cache_path

+ 2 - 0
settings.yml

@@ -49,6 +49,8 @@ speech_to_text:
 # ---------------------------
 # This is the default TTS that will be used by Kalliope to talk.
 default_text_to_speech: "pico2wave"
+# where we store generated audio files from TTS engine to reuse them
+cache_path: "/tmp/kalliope_tts_cache"
 
 # Text to Spreech engines configuration
 # Available engine are: