Преглед на файлове

Merged branch plugin-STT into dev

nico преди 8 години
родител
ревизия
6fe68e68dd
променени са 12 файла, в които са добавени 231 реда и са изтрити 3 реда
  1. 1 1
      Docs/dev_env_install.md
  2. 1 1
      brain.yml
  3. 11 1
      settings.yml
  4. 4 0
      stt/__init__.py
  5. 52 0
      stt/apiai/Apiai.py
  6. 1 0
      stt/apiai/__init__.py
  7. 51 0
      stt/bing/Bing.py
  8. 1 0
      stt/bing/__init__.py
  9. 58 0
      stt/houndify/Houndify.py
  10. 1 0
      stt/houndify/__init__.py
  11. 49 0
      stt/wit/Wit.py
  12. 1 0
      stt/wit/__init__.py

+ 1 - 1
Docs/dev_env_install.md

@@ -12,7 +12,7 @@ Tested env
 ### Packages installation
 On Ubuntu distribution:
 ```
-sudo apt-get install python-pip python-dev libsmpeg0 libttspico-utils libsmpeg0 flac dialog
+sudo apt-get install python-pip python-dev libsmpeg0 libttspico-utils libsmpeg0 flac dialog libffi-dev
 ```
 
 ### Python lib

+ 1 - 1
brain.yml

@@ -33,7 +33,7 @@
             - "Il est {{ hours }} heures et {{ minutes }} minutes"
           tts: "voxygen"
     signals:
-      - order: "quelle heure"
+      - order: "what time"
 
   - name: "Say local date from template"
     neurons:

+ 11 - 1
settings.yml

@@ -29,7 +29,17 @@ random_wake_up_answers:
 speech_to_text:
   - google:
       language: "fr-FR"
-  - bing
+  - wit:
+      key: "B5JI3YUSLYOYWNIDBINBVM34XUODME2K"
+  - bing: # API not working : credential fails ..
+      key: "9e48ddaf75904838bedc11aea6b36fb0"
+  - apiai: # Fail retriving the text from the audio file ..
+      key: "e0cbff154af44944a6b9f82c0668b527"
+      language: "fr"
+  - houndify: # In the online documentation but Not implemented yet in the speech recognition lib ..?
+      key: "7zj90T7qAV74OYXk4X4vI2Xhk7wPsJu4aEZ0G5Ll-BMmV1JGtFpCxtSH9SmTY4G3bpEJ7a5y_GTQid-CAKI6vw=="
+      client_id: "lN4JXeaSticbSo9-llczbA=="
+
 
 # Text to Spreech engines configuration
 # Available engine are:

+ 4 - 0
stt/__init__.py

@@ -1 +1,5 @@
 from google import Google
+from wit import Wit
+from bing import Bing
+from apiai import Apiai
+from houndify import Houndify

+ 52 - 0
stt/apiai/Apiai.py

@@ -0,0 +1,52 @@
+import speech_recognition as sr
+
+from core import Utils
+from core.OrderListener import OrderListener
+
+
+class Apiai(OrderListener):
+
+    def __init__(self, callback=None, **kwargs):
+        """
+        Start recording the microphone and analyse audio with Apiai api
+        :param callback: The callback function to call to send the text
+        :param kwargs:
+        """
+        OrderListener.__init__(self)
+
+        """
+        Start recording the microphone
+        :return:
+        """
+        # callback function to call after the translation speech/tex
+        self.callback = callback
+        # obtain audio from the microphone
+        r = sr.Recognizer()
+        with sr.Microphone() as source:
+            # listen for 1 second to calibrate the energy threshold for ambient noise levels
+            r.adjust_for_ambient_noise(source)
+            Utils.print_info("Say something!")
+            audio = r.listen(source)
+
+        # recognize speech using Apiai Speech Recognition
+        try:
+
+            key = kwargs.get('key', None)
+            language = kwargs.get('language', "en")
+            session_id= kwargs.get('session_id', None)
+            show_all = kwargs.get('show_all', False)
+
+            captured_audio = r.recognize_api(audio, client_access_token=key, language=language, session_id=session_id, show_all=show_all)
+            Utils.print_success("Apiai Speech Recognition thinks you said %s" % captured_audio)
+            self._analyse_audio(captured_audio)
+
+        except sr.UnknownValueError as e:
+            Utils.print_warning("Apiai Speech Recognition could not understand audio; {0}".format(e))
+        except sr.RequestError as e:
+            Utils.print_danger("Could not request results from Apiai Speech Recognition service; {0}".format(e))
+
+    def _analyse_audio(self, audio):
+        # if self.main_controller is not None:
+        #     self.main_controller.analyse_order(audio)
+        if self.callback is not None:
+            self.callback(audio)

+ 1 - 0
stt/apiai/__init__.py

@@ -0,0 +1 @@
+from Apiai import Apiai

+ 51 - 0
stt/bing/Bing.py

