Pārlūkot izejas kodu

Merge pull request #180 from kalliope-project/dev_nico

add offlline STT (CMUSphinx) #174
Monf 8 gadi atpakaļ
vecāks
revīzija
7e17d4fa4b

+ 1 - 0
Docs/stt.md

@@ -30,6 +30,7 @@ Core STTs are already packaged with the installation of Kalliope an can be used
 
 
 - [apiai](../kalliope/stt/apiai/README.md)
 - [apiai](../kalliope/stt/apiai/README.md)
 - [bing](../kalliope/stt/bing/README.md)
 - [bing](../kalliope/stt/bing/README.md)
+- [CMUSphinx](../kalliope/stt/cmusphinx/README.md)
 - [google](../kalliope/stt/google/README.md)
 - [google](../kalliope/stt/google/README.md)
 - [houndify](../kalliope/stt/houndify/README.md)
 - [houndify](../kalliope/stt/houndify/README.md)
 - [witai](../kalliope/stt/wit/README.md)
 - [witai](../kalliope/stt/wit/README.md)

+ 8 - 7
Docs/stt_list.md

@@ -6,13 +6,14 @@ See the [complete STT documentation](stt.md) for more information.
 ## Core STT
 ## Core STT
 Core STTs are already packaged with the installation of Kalliope an can be used out of the box.
 Core STTs are already packaged with the installation of Kalliope an can be used out of the box.
 
 
-| Name     | Description                                    |
-|----------|------------------------------------------------|
-| api.ai   | [apiai](../kalliope/stt/apiai/README.md)       |
-| bing     | [bing](../kalliope/stt/bing/README.md)         |
-| Google   | [google](../kalliope/stt/google/README.md)     |
-| Houndify | [houndify](../kalliope/stt/houndify/README.md) |
-| wit.ai   | [wit.ai](../kalliope/stt/wit/README.md)        |
+| Name      | Description                                      |
+|-----------|--------------------------------------------------|
+| api.ai    | [apiai](../kalliope/stt/apiai/README.md)         |
+| bing      | [bing](../kalliope/stt/bing/README.md)           |
+| Google    | [google](../kalliope/stt/google/README.md)       |
+| Houndify  | [houndify](../kalliope/stt/houndify/README.md)   |
+| CMUSphinx | [CMUSphinx](../kalliope/stt/cmusphinx/README.md) |
+| wit.ai    | [wit.ai](../kalliope/stt/wit/README.md)          |
 
 
 
 
 ## Community STT
 ## Community STT

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

@@ -247,8 +247,8 @@ class SettingLoader(object):
                     new_stt = Stt(name=name, parameters=parameters)
                     new_stt = Stt(name=name, parameters=parameters)
                     stts.append(new_stt)
                     stts.append(new_stt)
             else:
             else:
-                # the neuron does not have parameter
-                new_stt = Stt(name=speechs_to_text_el)
+                # the stt does not have parameter
+                new_stt = Stt(name=speechs_to_text_el, parameters=dict())
                 stts.append(new_stt)
                 stts.append(new_stt)
         return stts
         return stts
 
 

+ 3 - 3
kalliope/settings.yml

@@ -36,12 +36,13 @@ speech_to_text:
       key: "B5JI3YUSLYOYWNIDBINBVM34XUODME2K"
       key: "B5JI3YUSLYOYWNIDBINBVM34XUODME2K"
   - bing: # API not working : credential fails ..
   - bing: # API not working : credential fails ..
       key: "9e48ddaf75904838bedc11aea6b36fb0"
       key: "9e48ddaf75904838bedc11aea6b36fb0"
-  - apiai: # Fail retriving the text from the audio file ..
+  - apiai:
       key: "e0cbff154af44944a6b9f82c0668b527"
       key: "e0cbff154af44944a6b9f82c0668b527"
       language: "fr"
       language: "fr"
