瀏覽代碼

[Refacto] Rename the option for STT speak recognition options

ThiBuff 7 年之前
父節點
當前提交
8fc98eec51

+ 5 - 5
Docs/settings.md

@@ -126,18 +126,18 @@ speech_to_text:
 
 Some arguments are required, some others are optional, please refer to the [STT documentation](stt.md) to know available parameters for each supported STT.
 
-### stt_options
+### recognition_options
 
 Represents a collection of speech recognition settings and functionality.
 ```yml
-stt_options:
+recognition_options:
   option_name: option_value
   option_name2: option_value2
 ```
 
 E.g
 ```yml
-stt_options:
+recognition_options:
   energy_threshold: 3000
 ```
 
@@ -156,7 +156,7 @@ If you're having trouble with the recognizer trying to recognize words even when
 If you're having trouble with the recognizer not recognizing your words when you are speaking, try tweaking this to a lower value. 
 For example, a sensitive microphone or microphones in louder rooms might have a ambient energy level of up to 4000.
 ```yml
-stt_options:
+recognition_options:
   energy_threshold: 4000
 ```
 
@@ -169,7 +169,7 @@ When set, the `energy_threshold` parameter is overridden by the returned value o
 This value should be at least 0.5 in order to get a representative sample of the ambient noise.
 
 ```yml
-stt_options:
+recognition_options:
   adjust_for_ambient_noise_second: 1
 ```
 

+ 6 - 6
Tests/test_models.py

@@ -4,7 +4,7 @@ import mock
 
 from kalliope.core.Models.Player import Player
 from kalliope.core.Models.Signal import Signal
-from kalliope.core.Models.SttOptions import SttOptions
+from kalliope.core.Models.RecognitionOptions import RecognitionOptions
 from kalliope.core.Models.Tts import Tts
 
 from kalliope.core.Models.Trigger import Trigger
@@ -244,7 +244,7 @@ class TestModels(unittest.TestCase):
                                 active=True,
                                 port=5000, allowed_cors_origin="*")
 
-            stt_options = SttOptions()
+            recognition_options = RecognitionOptions()
 
             setting1 = Settings(default_tts_name="pico2wav",
                                 default_stt_name="google",
@@ -264,7 +264,7 @@ class TestModels(unittest.TestCase):
                                 default_synapse="default_synapse",
                                 resources=None,
                                 variables={"key1": "val1"},
-                                stt_options=stt_options)
+                                recognition_options=recognition_options)
             setting1.kalliope_version = "0.4.5"
 
             setting2 = Settings(default_tts_name="accapela",
@@ -284,7 +284,7 @@ class TestModels(unittest.TestCase):
                                 default_synapse="my_default_synapse",
                                 resources=None,
                                 variables={"key1": "val1"},
-                                stt_options=stt_options)
+                                recognition_options=recognition_options)
             setting2.kalliope_version = "0.4.5"
 
             setting3 = Settings(default_tts_name="pico2wav",
@@ -305,7 +305,7 @@ class TestModels(unittest.TestCase):
                                 default_synapse="default_synapse",
                                 resources=None,
                                 variables={"key1": "val1"},
-                                stt_options=stt_options)
+                                recognition_options=recognition_options)
             setting3.kalliope_version = "0.4.5"
 
             expected_result_serialize = {
@@ -338,7 +338,7 @@ class TestModels(unittest.TestCase):
                 'triggers': ['snowboy'],
                 'rpi_settings': None,
                 'players': ['mplayer'],
-                'stt_options': {'energy_threshold': 4000, 'adjust_for_ambient_noise_second': 0}
+                'recognition_options': {'energy_threshold': 4000, 'adjust_for_ambient_noise_second': 0}
             }
 
             self.assertDictEqual(expected_result_serialize, setting1.serialize())

+ 2 - 2
Tests/test_settings_loader.py