@@ -0,0 +1,51 @@
+import speech_recognition as sr
+
+from core import Utils
+from core.OrderListener import OrderListener
+
+
+class Bing(OrderListener):
+
+    def __init__(self, callback=None, **kwargs):
+        """
+        Start recording the microphone and analyse audio with Bing api
+        :param callback: The callback function to call to send the text
+        :param kwargs:
+        """
+        OrderListener.__init__(self)
+
+        """
+        Start recording the microphone
+        :return:
+        """
+        # callback function to call after the translation speech/tex
+        self.callback = callback
+        # obtain audio from the microphone
+        r = sr.Recognizer()
+        with sr.Microphone() as source:
+            # listen for 1 second to calibrate the energy threshold for ambient noise levels
+            r.adjust_for_ambient_noise(source)
+            Utils.print_info("Say something!")
+            audio = r.listen(source)
+
+        # recognize speech using Bing Speech Recognition
+        try:
+
+            key = kwargs.get('key', None)
+            language = kwargs.get('language', "en-US")
+            show_all = kwargs.get('show_all', False)
+
+            captured_audio = r.recognize_bing(audio, key=key, language=language, show_all=show_all)
+            Utils.print_success("Bing Speech Recognition thinks you said %s" % captured_audio)
+            self._analyse_audio(captured_audio)
+
+        except sr.UnknownValueError:
+            Utils.print_warning("Bing Speech Recognition could not understand audio")
+        except sr.RequestError as e:
+            Utils.print_danger("Could not request results from Bing Speech Recognition service; {0}".format(e))
+
+    def _analyse_audio(self, audio):
+        # if self.main_controller is not None:
+        #     self.main_controller.analyse_order(audio)
+        if self.callback is not None:
+            self.callback(audio)

+ 1 - 0
stt/bing/__init__.py

@@ -0,0 +1 @@
+from Bing import Bing

+ 58 - 0
stt/houndify/Houndify.py

@@ -0,0 +1,58 @@
+import speech_recognition as sr
+
+from core import Utils
+from core.OrderListener import OrderListener
+
+
+class Houndify(OrderListener):
+
+    def __init__(self, callback=None, **kwargs):
+        """
+        Start recording the microphone and analyse audio with Houndify api
+        :param callback: The callback function to call to send the text
+        :param kwargs:
+        """
+        OrderListener.__init__(self)
+
+        """
+        Start recording the microphone
+        :return:
+        """
+        # callback function to call after the translation speech/tex
+        self.callback = callback
+        # obtain audio from the microphone
+        r = sr.Recognizer()
+        with sr.Microphone() as source:
+            # listen for 1 second to calibrate the energy threshold for ambient noise levels
+            r.adjust_for_ambient_noise(source)
+            Utils.print_info("Say something!")
+            audio = r.listen(source)
+
+        # recognize speech using Houndify Speech Recognition
+        try:
+
+
+            id = kwargs.get('client_id', None)
+            key = kwargs.get('key', None)
+            language = kwargs.get('language', "en-US")
+            show_all = kwargs.get('show_all', False)
+
+            captured_audio = r.recognize_houndify(audio, client_id=id, client_key=key, language=language, show_all=show_all)
+            Utils.print_success("Houndify Speech Recognition thinks you said %s" % captured_audio)
+            self._analyse_audio(captured_audio)
+
+        except sr.UnknownValueError:
+            Utils.print_warning("Houndify Speech Recognition could not understand audio")
+        except sr.RequestError as e:
+            Utils.print_danger("Could not request results from Houndify Speech Recognition service; {0}".format(e))
+
+    def _analyse_audio(self, audio):
+        # if self.main_controller is not None:
+        #     self.main_controller.analyse_order(audio)
+        if self.callback is not None:
+            self.callback(audio)
+
+
+
+
+

+ 1 - 0
stt/houndify/__init__.py

@@ -0,0 +1 @@
+from Houndify import Houndify

+ 49 - 0
stt/wit/Wit.py

@@ -0,0 +1,49 @@
+import speech_recognition as sr
+
+from core import Utils
+from core.OrderListener import OrderListener
+
+
+class Wit(OrderListener):
+
+    def __init__(self, callback=None, **kwargs):
+        """
+        Start recording the microphone and analyse audio with Wit.ai api
+        :param callback: The callback function to call to send the text
+        :param kwargs:
+        """
+        OrderListener.__init__(self)
+
+        """
+        Start recording the microphone
+        :return:
+        """
+        # callback function to call after the translation speech/tex
+        self.callback = callback
+        # obtain audio from the microphone
+        r = sr.Recognizer()
+        with sr.Microphone() as source:
+            # listen for 1 second to calibrate the energy threshold for ambient noise levels
+            r.adjust_for_ambient_noise(source)
+            Utils.print_info("Say something!")
+            audio = r.listen(source)
+
+        # recognize speech using Wit.ai Speech Recognition
+        try:
+            key = kwargs.get('key', None)
+            show_all = kwargs.get('show_all', False)
+
+            captured_audio = r.recognize_wit(audio, key=key, show_all=show_all)
+            Utils.print_success("Wit.ai Speech Recognition thinks you said %s" % captured_audio)
+            self._analyse_audio(captured_audio)
+
+        except sr.UnknownValueError:
+            Utils.print_warning("Wit.ai Speech Recognition could not understand audio")
+        except sr.RequestError as e:
+            Utils.print_danger("Could not request results from Wit.ai Speech Recognition service; {0}".format(e))
+
+    def _analyse_audio(self, audio):
+        # if self.main_controller is not None:
+        #     self.main_controller.analyse_order(audio)
+        if self.callback is not None:
+            self.callback(audio)

+ 1 - 0
stt/wit/__init__.py

@@ -0,0 +1 @@
+from Wit import Wit