Переглянути джерело

Merged acapela_tts into master

nico 8 роки тому
батько
коміт
5112f1409c

+ 1 - 0
brain.yml

@@ -6,6 +6,7 @@
             - "Hello, I'm Jarvis"
     signals:
       - order: "hello"
+      - order: "je voudrais ecouter {{ artist_name }}"
 
   - name: "say hello"
     neurons:

+ 4 - 1
core/AudioPlayer.py

@@ -17,6 +17,7 @@ class AudioPlayer:
     AUDIO_MP3_BUFFER = 2048
 
     AUDIO_MP3_44100_FREQUENCY = 44100
+    AUDIO_MP3_22050_FREQUENCY = 22050
 
     AUDIO_DEFAULT_VOLUME = 0.8
 
@@ -35,7 +36,8 @@ class AudioPlayer:
             audio_buffer = audio_buffer
 
         audio_frequency = audio_frequency
-        pygame.mixer.init(audio_frequency, audio_size, audio_channel, audio_buffer)
+        pygame.mixer.pre_init(audio_frequency, audio_size, audio_channel, audio_buffer)
+        pygame.mixer.init()
 
     def play_audio(self, music_file):
         try:
@@ -60,4 +62,5 @@ class AudioPlayer:
         pygame.mixer.music.play()
         while pygame.mixer.music.get_busy():
             clock.tick(20)
+        pygame.mixer.quit()
         return

+ 10 - 0
settings.yml

@@ -53,6 +53,16 @@ text_to_speech:
       language: "fr"
       voice: "Emma"
       cache: True
+  - acapela:
+      language: "sonid15"
+      voice: "Manon"
+      cache: True
+  - googletts:
+      language: "fr"
+      cache: True
+  - voicerss:
+      language: "fr-fr"
+      cache: True
 
 # Trigger engine configuration
 # Available engine are:

+ 50 - 6
test.py

@@ -1,22 +1,66 @@
 # -*- coding: utf-8 -*-
 import os
 
+import re
+
 from core.ConfigurationManager import SettingLoader
+from core.ConfigurationManager.BrainLoader import BrainLoader
 from core.CrontabManager import CrontabManager
+from core.Models import Order
 from core.OrderAnalyser import OrderAnalyser
 
 import logging
 
 from core.TriggerLauncher import TriggerLauncher
 
-logging.basicConfig()
-logger = logging.getLogger("jarvis")
-logger.setLevel(logging.DEBUG)
-order = "dis bonjour"
 
-oa = OrderAnalyser(order=order)
+# user_said = "maman je voudrais ecouter ACDC"
+# order = "je voudrais ecouter {{ artist_name }}"
+
+user_said = "regle le reveil pour sept heures et dix minutes"
+order = "regle le reveil pour {{ hour }} heures et {{ minute }} minutes"
+
+
+brain = BrainLoader.get_brain()
+# take a look to each order
+
+
+def _is_containing_bracket(sentence):
+    # print "sentence to test %s" % sentence
+    pattern = r"{{|}}"
+    # prog = re.compile(pattern)
+    bool = re.search(pattern, sentence)
+    if bool is not None:
+        return True
+    return False
+
+list_word = user_said.split()
+# list_word = ["je", "voudrais"]
+print "user said: %s" % list_word
+
+
+def _get_order_without_variables(list_word_in_order):
+
+   pass
+
+
+# check if the order contain bracket
+if _is_containing_bracket(order):
+    # get a table of word said
+    list_word_in_order = order.split()
+    print "order matched: %s" % list_word_in_order
+    split_orider_variable = _get_order_without_variables(list_word_in_order)
+
+
+# return the beginning of the sentence before first bracket
+# return sentence[:sentence.find('{{')]
+
+# split each word
+# 
+
+
+
 
-oa.start()
 
 
 

+ 5 - 2
tts/TTS.py

@@ -12,6 +12,9 @@ logger = logging.getLogger("jarvis")
 
 
 class TTS:
+    TTS_CONTENT_TYPE = "audio/mpeg"
+    TTS_TIMEOUT_SEC = 30
+
     def __init__(self, cache_extension=None, volume=0.8):
         self.cache = Cache(module_name=self.__class__.__name__, cache_extension=cache_extension)
         self.audio_player = AudioPlayer(volume=volume)