-  - houndify: # In the online documentation but Not implemented yet in the speech recognition lib ..?
+  - houndify:
       key: "7zj90T7qAV74OYXk4X4vI2Xhk7wPsJu4aEZ0G5Ll-BMmV1JGtFpCxtSH9SmTY4G3bpEJ7a5y_GTQid-CAKI6vw=="
       key: "7zj90T7qAV74OYXk4X4vI2Xhk7wPsJu4aEZ0G5Ll-BMmV1JGtFpCxtSH9SmTY4G3bpEJ7a5y_GTQid-CAKI6vw=="
       client_id: "lN4JXeaSticbSo9-llczbA=="
       client_id: "lN4JXeaSticbSo9-llczbA=="
+  #- cmusphinx
 
 
 
 
 # ---------------------------
 # ---------------------------
@@ -74,7 +75,6 @@ text_to_speech:
       language: "fr-fr"
       language: "fr-fr"
       cache: True
       cache: True
 
 
-
 # ---------------------------
 # ---------------------------
 # Wake up answers
 # Wake up answers
 # ---------------------------
 # ---------------------------

+ 0 - 3
kalliope/stt/bing/bing.py

@@ -48,8 +48,5 @@ class Bing(SpeechRecognition):
         Confirm the audio exists and run it in a Callback
         Confirm the audio exists and run it in a Callback
         :param audio: the captured audio
         :param audio: the captured audio
         """
         """
-
-        # if self.main_controller is not None:
-        #     self.main_controller.analyse_order(audio)
         if self.callback is not None:
         if self.callback is not None:
             self.callback(audio)
             self.callback(audio)

+ 24 - 0
kalliope/stt/cmusphinx/README.md

@@ -0,0 +1,24 @@
+### CMU Sphinx
+
+This module is based on the self hosted STT solution [CMUSPhinx engine](http://cmusphinx.sourceforge.net/wiki/).
+By default, only english language is available. You can download [another language model](https://sourceforge.net/projects/cmusphinx/files/Acoustic%20and%20Language%20Models/) from the main repository and install it following [the official documentation](http://cmusphinx.sourceforge.net/wiki/tutoriallm).
+
+#### Installation
+
+Install packages
+```bash
+sudo apt-get install swig libpulse-dev
+```
+
+Then install the python lib
+```bash
+sudo pip install pocketsphinx
+```
+
+Then, declare it as usual in your settings
+```YAML
+default_speech_to_text: "cmusphinx"
+# no parameters for this one
+speech_to_text:  
+  - cmusphinx
+```

+ 1 - 0
kalliope/stt/cmusphinx/__init__.py

@@ -0,0 +1 @@
+from cmusphinx import Cmusphinx

+ 47 - 0
kalliope/stt/cmusphinx/cmusphinx.py

@@ -0,0 +1,47 @@
+import speech_recognition as sr
+
+from kalliope.core import Utils
+from kalliope.stt.Utils import SpeechRecognition
+
+
+class Cmusphinx(SpeechRecognition):
+
+    def __init__(self, callback=None, **kwargs):
+        """
+        Start recording the microphone and analyse audio with CMU sphinx api
+        :param callback: The callback function to call to send the text
+        :param kwargs:
+        """
+        SpeechRecognition.__init__(self)
+
+        # callback function to call after the translation speech/tex
+        self.callback = callback
+
+        # start listening in the background
+        self.stop_listening = self.start_listening(self.sphinx_callback)
+
+    def sphinx_callback(self, recognizer, audio):
+        """
+        called from the background thread
+        """
+        try:
+            captured_audio = recognizer.recognize_sphinx(audio)
+            Utils.print_success("Sphinx Speech Recognition thinks you said %s" % captured_audio)
+            self._analyse_audio(captured_audio)
+
+        except sr.UnknownValueError:
+            Utils.print_warning("Sphinx 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 Sphinx 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):
+        """
+        Confirm the audio exists and run it in a Callback
+        :param audio: the captured audio
+        """
+        if self.callback is not None:
+            self.callback(audio)