Parcourir la source

Merge pull request #163 from bacardi55/dev

Implement #140 - Startup sound/sentence when ready to listen
Nicolas Marcq il y a 8 ans
Parent
commit
7728976a07

+ 45 - 1
Docs/settings.md

@@ -134,7 +134,7 @@ Some arguments are required, some other optional, please refer to the [TTS docum
 When Kalliope detects your trigger/hotword/magic word, it lets you know that it's operational and now waiting for order. It's done by answering randomly
 one of the sentences provided in the variable random_wake_up_answers.
 
-This variable must contain a list of strings as shownbellow
+This variable must contain a list of strings as shown bellow
 ```
 random_wake_up_answers:
   - "You sentence"
@@ -177,6 +177,50 @@ random_wake_up_sounds:
 E.g: `# random_wake_up_answers:`
 
 
+## On ready answers configuration
+
+#### random_on_ready_answers (optional)
+When Kalliope is ready, it lets you know that it's operational and now waiting for order. It's done by answering randomly
+one of the sentences provided in the variable random_on_ready_answers.
+
+This variable must contain a list of strings as shown bellow
+```
+random_on_ready_answers:
+  - "Your sentence"
+  - "Another sentence"
+```
+
+E.g
+```
+random_on_ready_answers:
+  - "I am ready"
+  - "Let's roll"
+```
+
+#### random_on_ready_sounds (optional)
+You can play a sound when Kalliope is ready instead of saying something from the `random_on_ready_answers`.
+Place here a list of full paths of the sound files you want to use. Otherwise, you can use some default sounds provided by Kalliope which you can find in `/usr/lib/kalliope/sounds`.
+By default two file are provided: ding.wav and dong.wav. In all cases, the file must be in `.wav` or `.mp3` format. If more than on file is present in the list,
+Kalliope will select one randomly at each wake up.
+
+```
+random_on_ready_sounds:
+  - "local_file_in_sounds_folder.wav"
+  - "/my/personal/full/path/my_file.mp3"
+```
+
+E.g
+```
+random_on_ready_sounds:
+  - "ding.wav"
+  - "dong.wav"
+  - "/my/personal/full/path/my_file.mp3"
+```
+
+>**Note: ** If you want to use a on ready sound instead of a on ready you must comment out the `random_on_ready_answers` section.
+E.g: `# random_on_ready_answers:`
+
+
 ## Rest API
 
 A Rest API can be activated in order to:

+ 18 - 2
Tests/settings/settings_test.yml

@@ -59,8 +59,24 @@ random_wake_up_answers:
 # Place here the full path of the sound file or just the name of the file in /usr/lib/kalliope/sounds
 # The file must be .wav or .mp3 format. By default two file are provided: ding.wav and dong.wav
 random_wake_up_sounds:
-  - "ding.wav"
-  - "dong.wav"
+  - "sounds/ding.wav"
+  - "sounds/dong.wav"
+
+# ---------------------------
+# On ready answers
+# ---------------------------
+# You can play a sound when Kalliope is started and is waiting for the trigger.
+random_on_ready_answers:
+  - "Kalliope is ready"
+
+# If you prefer, you can play a sound instead of a sentence.
+# Remove the `random_on_ready_answers` parameters to use this one.
+# Place here the full path of the sound file or just the name of the file in /usr/lib/kalliope/sounds
+# The file must be .wav or .mp3 format. By default two file are provided: ding.wav and dong.wav
+random_on_ready_sounds:
+  - "sounds/ding.wav"
+  - "sounds/dong.wav"
+
 
 # ---------------------------
 # Rest API

+ 11 - 2
Tests/test_settings_loader.py

@@ -39,7 +39,9 @@ class TestSettingLoader(unittest.TestCase):
             'random_wake_up_answers': ['Oui monsieur?'],
             'default_text_to_speech': 'pico2wave',
             'default_speech_to_text': 'google',
-            'random_wake_up_sounds': ['ding.wav', 'dong.wav'],
+            'random_wake_up_sounds': ['sounds/ding.wav', 'sounds/dong.wav'],
+            'random_on_ready_answers': ['Kalliope is ready'],
+            'random_on_ready_sounds': ['sounds/ding.wav', 'sounds/dong.wav'],
             'text_to_speech': [
                 {'pico2wave': {'cache': True, 'language': 'fr-FR'}},
                 {'voxygen': {'voice': 'Agnes', 'cache': True}}
@@ -87,7 +89,9 @@ class TestSettingLoader(unittest.TestCase):
         stt = Stt(name="google", parameters={'language': 'fr-FR'})
         settings_object.stts = [stt]
         settings_object.random_wake_up_answers = ['Oui monsieur?']
-        settings_object.random_wake_up_sounds = ['ding.wav', 'dong.wav']
+        settings_object.random_wake_up_sounds = ['sounds/ding.wav', 'sounds/dong.wav']
+        settings_object.random_on_ready_answers = ['Kalliope is ready']
+        settings_object.random_on_ready_sounds = ['sounds/ding.wav', 'sounds/dong.wav']
         trigger1 = Trigger(name="snowboy",
                            parameters={'pmdl_file': 'trigger/snowboy/resources/kalliope-FR-6samples.pmdl'})
         settings_object.triggers = [trigger1]
@@ -146,6 +150,11 @@ class TestSettingLoader(unittest.TestCase):
         sl = SettingLoader(file_path=self.settings_file_to_test)
         self.assertEqual(expected_random_wake_up_answers, sl._get_random_wake_up_answers(self.settings_dict))
 
+    def test_get_random_on_ready_answers(self):
+        expected_random_on_ready_answers = ['Kalliope is ready']
+        sl = SettingLoader(file_path=self.settings_file_to_test)
+        self.assertEqual(expected_random_on_ready_answers, sl._get_random_on_ready_answers(self.settings_dict))
+
     def test_get_rest_api(self):
         expected_rest_api = RestAPI(password_protected=True, active=True,
                                     login="admin", password="secret", port=5000,

+ 64 - 0
kalliope/core/ConfigurationManager/SettingLoader.py

@@ -105,6 +105,8 @@ class SettingLoader(object):
         triggers = self._get_triggers(settings)
         random_wake_up_answers = self._get_random_wake_up_answers(settings)
         random_wake_up_sounds = self._get_random_wake_up_sounds(settings)
+        random_on_ready_answers = self._get_random_on_ready_answers(settings)
+        random_on_ready_sounds = self._get_random_on_ready_sounds(settings)
         rest_api = self._get_rest_api(settings)
         cache_path = self._get_cache_path(settings)
         default_synapse = self._get_default_synapse(settings)
@@ -119,6 +121,8 @@ class SettingLoader(object):
         setting_object.triggers = triggers
         setting_object.random_wake_up_answers = random_wake_up_answers
         setting_object.random_wake_up_sounds = random_wake_up_sounds
+        setting_object.random_on_ready_answers = random_on_ready_answers
+        setting_object.random_on_ready_sounds = random_on_ready_sounds
         setting_object.rest_api = rest_api
         setting_object.cache_path = cache_path
         setting_object.default_synapse = default_synapse
@@ -379,6 +383,10 @@ class SettingLoader(object):
 
         try:
             random_wake_up_sounds_list = settings["random_wake_up_sounds"]
+            # In case files are declared in settings.yml, make sure kalliope can access them.
+            for sound in random_wake_up_sounds_list:
+                if Utils.get_real_file_path(sound) is None:
+                    raise SettingInvalidException("sound file %s not found" % sound)
         except KeyError:
             # User does not provide this settings
             return None
@@ -389,6 +397,62 @@ class SettingLoader(object):
 
         return random_wake_up_sounds_list
 
+    @staticmethod
+    def _get_random_on_ready_answers(settings):
+        """
+        Return a list of the wake up answers set up on the settings.yml file
+
+        :param settings: The YAML settings file
+        :type settings: dict
+        :return: List of on ready answers
+        :rtype: list of str
+
+        :Example:
+
+            wakeup = cls._get_random_on_ready_answers(settings)
+
+        .. seealso::
+        .. warnings:: Class Method and Private
+        """
+
+        try:
+            random_on_ready_answers_list = settings["random_on_ready_answers"]
+        except KeyError:
+            # User does not provide this settings
+            return None
+
+        return random_on_ready_answers_list
+
+    @staticmethod
+    def _get_random_on_ready_sounds(settings):
+        """
+        Return a list of the on ready sounds set up on the settings.yml file
+
+        :param settings: The YAML settings file
+        :type settings: dict
+        :return: list of wake up sounds
+        :rtype: list of str
+
+        :Example:
+
+            wakeup_sounds = cls._get_random_on_ready_sounds(settings)
+
+        .. seealso::
+        .. warnings:: Class Method and Private
+        """
+
+        try:
+            random_on_ready_sounds_list = settings["random_on_ready_sounds"]
+            # In case files are declared in settings.yml, make sure kalliope can access them.
+            for sound in random_on_ready_sounds_list:
+                if Utils.get_real_file_path(sound) is None:
+                    raise SettingInvalidException("sound file %s not found" % sound)
+        except KeyError:
+            # User does not provide this settings
+            return None
+
+        return random_on_ready_sounds_list
+
     @staticmethod
     def _get_rest_api(settings):
         """

+ 7 - 0
kalliope/core/MainController.py

@@ -38,6 +38,13 @@ class MainController:
 
         # create an order listener object. This last will the trigger callback before starting
         self.order_listener = OrderListener(self.analyse_order)
+
+        if self.settings.random_on_ready_answers is not None:
+            Say(message=self.settings.random_on_ready_answers)
+        elif self.settings.random_on_ready_sounds is not None:
+            random_sound_to_play = self._get_random_sound(self.settings.random_on_ready_sounds)
+            Mplayer.play(random_sound_to_play)
+
         # Wait that the kalliope trigger is pronounced by the user
         self.trigger_instance = self._get_default_trigger()
         self.trigger_instance.start()

+ 4 - 0
kalliope/core/Models/Settings.py

@@ -16,6 +16,8 @@ class Settings(object):
                  stts=None,
                  random_wake_up_answers=None,
                  random_wake_up_sounds=None,
+                 random_on_ready_answers=None,
+                 random_on_ready_sounds=None,
                  triggers=None,
                  rest_api=None,
                  cache_path=None,
@@ -31,6 +33,8 @@ class Settings(object):
         self.stts = stts
         self.random_wake_up_answers = random_wake_up_answers
         self.random_wake_up_sounds = random_wake_up_sounds
+        self.random_on_ready_answers = random_on_ready_answers
+        self.random_on_ready_sounds = random_on_ready_sounds
         self.triggers = triggers
         self.rest_api = rest_api
         self.cache_path = cache_path

+ 18 - 2
kalliope/settings.yml

@@ -93,11 +93,27 @@ random_wake_up_answers:
 # Place here the full path of the sound file or just the name of the file in /usr/lib/kalliope/sounds
 # The file must be .wav or .mp3 format. By default two file are provided: ding.wav and dong.wav
 random_wake_up_sounds:
-  - "ding.wav"
-  - "dong.wav"
+  - "sounds/ding.wav"
+  - "sounds/dong.wav"
   # - "/my/personal/full/path/my_file.mp3"
 
 
+# ---------------------------
+# On ready answers
+# ---------------------------
+# You can play a sound when Kalliope is started and is waiting for the trigger.
+#random_on_ready_answers:
+#  - "Kalliope is ready"
+
+# If you prefer, you can play a sound instead of a sentence.
+# Remove the `random_on_ready_answers` parameters to use this one.
+# Place here the full path of the sound file or just the name of the file in /usr/lib/kalliope/sounds
+# The file must be .wav or .mp3 format. By default two file are provided: ding.wav and dong.wav
+#random_on_ready_sounds:
+#  - "sounds/ding.wav"
+#  - "sounds/dong.wav"
+
+
 # ---------------------------
 # Rest API
 # ---------------------------