@@ -24,7 +27,7 @@ class TTS:
     def say_generic(self, cache, language, words, get_audio_specific, audio_type, audio_frequency, voice=None):
         file_path = self.cache.get_audio_file_cache_path(words, language, voice)
 
-        if get_audio_specific(language, words, file_path, cache):
+        if get_audio_specific(language=language, words=words, file_path=file_path, cache=cache, voice=voice):
             self.play_audio(file_path, audio_type, audio_frequency, cache)
 
     @staticmethod
@@ -32,7 +35,7 @@ class TTS:
         return key.lower()
 
     @staticmethod
-    def get_audio(file_path, cache, payload, url, content_type_expected, timeout_expected=30):
+    def get_audio(file_path, cache, payload, url, content_type_expected=TTS_CONTENT_TYPE, timeout_expected=TTS_TIMEOUT_SEC):
         if not cache or not os.path.exists(file_path) or FileManager.file_is_empty(file_path):
 
             r = requests.get(url, params=payload, stream=True, timeout=timeout_expected)

+ 1 - 0
tts/__init__.py

@@ -3,3 +3,4 @@ from voxygen import Voxygen
 from pico2wave import Pico2wave
 from voicerss import Voicerss
 from googletts import Googletts
+from acapela import Acapela

+ 1 - 0
tts/acapela/__init__.py

@@ -0,0 +1 @@
+from acapela import Acapela

+ 52 - 0
tts/acapela/acapela.py

@@ -0,0 +1,52 @@
+import logging
+
+import re
+
+import requests
+
+from core import AudioPlayer
+from tts import TTS
+
+logging.basicConfig()
+logger = logging.getLogger("jarvis")
+
+
+class Acapela(TTS):
+    TTS_LANGUAGES_DEFAULT = 'sonid15'
+    TTS_VOICE_DEFAULT = 'Manon'
+    TTS_URL = "http://www.acapela-group.com/demo-tts/DemoHTML5Form_V2_fr.php"
+    TTS_CONTENT_TYPE = "audio/mpeg"
+    TTS_TIMEOUT_SEC = 30
+
+    def __init__(self):
+        TTS.__init__(self)
+
+    def say(self, words=None, language=TTS_LANGUAGES_DEFAULT, voice=TTS_VOICE_DEFAULT, cache=True):
+        self.say_generic(cache, language, words, self.get_audio_acapela, AudioPlayer.PLAYER_MP3, AudioPlayer.AUDIO_MP3_22050_FREQUENCY, voice)
+
+    def get_audio_acapela(self, **kwargs):
+        language = kwargs.get('language', None)
+        words = kwargs.get('words', None)
+        cache = kwargs.get('cache', None)
+        file_path = kwargs.get('file_path', None)
+        voice = kwargs.get('voice', None)
+        payload = Acapela.get_payload(language, voice, words)
+        url = Acapela.get_audio_link(self.TTS_URL, payload)
+
+        return TTS.get_audio(file_path, cache, payload, url)
+
+    @staticmethod
+    def get_audio_link(url, payload, timeout_expected=30):
+        r = requests.post(url, payload, timeout=timeout_expected)
+        data = r.content
+        return re.search("(?P<url>https?://[^\s]+).mp3", data).group(0)
+
+    @staticmethod
+    def get_payload(language, voice, words):
+        return {
+            "MyLanguages": language,
+            "MySelectedVoice": voice,
+            "MyTextForTTS": words,
+            "t": "1",
+            "SendToVaaS": ""
+        }

+ 13 - 4
tts/googletts/googletts.py

@@ -19,12 +19,21 @@ class Googletts(TTS):
     def say(self, words=None, language=TTS_LANGUAGES_DEFAULT, cache=True):
         self.say_generic(cache, language, words, self.get_audio_googletts, AudioPlayer.PLAYER_MP3, 25000)
 