@@ -11,7 +11,7 @@ from kalliope.core.Models.Player import Player
 from kalliope.core.Models.RestAPI import RestAPI
 from kalliope.core.Models.Settings import Settings
 from kalliope.core.Models.Stt import Stt
-from kalliope.core.Models.SttOptions import SttOptions
+from kalliope.core.Models.RecognitionOptions import RecognitionOptions
 from kalliope.core.Models.Trigger import Trigger
 from kalliope.core.Models.Tts import Tts
 
@@ -120,7 +120,7 @@ class TestSettingLoader(unittest.TestCase):
             "test": "kalliope"
         }
         settings_object.machine = platform.machine()
-        settings_object.stt_options = SttOptions()
+        settings_object.recognition_options = RecognitionOptions()
 
         sl = SettingLoader(file_path=self.settings_file_to_test)
 

+ 16 - 16
kalliope/core/ConfigurationManager/SettingLoader.py

@@ -3,7 +3,7 @@ import os
 from six import with_metaclass
 
 from kalliope.core.Models.RpiSettings import RpiSettings
-from kalliope.core.Models.SttOptions import SttOptions
+from kalliope.core.Models.RecognitionOptions import RecognitionOptions
 from .YAMLLoader import YAMLLoader
 from kalliope.core.Models.Resources import Resources
 from kalliope.core.Utils.Utils import Utils
@@ -119,7 +119,7 @@ class SettingLoader(with_metaclass(Singleton, object)):
         resources = self._get_resources(settings)
         variables = self._get_variables(settings)
         rpi_settings = self._get_rpi_settings(settings)
-        stt_options = self._get_stt_options(settings)
+        recognition_options = self._get_recognition_options(settings)
 
         # Load the setting singleton with the parameters
         setting_object.default_tts_name = default_tts_name
@@ -141,7 +141,7 @@ class SettingLoader(with_metaclass(Singleton, object)):
         setting_object.resources = resources
         setting_object.variables = variables
         setting_object.rpi_settings = rpi_settings
-        setting_object.stt_options = stt_options
+        setting_object.recognition_options = recognition_options
 
         return setting_object
 
@@ -789,28 +789,28 @@ class SettingLoader(with_metaclass(Singleton, object)):
             return None
 
     @staticmethod
-    def _get_stt_options(settings):
+    def _get_recognition_options(settings):
         """
         return the value of stt_threshold
         :param settings: The loaded YAML settings file
         :return: integer or 1200 by default if not set
         """
-        stt_options = SttOptions()
+        recognition_options = RecognitionOptions()
 
         try:
-            stt_options_dict = settings["stt_options"]
+            recognition_options_dict = settings["RecognitionOptions"]
 
-            if "energy_threshold" in stt_options_dict:
-                stt_options.energy_threshold = stt_options_dict["energy_threshold"]
-                logger.debug("[SettingsLoader] energy_threshold set to %s" % stt_options.energy_threshold)
-            if "adjust_for_ambient_noise_second" in stt_options_dict:
-                stt_options.adjust_for_ambient_noise_second = stt_options_dict["adjust_for_ambient_noise_second"]
+            if "energy_threshold" in recognition_options_dict:
+                recognition_options.energy_threshold = recognition_options_dict["energy_threshold"]
+                logger.debug("[SettingsLoader] energy_threshold set to %s" % recognition_options.energy_threshold)
+            if "adjust_for_ambient_noise_second" in recognition_options_dict:
+                recognition_options.adjust_for_ambient_noise_second = recognition_options_dict["adjust_for_ambient_noise_second"]
                 logger.debug("[SettingsLoader] adjust_for_ambient_noise_second set to %s"
-                             % stt_options.adjust_for_ambient_noise_second)
-            return stt_options
+                             % recognition_options.adjust_for_ambient_noise_second)
+            return recognition_options
 
         except KeyError:
