Browse Source

[Refacto] rename settings mute to deaf

ThiBuff 7 years ago
parent
commit
c85519513a

+ 4 - 4
Docs/kalliope_cli.md

@@ -96,18 +96,18 @@ You can combine the options together like, for example:
 kalliope start --run-synapse "say-hello" --brain-file /home/me/my_other_brain.yml
 ```
 
-### --muted
+### --deaf
 
-Starts Kalliope in a muted state.
+Starts Kalliope in a deaf state, the trigger is paused.
 
 Example of use
 ```bash
-kalliope start --muted
+kalliope start --deaf
 ```
 
 You can combine the options together like, for example:
 ```bash
-kalliope start --muted --brain-file /home/me/my_other_brain.yml
+kalliope start --deaf --brain-file /home/me/my_other_brain.yml
 ```
 
 ### --debug

+ 8 - 8
Docs/rest_api.md

@@ -12,8 +12,8 @@ Kalliope provides the REST API to manage the synapses. For configuring the API r
 | POST   | /synapses/start/id/<synapse_name> | Run a synapse by its name          |
 | POST   | /synapses/start/order             | Run a synapse from a text order    |
 | POST   | /synapses/start/audio             | Run a synapse from an audio sample |
-| GET    | /mute                             | Get the current mute status        |
-| POST   | /mute                             | Switch the mute status             |
+| GET    | /deaf                             | Get the current deaf status        |
+| POST   | /deaf                             | Switch the deaf status             |
 
 ## Curl examples
 
@@ -390,37 +390,37 @@ The ```"status": "waiting_for_answer"``` indicates that it waits for a response,
 
 And now the status is complete. This works also when you have nested neurotransmitter neurons, you just need to keep monitoring the status from the API answer.
 
-### Get mute status
+### Get deaf status
 
 Normal response codes: 200
 Error response codes: unauthorized(401), Bad request(400)
 
 Curl command:
 ```bash
-curl -i --user admin:secret  -X GET  http://127.0.0.1:5000/mute
+curl -i --user admin:secret  -X GET  http://127.0.0.1:5000/deaf
 ```
 
 Output example:
 ```JSON
 {
-  "mute": true
+  "deaf": true
 }
 ```
 
-### Switch mute status
+### Switch deaf status
 
 Normal response codes: 200
 Error response codes: unauthorized(401), Bad request(400)
 
 Curl command:
 ```bash