-    def get_audio_googletts(self, language, words, file_path, cache):
-        payload = {
+    def get_audio_googletts(self, **kwargs):
+        words = kwargs.get('words', None)
+        cache = kwargs.get('cache', None)
+        file_path = kwargs.get('file_path', None)
+        language = kwargs.get('language', None)
+        payload = Googletts.get_payload(language,words)
+
+        return TTS.get_audio(file_path, cache, payload, self.TTS_URL)
+
+    @staticmethod
+    def get_payload(language, words):
+        return {
             "q": words,
             "tl": language,
             "ie": "UTF-8",
             "total": "1",
             "client": "tw-ob"
-        }
-        return self.get_audio(file_path, cache, payload, self.TTS_URL, self.TTS_CONTENT_TYPE, self.TTS_TIMEOUT_SEC)
+        }

+ 5 - 1
tts/pico2wave/pico2wave.py

@@ -19,6 +19,10 @@ class Pico2wave(TTS):
         self.say_generic(cache, language, words, self.get_audio_pico2wave, AudioPlayer.PLAYER_WAV, AudioPlayer.AUDIO_MP3_FREQUENCY)
 
     @staticmethod
-    def get_audio_pico2wave(language, words, file_path, cache):
+    def get_audio_pico2wave(**kwargs):
+        language = kwargs.get('language', None)
+        words = kwargs.get('words', None)
+        file_path = kwargs.get('file_path', None)
+
         subprocess.check_output(["/usr/bin/pico2wave", "-l=%s" % language, "-w=%s" % file_path, words], stderr=sys.stderr)
         return True

+ 12 - 3
tts/voicerss/voicerss.py

@@ -19,10 +19,19 @@ class Voicerss(TTS):
     def say(self, words=None, language=TTS_LANGUAGES_DEFAULT, cache=True):
         self.say_generic(cache, language, words, self.get_audio_voicerss, AudioPlayer.PLAYER_MP3, AudioPlayer.AUDIO_MP3_44100_FREQUENCY)
 
-    def get_audio_voicerss(self, language, words, file_path, cache):
-        payload = {
+    def get_audio_voicerss(self, **kwargs):
+        words = kwargs.get('words', None)
+        cache = kwargs.get('cache', None)
+        file_path = kwargs.get('file_path', None)
+        language = kwargs.get('language', None)
+        payload = Voicerss.get_payload(language, words)
+
+        return TTS.get_audio(file_path, cache, payload, self.TTS_URL)
+
+    @staticmethod
+    def get_payload(language, words):
+        return {
             "src": words,
             "hl": language,
             "c": "mp3"
         }
-        return self.get_audio(file_path, cache, payload, self.TTS_URL, self.TTS_CONTENT_TYPE, self.TTS_TIMEOUT_SEC)

+ 13 - 6
tts/voxygen/voxygen.py

@@ -11,8 +11,6 @@ class Voxygen(TTS):
     TTS_VOICE_DEFAULT = "Michel"
     TTS_LANGUAGES_DEFAULT = "default"
     TTS_URL = "https://www.voxygen.fr/sites/all/modules/voxygen_voices/assets/proxy/index.php"
-    TTS_CONTENT_TYPE = "audio/mpeg"
-    TTS_TIMEOUT_SEC = 30
 
     def __init__(self):
         TTS.__init__(self)
@@ -20,10 +18,19 @@ class Voxygen(TTS):
     def say(self, words=None, voice=TTS_VOICE_DEFAULT, language=TTS_LANGUAGES_DEFAULT, cache=True):
         self.say_generic(cache, language, words, self.get_audio_voxygen, AudioPlayer.PLAYER_MP3, AudioPlayer.AUDIO_MP3_FREQUENCY, voice)
 
-    def get_audio_voxygen(self, voice, words, file_path, cache):
-        payload = {
+    def get_audio_voxygen(self, **kwargs):
+        words = kwargs.get('words', None)
+        cache = kwargs.get('cache', None)
+        file_path = kwargs.get('file_path', None)
+        voice = kwargs.get('voice', None)
+        payload = Voxygen.get_payload(voice, words)
+
+        return TTS.get_audio(file_path, cache, payload, self.TTS_URL)
+
+    @staticmethod
+    def get_payload(voice, words):
+        return {
             "method": "redirect",
             "text": words,
             "voice": voice
-        }
-        return self.get_audio(file_path, cache, payload, self.TTS_URL, self.TTS_CONTENT_TYPE, self.TTS_TIMEOUT_SEC)
+        }