-            logger.debug("[SettingsLoader] no stt_options defined. Set to default")
+            logger.debug("[SettingsLoader] no recognition_options defined. Set to default")
 
-        logger.debug("[SettingsLoader] stt_options: %s" % str(stt_options))
-        return stt_options
+        logger.debug("[SettingsLoader] recognition_options: %s" % str(recognition_options))
+        return recognition_options

+ 2 - 2
kalliope/core/Models/SttOptions.py → kalliope/core/Models/RecognitionOptions.py

@@ -1,6 +1,6 @@
-class SttOptions(object):
+class RecognitionOptions(object):
     """
-    This Class is representing a Speech To Text (STT) element with name and parameters
+    This Class is representing a Speech To Text (STT) Recognition elements with name and parameters
 
     .. note:: must be defined in the settings.yml
     """

+ 3 - 3
kalliope/core/Models/Settings.py

@@ -28,7 +28,7 @@ class Settings(object):
                  resources=None,
                  variables=None,
                  rpi_settings=None,
-                 stt_options=None):
+                 recognition_options=None):
 
         self.default_tts_name = default_tts_name
         self.default_stt_name = default_stt_name
@@ -51,7 +51,7 @@ class Settings(object):
         self.machine = platform.machine()   # can be x86_64 or armv7l
         self.kalliope_version = current_kalliope_version
         self.rpi_settings = rpi_settings
-        self.stt_options = stt_options
+        self.recognition_options = recognition_options
 
     def serialize(self):
         """
@@ -83,7 +83,7 @@ class Settings(object):
             'machine': self.machine,
             'kalliope_version': self.kalliope_version,
             'rpi_settings': self.rpi_settings.serialize() if self.rpi_settings is not None else None,
-            'stt_options': self.stt_options.serialize() if self.stt_options is not None else None,
+            'recognition_options': self.recognition_options.serialize() if self.recognition_options is not None else None,
         }
 
     def __str__(self):

+ 1 - 1
kalliope/settings.yml

@@ -26,7 +26,7 @@ triggers:
 default_speech_to_text: "google"
 
 # Speech to text options
-#stt_options:
+#recognition_options:
 #  energy_threshold: 4000
 #  adjust_for_ambient_noise_second: 1
 

+ 6 - 6
kalliope/stt/Utils.py

@@ -32,21 +32,21 @@ class SpeechRecognition(Thread):
         if audio_file is None:
             # audio file not set, we need to capture a sample from the microphone
             with self.microphone as source:
-                if self.settings.stt_options.adjust_for_ambient_noise_second > 0:
+                if self.settings.recognition_options.adjust_for_ambient_noise_second > 0:
                     # threshold is calculated from capturing ambient sound
                     logger.debug("[SpeechRecognition] threshold calculated by "
                                  "capturing ambient noise during %s seconds" %
-                                 self.settings.stt_options.adjust_for_ambient_noise_second)
+                                 self.settings.recognition_options.adjust_for_ambient_noise_second)
                     Utils.print_info("[SpeechRecognition] capturing ambient sound during %s seconds" %
-                                     self.settings.stt_options.adjust_for_ambient_noise_second)
+                                     self.settings.recognition_options.adjust_for_ambient_noise_second)
                     self.recognizer.adjust_for_ambient_noise(source,
                                                              duration=self.settings.
-                                                             stt_options.adjust_for_ambient_noise_second)
+                                                             recognition_options.adjust_for_ambient_noise_second)
                 else:
                     # threshold is defined manually
                     logger.debug("[SpeechRecognition] threshold defined by settings: %s" %
-                                 self.settings.stt_options.energy_threshold)
-                    self.recognizer.energy_threshold = self.settings.stt_options.energy_threshold
+                                 self.settings.recognition_options.energy_threshold)
+                    self.recognizer.energy_threshold = self.settings.recognition_options.energy_threshold
 
                 Utils.print_info("Threshold set to: %s" % self.recognizer.energy_threshold)
         else: