Browse Source

Merge branch 'dev'

monf 8 years ago
parent
commit
e90ccd5196

+ 1 - 1
Docs/dev_env_install.md

@@ -14,7 +14,7 @@ To make Kalliope work, you will have to install a certain number of libraries
 
 On Ubuntu distribution :
 ```
-sudo apt-get install python-pip python-dev libsmpeg0 libttspico-utils libsmpeg0 flac dialog libffi-dev portaudio19-dev build-essential libssl-dev libffi-dev sox libatlas3-base
+sudo apt-get install python-pip python-dev libsmpeg0 libttspico-utils libsmpeg0 flac dialog libffi-dev portaudio19-dev build-essential libssl-dev libffi-dev sox libatlas3-base mplayer
 ```
 
 ### Python lib

+ 5 - 3
core/MainController.py

@@ -58,12 +58,14 @@ class MainController:
 
     def analyse_order(self, order):
         """
-        Receive an order, try to retreive it in the brain.yml to launch to attached plugins
+        Receive an order, try to retrieve it in the brain.yml to launch to attached plugins
         :param order: the sentence received
         :type order: str
         """
-        order_analyser = OrderAnalyser(order, main_controller=self, brain=self.brain)
-        order_analyser.start()
+        if order is not None:   # maybe we have received a null audio from STT engine
+            order_analyser = OrderAnalyser(order, main_controller=self, brain=self.brain)
+            order_analyser.start()
+
         # restart the trigger when the order analyser has finish his job
         Utils.print_info("Waiting for trigger detection")
         self.trigger_instance.unpause()

+ 2 - 2
core/TTS/TTSModule.py

@@ -58,10 +58,10 @@ class TTSModule(object):
         # load settings
         self.settings = SettingLoader.get_settings()
 
-        print "Class TTSModule called from module %s, cache: %s, language: %s, voice: %s" % (self.tts_caller_name,
+        logger.debug("Class TTSModule called from module %s, cache: %s, language: %s, voice: %s" % (self.tts_caller_name,
                                                                                              self.cache,
                                                                                              self.language,
-                                                                                             self.voice)
+                                                                                             self.voice))
 
     def play_audio(self):
         """

+ 33 - 33
install/install.yml

@@ -1,17 +1,17 @@
 ---
-- hosts: localhost
-  gather_facts: no
-  connection: local
-  vars:
-    - git_url: "git@github.com:kalliope-project/kalliope.git"
-    - temp_local_repo: "/tmp/kalliope_repo"
-
-  tasks:
-    - name: clone project in /tmp as standart user
-      git:
-        repo: "{{ git_url }}"
-        dest: /tmp/kalliope_repo
-        accept_hostkey: yes
+#- hosts: localhost
+#  gather_facts: no
+#  connection: local
+#  vars:
+#    - git_url: "git@github.com:kalliope-project/kalliope.git"
+#    - temp_local_repo: "/tmp/kalliope_repo"
+#
+#  tasks:
+#    - name: clone project in /tmp as standart user
+#      git:
+#        repo: "{{ git_url }}"
+#        dest: /tmp/kalliope_repo
+#        accept_hostkey: yes
 
 
 - hosts: localhost
@@ -56,24 +56,24 @@
       pip:
         requirements=/tmp/requirements.txt
 
-    - name: Check that the repo has been cloned
-      stat:
-        path: "{{ temp_local_repo }}"
-      register: git_repo_stat
-
-    - name: Remove old version if exist
-      file:
-        path: "{{ install_path }}"
-        state: absent
-
-    - name: Move repo in /usr/lib
-      command: mv "{{ temp_local_repo }}" "{{ install_path }}"
-      when: git_repo_stat.stat.exists
-
-    - name: Add entry in /usr/bin
-      file:
-        src: "{{ install_path }}/kalliope.py"
-        dest: /usr/bin/kalliope
-        state: link
-        force: True
+#    - name: Check that the repo has been cloned
+#      stat:
+#        path: "{{ temp_local_repo }}"
+#      register: git_repo_stat
+#
+#    - name: Remove old version if exist
+#      file:
+#        path: "{{ install_path }}"
+#        state: absent
+#
+#    - name: Move repo in /usr/lib
+#      command: mv "{{ temp_local_repo }}" "{{ install_path }}"
+#      when: git_repo_stat.stat.exists
+#
+#    - name: Add entry in /usr/bin
+#      file:
+#        src: "{{ install_path }}/kalliope.py"
+#        dest: /usr/bin/kalliope
+#        state: link
+#        force: True
 

+ 4 - 0
stt/apiai/Apiai.py

@@ -38,8 +38,12 @@ class Apiai(OrderListener):
 
         except sr.UnknownValueError as e:
             Utils.print_warning("Apiai Speech Recognition could not understand audio; {0}".format(e))
+            # callback anyway, we need to listen again for a new order
+            self._analyse_audio(audio=None)
         except sr.RequestError as e:
             Utils.print_danger("Could not request results from Apiai Speech Recognition service; {0}".format(e))
+            # callback anyway, we need to listen again for a new order
+            self._analyse_audio(audio=None)
 
     def _analyse_audio(self, audio):
         """

