浏览代码

Merge branch 'dev' of gitlab.pwit.fr:millionsfortomorrow/jarvis into Order-with-Params

monf 8 年之前
父节点
当前提交
e34ed00a57
共有 7 个文件被更改,包括 71 次插入6 次删除
  1. 0 2
      Docs/automated_install.md
  2. 25 2
      core/ConfigurationManager/SettingLoader.py
  3. 34 1
      core/MainController.py
  4. 3 1
      core/Models/Settings.py
  5. 9 0
      settings.yml
  6. 0 0
      sounds/ding.wav
  7. 0 0
      sounds/dong.wav

+ 0 - 2
Docs/automated_install.md

@@ -14,8 +14,6 @@ Run the install script.
 >**Note:** The install script must not be ran as root or with sudo. 
 You will be prompted to enter your sudo password during the installation process.
 
-You will be prompted to enter your sudo password during the installation process.
-
 Be sure you can record you voice, run the following command to capture audio from your microphone
 ```
 rec test.wav

+ 25 - 2
core/ConfigurationManager/SettingLoader.py

@@ -45,6 +45,8 @@ class SettingLoader(object):
         ttss = cls._get_ttss(settings)
         triggers = cls._get_triggers(settings)
         random_wake_up_answers = cls._get_random_wake_up_answers(settings)
+        random_wake_up_sounds = cls._get_random_wake_up_sounds(settings)
+
         # create a setting object
         setting_object = Settings(default_stt_name=default_stt_name,
                                   default_tts_name=default_tts_name,
@@ -52,7 +54,8 @@ class SettingLoader(object):
                                   stts=stts,
                                   ttss=ttss,
                                   triggers=triggers,
-                                  random_wake_up_answers=random_wake_up_answers)
+                                  random_wake_up_answers=random_wake_up_answers,
+                                  random_wake_up_sounds=random_wake_up_sounds)
         return setting_object
 
     @staticmethod
@@ -180,10 +183,30 @@ class SettingLoader(object):
         try:
             random_wake_up_answers_list = settings["random_wake_up_answers"]
         except KeyError:
-            raise SettingNotFound("text_to_speech settings not found")
+            # User does not provide this settings
+            return None
 
         # 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
+
+    @classmethod
+    def _get_random_wake_up_sounds(cls, settings):
+        """
+        return a list of string
+        :param settings:
+        :return: List of string
+        """
+        try:
+            random_wake_up_sounds_list = settings["random_wake_up_sounds"]
+        except KeyError:
+            # User does not provide this settings
+            return None
+
+        # The the setting is present, the list cannot be empty
+        if random_wake_up_sounds_list is None:
+            raise NullSettingException("random_wake_up_sounds settings is empty")
+
+        return random_wake_up_sounds_list

+ 34 - 1
core/MainController.py

@@ -1,3 +1,8 @@
+import logging
+import os
+import random
+
+from core import AudioPlayer
 from core import Utils
 from core.ConfigurationManager import SettingLoader
 from core.OrderAnalyser import OrderAnalyser
@@ -6,6 +11,8 @@ from core.TriggerLauncher import TriggerLauncher
 
 from neurons import Say
 
+logging.basicConfig()
+logger = logging.getLogger("jarvis")
 
 class MainController:
     def __init__(self, brain_file=None):
@@ -30,7 +37,14 @@ class MainController:
         self.trigger_instance.pause()
         # start listening for an order
         self.order_listener.start()
-        Say(message=self.settings.random_wake_up_answers)
+        # if random wake answer sentence are present, we play this
+        if self.settings.random_wake_up_answers is not None:
+            Say(message=self.settings.random_wake_up_answers)
+        else:
+            ap = AudioPlayer()
+            ap.init_play()
+            random_sound_to_play = self._get_random_sound(self.settings.random_wake_up_sounds)
+            ap.play_audio(random_sound_to_play)
 
     def analyse_order(self, order):
         """
@@ -59,3 +73,22 @@ class MainController:
     def unpause_jarvis_trigger(self):
         print "call unpause"
         self.trigger_instance.unpause()
+
+    @staticmethod
+    def _get_random_sound(random_wake_up_sounds):
+        """
+        Return a path of a sound to play
+        If the path is absolute, test if file exist
+        If the path is relative, we check if the file exist in the sound folder
+        :param random_wake_up_sounds:
+        :return:
+        """
+        # take first randomly a path
+        random_path = random.choice(random_wake_up_sounds)
+        logger.debug("Selected sound: %s" % random_path)
+        if os.path.isabs(random_path):
+            logger.debug("Path of file %s is absolute" % random_path)
+            return random_path
+        else:
+            logger.debug("Path of file %s is relative" % random_path)
+            return "sounds" + os.sep + random_path

+ 3 - 1
core/Models/Settings.py

@@ -2,11 +2,13 @@
 
 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, triggers=None):
+                 default_trigger_name=None, ttss=None, stts=None,
+                 random_wake_up_answers=None, random_wake_up_sounds=None, triggers=None):
         self.default_tts_name = default_tts_name
         self.default_stt_name = default_stt_name
         self.default_trigger_name = default_trigger_name
         self.ttss = ttss
         self.stts = stts
         self.random_wake_up_answers = random_wake_up_answers
+        self.random_wake_up_sounds = random_wake_up_sounds
         self.triggers = triggers

+ 9 - 0
settings.yml

@@ -22,6 +22,15 @@ random_wake_up_answers:
   - "J'écoute"
   - "Oui?"
 
+# You can play a sound when jarvis detect the hotword/trigger instead of saying something from
+# the `random_wake_up_answers`.
+# Place here the full path of the sound file or just the name of the file in /usr/lib/jarvis/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"
+  # - "/my/personal/full/path/my_file.mp3"
+
 # Spreech to Text engines configuration
 # Available engine are:
 # - google (via SpeechRecognition)

+ 0 - 0
trigger/snowboy/resources/ding.wav → sounds/ding.wav


+ 0 - 0
trigger/snowboy/resources/dong.wav → sounds/dong.wav