-curl -i -H "Content-Type: application/json" --user admin:secret  -X POST -d '{"mute": "True"}' http://127.0.0.1:5000/mute
+curl -i -H "Content-Type: application/json" --user admin:secret  -X POST -d '{"deaf": "True"}' http://127.0.0.1:5000/deaf
 ```
 
 Output example:
 ```JSON
 {
-  "mute": true
+  "deaf": true
 }
 ```
 

+ 2 - 2
Docs/settings.md

@@ -246,8 +246,8 @@ List of available hook
 | on_order_found         | When the pronounced order has been found in the brain           |
 | on_order_not_found     | When the pronounced order has not been found in the brain       |
 | on_processed_synapses  | When all neurons in synapses have been processed                |
-| on_mute                | When Kalliope switches from non muted to muted                  |
-| on_unmute              | When Kalliope switches from muted to non muted                  |
+| on_deaf                | When Kalliope switches from non deaf to deaf                    |
+| on_undeaf              | When Kalliope switches from deaf to non deaf                    |
 | on_start_speaking      | When Kalliope starts speaking via the text to speech engine     |
 | on_stop_speaking       | When Kalliope stops speaking                                    |
 

+ 3 - 3
Tests/settings/settings_test.yml

@@ -92,8 +92,8 @@ hooks:
   on_order_not_found:
     - "order-not-found-synapse"
   on_processed_synapses:
-  on_mute: []
-  on_unmute: []
+  on_deaf: []
+  on_undeaf: []
   on_start_speaking:
   on_stop_speaking:
 
@@ -114,4 +114,4 @@ var_files:
   - "../Tests/settings/variables.yml"
 
 start_options:
-  muted: True
+  deaf: True

+ 2 - 2
Tests/test_hook_manager.py

@@ -77,11 +77,11 @@ class TestInit(unittest.TestCase):
     def test_on_processed_synapses(self):
         self.assertIsNone(HookManager.on_processed_synapses())
 
-    def test_on_mute(self):
+    def test_on_deaf(self):
         """
         test that empty list of synapse return none
         """
-        self.assertIsNone(HookManager.on_mute())
+        self.assertIsNone(HookManager.on_deaf())
 
 
 if __name__ == '__main__':

+ 4 - 4
Tests/test_models.py

@@ -259,7 +259,7 @@ class TestModels(unittest.TestCase):
                                 resources=None,
                                 variables={"key1": "val1"},
                                 recognition_options=recognition_options,
-                                start_options={'muted': False})
+                                start_options={'deaf': False})
             setting1.kalliope_version = "0.4.5"
 
             setting2 = Settings(default_tts_name="accapela",
@@ -274,7 +274,7 @@ class TestModels(unittest.TestCase):
                                 resources=None,
                                 variables={"key1": "val1"},
                                 recognition_options=recognition_options,
-                                start_options={'muted': False})
+                                start_options={'deaf': False})
             setting2.kalliope_version = "0.4.5"
 
             setting3 = Settings(default_tts_name="pico2wav",
@@ -290,7 +290,7 @@ class TestModels(unittest.TestCase):
                                 resources=None,
                                 variables={"key1": "val1"},
                                 recognition_options=recognition_options,
-                                start_options={'muted': False})
+                                start_options={'deaf': False})
             setting3.kalliope_version = "0.4.5"
 
             expected_result_serialize = {
@@ -318,7 +318,7 @@ class TestModels(unittest.TestCase):
                 'triggers': ['snowboy'],
                 'players': ['mplayer'],
                 'recognition_options': {'energy_threshold': 4000, 'adjust_for_ambient_noise_second': 0},
-                'start_options': {'muted': False}
+                'start_options': {'deaf': False}
             }
 
             self.maxDiff = None

+ 11 - 11
Tests/test_settings_loader.py

@@ -51,15 +51,15 @@ class TestSettingLoader(unittest.TestCase):
                 {'voxygen': {'voice': 'Agnes', 'cache': True}}
                 ],
             'var_files': ["../Tests/settings/variables.yml"],
-            'start_options': {'muted': True},
+            'start_options': {'deaf': True},
             'hooks': {'on_waiting_for_trigger': 'test',
                       'on_stop_listening': None,
                       'on_start_listening': None,
                       'on_order_found': None,
                       'on_start': ['on-start-synapse', 'bring-led-on'],
-                      'on_unmute': [],
+                      'on_undeaf': [],
                       'on_triggered': ['on-triggered-synapse'],
-                      'on_mute': [],
+                      'on_deaf': [],
                       'on_order_not_found': [
                           'order-not-found-synapse'],
                       'on_processed_synapses': None,
@@ -124,7 +124,7 @@ class TestSettingLoader(unittest.TestCase):
             "test": "kalliope"
         }
         settings_object.start_options = {
-            "muted": True
+            "deaf": True
         }
         settings_object.machine = platform.machine()
         settings_object.recognition_options = RecognitionOptions()
@@ -133,9 +133,9 @@ class TestSettingLoader(unittest.TestCase):
                                  'on_start_listening': None,
                                  'on_order_found': None,
                                  'on_start': ['on-start-synapse', 'bring-led-on'],
-                                 'on_unmute': [],
+                                 'on_undeaf': [],
                                  'on_triggered': ['on-triggered-synapse'],
-                                 'on_mute': [],
+                                 'on_deaf': [],
                                  'on_order_not_found': [
                                      'order-not-found-synapse'],
                                  'on_processed_synapses': None,
@@ -223,7 +223,7 @@ class TestSettingLoader(unittest.TestCase):
 
     def test_get_start_options(self):
         expected_result = {
-            "muted": True
+            "deaf": True
         }
         sl = SettingLoader(file_path=self.settings_file_to_test)
         self.assertEqual(expected_result,
@@ -245,8 +245,8 @@ class TestSettingLoader(unittest.TestCase):
             "on_stop_listening": None,
             "on_order_found": None,
             "on_order_not_found": None,
-            "on_mute": None,
-            "on_unmute": None,
+            "on_deaf": None,
+            "on_undeaf": None,
             "on_start_speaking": None,
             "on_stop_speaking": None
         }
@@ -266,8 +266,8 @@ class TestSettingLoader(unittest.TestCase):
             "on_stop_listening": None,
             "on_order_found": None,
             "on_order_not_found": None,
-            "on_mute": None,
-            "on_unmute": None,
+            "on_deaf": None,
+            "on_undeaf": None,
             "on_start_speaking": None,
             "on_stop_speaking": None
         }

+ 2 - 2
brain_examples/mute.yml

@@ -1,10 +1,10 @@
 
-- name: "mute-synapse"
+- name: "deaf-synapse"
   signals:
     - order: "stop listening"
   neurons:
     - say:
         message:
           - "I stop hearing you, sir"
-    - mute:
+    - deaf:
         status: True

+ 4 - 4
kalliope/__init__.py

@@ -63,7 +63,7 @@ def parse_args(args):
     parser.add_argument("--tts-name", help="TTS name to uninstall")
     parser.add_argument("--trigger-name", help="Trigger name to uninstall")
     parser.add_argument("--signal-name", help="Signal name to uninstall")
-    parser.add_argument("--muted", action='store_true', help="Starts Kalliope muted")
+    parser.add_argument("--deaf", action='store_true', help="Starts Kalliope deaf")
     parser.add_argument('-v', '--version', action='version',
                         version='Kalliope ' + version_str)
 
@@ -155,9 +155,9 @@ def main():
                                                             is_api_call=False)
 
         if (parser.run_synapse is None) and (parser.run_order is None):
-            # if --muted
-            if parser.muted:
-                settings.start_options['muted'] = True
+            # if --deaf
+            if parser.deaf:
+                settings.start_options['deaf'] = True
 
             # start rest api
             start_rest_api(settings, brain)

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

@@ -642,7 +642,7 @@ class SettingLoader(with_metaclass(Singleton, object)):
         :rtype: dict
         """
         options = dict()
-        muted = False
+        deaf = False
 
         try:
             start_options = settings["start_options"]
@@ -651,11 +651,11 @@ class SettingLoader(with_metaclass(Singleton, object)):
 
         if start_options is not None:
             try:
-                muted = start_options['muted']
+                deaf = start_options['deaf']
             except KeyError:
-                muted = False
+                deaf = False
 
-        options['muted'] = muted
+        options['deaf'] = deaf
 
         logger.debug("Start options: %s" % options)
         return options
@@ -684,8 +684,8 @@ class SettingLoader(with_metaclass(Singleton, object)):
             "on_stop_listening",
             "on_order_found",
             "on_order_not_found",
-            "on_mute",
-            "on_unmute",
+            "on_deaf",
+            "on_undeaf",
             "on_start_speaking",
             "on_stop_speaking"
         ]

+ 4 - 4
kalliope/core/HookManager.py

@@ -40,12 +40,12 @@ class HookManager(object):
         return cls.execute_synapses_in_hook_name("on_processed_synapses")
 
     @classmethod
-    def on_mute(cls):
-        return cls.execute_synapses_in_hook_name("on_mute")
+    def on_deaf(cls):
+        return cls.execute_synapses_in_hook_name("on_deaf")
 
     @classmethod
-    def on_unmute(cls):
-        return cls.execute_synapses_in_hook_name("on_unmute")
+    def on_undeaf(cls):
+        return cls.execute_synapses_in_hook_name("on_undeaf")
 
     @classmethod
     def on_start_speaking(cls):

+ 1 - 1
kalliope/core/NeuronModule.py

@@ -105,7 +105,7 @@ class NeuronModule(object):
         self.tts_message = None
         # if the current call is api one
         self.is_api_call = kwargs.get('is_api_call', False)
-        # if the current call want to mute kalliope
+        # if the current call want to deaf kalliope
         self.no_voice = kwargs.get('no_voice', False)
         # boolean to know id the synapse is waiting for an answer
         self.is_waiting_for_answer = False

+ 17 - 17
kalliope/core/RestAPI/FlaskAPI.py

@@ -73,8 +73,8 @@ class FlaskAPI(threading.Thread):
         self.app.add_url_rule('/synapses/start/order', view_func=self.run_synapse_by_order, methods=['POST'])
         self.app.add_url_rule('/synapses/start/audio', view_func=self.run_synapse_by_audio, methods=['POST'])
         self.app.add_url_rule('/shutdown/', view_func=self.shutdown_server, methods=['POST'])
-        self.app.add_url_rule('/mute/', view_func=self.get_mute, methods=['GET'])
-        self.app.add_url_rule('/mute/', view_func=self.set_mute, methods=['POST'])
+        self.app.add_url_rule('/deaf/', view_func=self.get_deaf, methods=['GET'])
+        self.app.add_url_rule('/deaf/', view_func=self.set_deaf, methods=['POST'])
 
     def run(self):
         self.app.run(host='0.0.0.0', port=int(self.port), debug=True, threaded=True, use_reloader=False)
@@ -309,55 +309,55 @@ class FlaskAPI(threading.Thread):
         return "Shutting down..."
 
     @requires_auth
-    def get_mute(self):
+    def get_deaf(self):
         """
         Return the current trigger status
 
         Curl test
-        curl -i --user admin:secret  -X GET  http://127.0.0.1:5000/mute
+        curl -i --user admin:secret  -X GET  http://127.0.0.1:5000/deaf
         """
 
-        # find the order signal and call the mute method
+        # find the order signal and call the deaf method
         signal_order = SignalLauncher.get_order_instance()
         if signal_order is not None:
             data = {
-                "mute": signal_order.get_mute_status()
+                "deaf": signal_order.get_deaf_status()
             }
             return jsonify(data), 200
 
         # if no Order instance
         data = {
-            "error": "Mute status unknow"
+            "error": "deaf status unknow"
         }
         return jsonify(error=data), 400
 
     @requires_auth
-    def set_mute(self):
+    def set_deaf(self):
         """
-        Set the trigger status (muted or not)
+        Set the trigger status (deaf or not)
 
         Curl test:
         curl -i -H "Content-Type: application/json" --user admin:secret  -X POST \
-        -d '{"mute": "True"}' http://127.0.0.1:5000/mute
+        -d '{"deaf": "True"}' http://127.0.0.1:5000/deaf
         """
 
-        if not request.get_json() or 'mute' not in request.get_json():
+        if not request.get_json() or 'deaf' not in request.get_json():
             abort(400)
 
-        # get mute if present
-        mute = self.get_boolean_flag_from_request(request, boolean_flag_to_find="mute")
+        # get deaf if present
+        deaf = self.get_boolean_flag_from_request(request, boolean_flag_to_find="deaf")
 
-        # find the order signal and call the mute method
+        # find the order signal and call the deaf method
         signal_order = SignalLauncher.get_order_instance()
         if signal_order is not None:
-            signal_order.set_mute_status(mute)
+            signal_order.set_deaf_status(deaf)
             data = {
-                "mute": signal_order.get_mute_status()
+                "deaf": signal_order.get_deaf_status()
             }
             return jsonify(data), 200
 
         data = {
-            "error": "Cannot switch mute status"
+            "error": "Cannot switch deaf status"
         }
         return jsonify(error=data), 400
 

+ 11 - 11
kalliope/neurons/mute/README.md → kalliope/neurons/deaf/README.md

@@ -1,12 +1,12 @@
-# Mute
+# Deaf
 
 ## Synopsis
 
-Mute control of kalliope. If set to True the trigger process will be stopped.
+Deaf control of kalliope. If set to True the trigger process will be stopped.
 
-Once this neuron is used, and Kalliope muted, the hotword is deactivated. Only ways to unmute are:
-- by calling the API (see [mute section](../../../Docs/rest_api.md#switch-mute-status))
-- If running on Raspberry, by using the unmute button. (See the section [Raspberry LED and mute button](../../../Docs/settings.md#raspberry-led-and-mute-button))
+Once this neuron is used, and Kalliope deaf, the hotword is deactivated. Only ways to undeaf are:
+- by calling the API (see [deaf section](../../../Docs/rest_api.md#switch-deaf-status))
+- If running on Raspberry, by using the undeaf button. (See the section [Raspberry LED and deaf button](../../../Docs/settings.md#raspberry-led-and-deaf-button))
 - by using another signals than a "vocal order" that call back this neuron with a status set to "False"
 - Restarting Kalliope
 
@@ -23,28 +23,28 @@ Not returned values
 
 ## Synapses example
 
-Mute Kalliope from a vocal order
+Deaf Kalliope from a vocal order
 ```yml
-- name: "mute-synapse"
+- name: "deaf-synapse"
   signals:
     - order: "stop listening"
   neurons:
     - say:
         message:
           - "I stop hearing you, sir"
-    - mute:
+    - deaf:
         status: True
 ```
 
-Unmute Kalliope from another signals. In the following example, a MQTT message is received
+Undeaf Kalliope from another signals. In the following example, a MQTT message is received
 ```yml
-- name: "unmute-synapse"
+- name: "undeaf-synapse"
   signals:
     - mqtt_subscriber:
         broker_ip: "127.0.0.1"
         topic: "/my/sensor"
   neurons:
-    - mute:
+    - deaf:
         status: False
     - say:
         message:

+ 0 - 0
kalliope/neurons/mute/__init__.py → kalliope/neurons/deaf/__init__.py


+ 4 - 4
kalliope/neurons/mute/mute.py → kalliope/neurons/deaf/deaf.py

@@ -7,10 +7,10 @@ logging.basicConfig()
 logger = logging.getLogger("kalliope")
 
 
-class Mute(NeuronModule):
+class Deaf(NeuronModule):
 
     def __init__(self, **kwargs):
-        super(Mute, self).__init__(**kwargs)
+        super(Deaf, self).__init__(**kwargs)
 
         self.status = kwargs.get('status', None)
 
@@ -18,7 +18,7 @@ class Mute(NeuronModule):
         if self._is_parameters_ok():
             signal_order = SignalLauncher.get_order_instance()
             if signal_order is not None:
-                signal_order.set_mute_status(self.status)
+                signal_order.set_deaf_status(self.status)
 
     def _is_parameters_ok(self):
         """
@@ -28,6 +28,6 @@ class Mute(NeuronModule):
         .. raises:: MissingParameterException
         """
         if self.status is None:
-            logger.debug("[Mute] You must specify a status with a boolean")
+            logger.debug("[Deaf] You must specify a status with a boolean")
             return False
         return True

+ 2 - 2
kalliope/settings.yml

@@ -119,8 +119,8 @@ hooks:
   on_order_found:
   on_order_not_found: "order-not-found-synapse"
   on_processed_synapses:
-  on_mute:
-  on_unmute:
+  on_deaf:
+  on_undeaf:
   on_start_speaking:
   on_stop_speaking:
 

+ 14 - 19
kalliope/signals/order/order.py

@@ -48,11 +48,7 @@ class Order(Thread):
         # save an instance of the trigger
         self.trigger_instance = None
         self.trigger_callback_called = False
-        self.is_trigger_muted = False
-
-        # If kalliope is asked to start muted
-        if self.settings.start_options['muted'] is True:
-            self.is_trigger_muted = True
+        self.is_trigger_deaf = self.settings.start_options['deaf']
 
         # save the current order listener
         self.order_listener = None