+ 4 - 0
stt/bing/Bing.py

@@ -37,8 +37,12 @@ class Bing(OrderListener):
 
         except sr.UnknownValueError:
             Utils.print_warning("Bing Speech Recognition could not understand audio")
+            # callback anyway, we need to listen again for a new order
+            self._analyse_audio(audio=None)
         except sr.RequestError as e:
             Utils.print_danger("Could not request results from Bing Speech Recognition service; {0}".format(e))
+            # callback anyway, we need to listen again for a new order
+            self._analyse_audio(audio=None)
 
     def _analyse_audio(self, audio):
         """

+ 4 - 0
stt/google/Google.py

@@ -40,8 +40,12 @@ class Google(OrderListener):
 
         except sr.UnknownValueError:
             Utils.print_warning("Google Speech Recognition could not understand audio")
+            # callback anyway, we need to listen again for a new order
+            self._analyse_audio(audio=None)
         except sr.RequestError as e:
             Utils.print_danger("Could not request results from Google Speech Recognition service; {0}".format(e))
+            # callback anyway, we need to listen again for a new order
+            self._analyse_audio(audio=None)
 
     def _analyse_audio(self, audio):
         """

+ 4 - 0
stt/houndify/Houndify.py

@@ -38,8 +38,12 @@ class Houndify(OrderListener):
 
         except sr.UnknownValueError:
             Utils.print_warning("Houndify Speech Recognition could not understand audio")
+            # callback anyway, we need to listen again for a new order
+            self._analyse_audio(audio=None)
         except sr.RequestError as e:
             Utils.print_danger("Could not request results from Houndify Speech Recognition service; {0}".format(e))
+            # callback anyway, we need to listen again for a new order
+            self._analyse_audio(audio=None)
 
     def _analyse_audio(self, audio):
         """

+ 4 - 0
stt/wit/Wit.py

@@ -35,8 +35,12 @@ class Wit(OrderListener):
 
         except sr.UnknownValueError:
             Utils.print_warning("Wit.ai Speech Recognition could not understand audio")
+            # callback anyway, we need to listen again for a new order
+            self._analyse_audio(audio=None)
         except sr.RequestError as e:
             Utils.print_danger("Could not request results from Wit.ai Speech Recognition service; {0}".format(e))
+            # callback anyway, we need to listen again for a new order
+            self._analyse_audio(audio=None)
 
     def _analyse_audio(self, audio):
         """

+ 28 - 15
tts/acapela/acapela.py

@@ -12,6 +12,15 @@ TTS_CONTENT_TYPE = "audio/mpeg"
 TTS_TIMEOUT_SEC = 30
 
 
+class TCPTimeOutError(Exception):
+    """
+    This error is raised when the TCP connection has been lost. Probably due to a low internet
+    connection while trying to access the remote API.
+    """
+
+    pass
+
+
 class Acapela(TTSModule):
     def __init__(self, **kwargs):
         super(Acapela, self).__init__(**kwargs)
@@ -32,28 +41,32 @@ class Acapela(TTSModule):
         Generic method used as a Callback in TTSModule
             - must provided the audio file and write it on the disk
 
-        .. raises:: FailToLoadSoundFile
+        .. raises:: FailToLoadSoundFile, TCPTimeOutError
         """
         # Prepare payload
         payload = self.get_payload()
 
-        # Get the mp3 URL from the page
-        url = Acapela.get_audio_link(TTS_URL, payload)
+        try:
+            # Get the mp3 URL from the page
+            url = Acapela.get_audio_link(TTS_URL, payload)
+
+            # getting the mp3
+            r = requests.get(url, params=payload, stream=True, timeout=TTS_TIMEOUT_SEC)
+            content_type = r.headers['Content-Type']
 
-        # getting the mp3
-        r = requests.get(url, params=payload, stream=True, timeout=TTS_TIMEOUT_SEC)
-        content_type = r.headers['Content-Type']
+            logger.debug("Acapela : Trying to get url: %s response code: %s and content-type: %s",
+                         r.url,
+                         r.status_code,
+                         content_type)
+            # Verify the response status code and the response content type
+            if r.status_code != requests.codes.ok or content_type != TTS_CONTENT_TYPE:
+                raise FailToLoadSoundFile("Acapela : Fail while trying to remotely access the audio file")
 
-        logger.debug("Acapela : Trying to get url: %s response code: %s and content-type: %s",
-                     r.url,
-                     r.status_code,
-                     content_type)
-        # Verify the response status code and the response content type
-        if r.status_code != requests.codes.ok or content_type != TTS_CONTENT_TYPE:
-            raise FailToLoadSoundFile("Acapela : Fail while trying to remotely access the audio file")
+            # OK we get the audio we can write the sound file
+            FileManager.write_in_file(self.file_path, r.content)
 
-        # OK we get the audio we can write the sound file
-        FileManager.write_in_file(self.file_path, r.content)
+        except:
+            raise TCPTimeOutError("TCP timeout, the connection to the remote API has been lost")
 
     def get_payload(self):
         """