Selaa lähdekoodia

add mplayer class and start working on TTSModule

nico 8 vuotta sitten
vanhempi
commit
270f2b7506
7 muutettua tiedostoa jossa 136 lisäystä ja 27 poistoa
  1. 30 0
      core/Players/Mplayer.py
  2. 1 0
      core/Players/__init__.py
  3. 41 0
      core/TTS/Cache2.py
  4. 22 0
      core/TTS/TTSLauncher.py
  5. 32 0
      core/TTS/TTSModule.py
  6. 0 0
      core/TTS/__init__.py
  7. 10 27
      test.py

+ 30 - 0
core/Players/Mplayer.py

@@ -0,0 +1,30 @@
+import logging
+import os
+import subprocess
+
+logging.basicConfig()
+logger = logging.getLogger("kalliope")
+
+
+MPLAYER_EXEC_PATH = "/usr/bin/mplayer"
+
+
+class Mplayer(object):
+
+    def __init__(self):
+        mplayer_exec_path = [MPLAYER_EXEC_PATH]
+        mplayer_options = ['-slave', '-quiet']
+        self.mplayer_command = list()
+        self.mplayer_command.extend(mplayer_exec_path)
+        self.mplayer_command.extend(mplayer_options)
+
+    def play(self, filepath):
+
+        self.mplayer_command.append(filepath)
+        logger.debug("Mplayer cmd: %s" % str(self.mplayer_command))
+
+        FNULL = open(os.devnull, 'w')
+
+        subprocess.call(self.mplayer_command, stdout=FNULL, stderr=FNULL)
+
+

+ 1 - 0
core/Players/__init__.py

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

+ 41 - 0
core/TTS/Cache2.py

@@ -0,0 +1,41 @@
+
+
+class Cache2(object):
+    def __init__(self):
+        pass
+
+    @classmethod
+    def get_file_path_from_text(cls, sentence, tts):
+        """
+        Get a sentence (a text) an return the full path of the file
+
+        Path syntax:
+        </path/in/settings>/<tts.name>/tts.parameter["language"]/<md5_of_sentence.tts
+
+        E.g:
+        /tmp/kalliope/voxygene/fr/abcd12345.tts
+
+        :param sentence:
+        :param tts: The Tts model instance that contain parameter like language, key, etc...
+        :type tts: Tts
+        :return: path String
+        """
+        pass
+
+    @classmethod
+    def delete_file(cls, file_path):
+        """
+        Delete the file in path <file_path>
+        :param file_path:
+        :return:
+        """
+        pass
+
+    @staticmethod
+    def _generate_md5_from_text(text):
+        """
+        Local function to generate a md5 hash from a string sentence
+        :param text:
+        :return: String
+        """
+        pass

+ 22 - 0
core/TTS/TTSLauncher.py

@@ -0,0 +1,22 @@
+import logging
+
+from core import Utils
+
+logging.basicConfig()
+logger = logging.getLogger("kalliope")
+
+
+class TTSLauncher(object):
+    def __init__(self):
+        pass
+
+    @classmethod
+    def get_tts(cls, tts):
+        """
+        Return an instance of a TTS module from the name of this module
+        :param tts: TTS model
+        :type tts: Tts
+        :return: TTS module instance
+        """
+        logger.debug("get TTS module \"%s\" with parameters %s" % (tts.name, tts.parameters))
+        return Utils.get_dynamic_class_instantiation("tts", tts.name.capitalize(), tts.parameters)

+ 32 - 0
core/TTS/TTSModule.py

@@ -0,0 +1,32 @@
+# coding: utf8
+import logging
+
+logging.basicConfig()
+logger = logging.getLogger("kalliope")
+
+
+class TTSModule(object):
+
+    def __init__(self):
+        """
+        Mother class of TTS module. Hnadle:
+        - Cache: call cache object to create file, delete file, check if file exist
+
+        - Player: call the default player to play the generated file
+        """
+
+    def play_audio(self, audio_file_path):
+        """
+
+        :param audio_file_path:
+        :return:
+        """
+
+    def get_path_to_store_audio(self, text):
+        """
+        Call the cache to get the valid path where the TTS module will store the downloaded or generated file
+        :param text: String text audio we want to save on the local disk
+        :return:
+        """
+        # TODO: question: maybe we can implement function in cache directly in TTSModule as it is its job anyway to do all that stuff?
+        pass

+ 0 - 0
core/TTS/__init__.py


+ 10 - 27
test.py

@@ -1,17 +1,7 @@
 # coding: utf8
 import logging
-import re
-from collections import Counter
 
-from flask import Flask
-from core.RestAPI.FlaskAPI import FlaskAPI
-from core import OrderAnalyser
-from core.ConfigurationManager import SettingLoader
-from core.ConfigurationManager import YAMLLoader
-from core.ConfigurationManager.BrainLoader import BrainLoader
-
-from neurons import Systemdate
-from neurons.tasker_autoremote.tasker_autoremote import Tasker_autoremote
+from core.Players import Mplayer
 
 logging.basicConfig()
 logger = logging.getLogger("kalliope")
@@ -23,27 +13,20 @@ logger.setLevel(logging.DEBUG)
 
 # SettingLoader.get_settings()
 #
-brain = BrainLoader.get_brain()
-
-order = "est-ce que j'ai des emails"
-
-oa = OrderAnalyser(order=order, brain=brain)
-
-oa.start()
-
-
-# import wikipedia
+# brain = BrainLoader.get_brain()
 #
-# languages = wikipedia.languages().keys()
-# languages = sorted(languages)
-# for el in languages:
-#     print "- " + el
-
-
+# order = "bonjour2"
+#
+# oa = OrderAnalyser(order=order, brain=brain)
+#
+# oa.start()
 
 
+file_path = "/tmp/kalliope/tts/Acapela/sonid15/Manon.378f97b9ae266e30898396f4c4f7e159.tts"
 
 
+player = Mplayer()
+player.play(file_path)