@@ -101,8 +97,8 @@ class Order(Thread):
         Method to print in debug that the main process is waiting for a trigger detection
         """
         logger.debug("[MainController] Entering state: %s" % self.state)
-        if self.is_trigger_muted:  # the user asked to mute inside the mute neuron
-            Utils.print_info("Kalliope is muted")
+        if self.is_trigger_deaf:  # the user asked to deaf inside the deaf neuron
+            Utils.print_info("Kalliope is deaf")
             self.trigger_instance.pause()
         else:
             Utils.print_info("Waiting for trigger detection")
@@ -180,26 +176,25 @@ class Order(Thread):
         # return to the state "unpausing_trigger"
         self.start_trigger()
 
-    def set_mute_status(self, muted=False):
+    def set_deaf_status(self, deaf=False):
         """
         Define is the trigger is listening or not
-        :param muted: Boolean. If true, kalliope is muted
+        :param deaf: Boolean. If true, kalliope is trigger is paused
         """
-        logger.debug("[MainController] Mute button pressed. Switch trigger process to muted: %s" % muted)
-        if muted:
+        logger.debug("[MainController] deaf button pressed. Switch trigger process to deaf : %s" % deaf)
+        self.is_trigger_deaf = deaf
+        if deaf:
             self.trigger_instance.pause()
-            self.is_trigger_muted = True
-            Utils.print_info("Kalliope now muted")
-            HookManager.on_mute()
+            Utils.print_info("Kalliope now deaf, trigger has been paused")
+            HookManager.on_deaf()
         else:
             self.trigger_instance.unpause()
-            self.is_trigger_muted = False
             Utils.print_info("Kalliope now listening for trigger detection")
-            HookManager.on_unmute()
+            HookManager.on_undeaf()
 
-    def get_mute_status(self):
+    def get_deaf_status(self):
         """
-        return the current state of the trigger (muted or not)
+        return the current state of the trigger (deaf or not)
         :return: Boolean
         """
-        return self.is_trigger_muted
+        return self.is_trigger_deaf