示例#1
0
    def __init__(self, **kwargs):

        # set parameter from what we receive from the settings
        self.cache = kwargs.get('cache', False)
        self.language = kwargs.get('language', "default")
        self.voice = kwargs.get('voice', "default")
        # the name of the TSS is the name of the Tss module that have instantiated TTSModule
        self.tts_caller_name = self.__class__.__name__

        # we don't know yet the words that will be converted to an audio and so we don't have the audio path yet too
        self.words = None
        self.file_path = None
        self.base_cache_path = None

        # load settings
        sl = SettingLoader()
        self.settings = sl.settings
        self.player = PlayerLauncher.get_player(settings=self.settings)

        # create the path in the tmp folder
        base_path = os.path.join(self.settings.cache_path, self.tts_caller_name, self.language, self.voice)
        FileManager.create_directory(base_path)

        logger.debug("Class TTSModule called from module %s, cache: %s, language: %s, voice: %s" % (self.tts_caller_name,
                                                                                                     self.cache,
                                                                                                     self.language,
                                                                                                     self.voice))
示例#2
0
    def __init__(self, **kwargs):

        # set parameter from what we receive from the settings
        self.cache = kwargs.get('cache', False)
        self.language = kwargs.get('language', None)
        self.voice = kwargs.get('voice', "default")
        # the name of the TSS is the name of the Tss module that have instantiated TTSModule
        self.tts_caller_name = self.__class__.__name__

        # we don't know yet the words that will be converted to an audio and so we don't have the audio path yet too
        self.words = None
        self.file_path = None
        self.base_cache_path = None

        # load settings
        sl = SettingLoader()
        self.settings = sl.settings

        # create the path in the tmp folder
        base_path = os.path.join(self.settings.cache_path,
                                 self.tts_caller_name, self.language,
                                 self.voice)
        FileManager.create_directory(base_path)

        logger.debug(
            "Class TTSModule called from module %s, cache: %s, language: %s, voice: %s"
            % (self.tts_caller_name, self.cache, self.language, self.voice))
示例#3
0
    def __init__(self, app, port=5000, brain=None, allowed_cors_origin=False):
        """

        :param app: Flask API
        :param port: Port to listen
        :param brain: Brain object
        :type brain: Brain
        """
        super(FlaskAPI, self).__init__()
        self.app = app
        self.port = port
        self.brain = brain
        self.allowed_cors_origin = allowed_cors_origin

        # get current settings
        sl = SettingLoader()
        self.settings = sl.settings

        # configure the upload folder
        app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
        # create the temp folder
        FileManager.create_directory(UPLOAD_FOLDER)

        # Flask configuration remove default Flask behaviour to encode to ASCII
        self.app.url_map.strict_slashes = False
        self.app.config['JSON_AS_ASCII'] = False

        if self.allowed_cors_origin is not False:
            CORS(app, resources={r"/*": {"origins": allowed_cors_origin}}, supports_credentials=True)

        # Add routing rules
        self.app.add_url_rule('/', view_func=self.get_main_page, methods=['GET'])
        self.app.add_url_rule('/shutdown/', view_func=self.shutdown_server, methods=['POST'])

        # Register blue prints
        self.synapses_blueprint = SynapsesView('synapses',
                                               __name__,
                                               app=self.app,
                                               brain=self.brain,
                                               settings=self.settings)
        self.app.register_blueprint(self.synapses_blueprint)
        self.settings_blueprint = SettingsView('settings',
                                               __name__,
                                               app=self.app,
                                               brain=self.brain,
                                               settings=self.settings)
        self.app.register_blueprint(self.settings_blueprint)
        self.neurons_blueprint = NeuronsView('neurons',
                                             __name__,
                                             app=self.app,
                                             brain=self.brain,
                                             settings=self.settings)
        self.app.register_blueprint(self.neurons_blueprint)
示例#4
0
    def _is_file_already_in_cache(base_cache_path, file_path):
        """
        Return true if the file to generate has already been generated before
        """
        # generate sub folder
        FileManager.create_directory(base_cache_path)

        # check if the audio file exist
        exist_in_cache = os.path.exists(file_path)

        if exist_in_cache:
            logger.debug("TTSModule, File already in cache: %s" % file_path)
        else:
            logger.debug("TTSModule, File not yet in cache: %s" % file_path)
        return exist_in_cache
示例#5
0
    def _is_file_already_in_cache(base_cache_path, file_path):
        """
        Return true if the file to generate has already been generated before
        """
        # generate sub folder
        FileManager.create_directory(base_cache_path)

        # check if the audio file exist
        exist_in_cache = os.path.exists(file_path)

        if exist_in_cache:
            logger.debug("TTSModule, File already in cache: %s" % file_path)
        else:
            logger.debug("TTSModule, File not yet in cache: %s" % file_path)
        return exist_in_cache
示例#6
0
    def test_create_directory(self):
        """
        Test to create a new directory.
        """
        # set up
        cache_path = "/tmp/kalliope/tests/testDirectory"
        if os.path.exists(cache_path):
            os.removedirs(cache_path)

        # Test FileManager.create_directory
        FileManager.create_directory(cache_path)
        self.assertTrue(os.path.exists(cache_path),
                        "Fail creating a directory to the path ")

        # Remove the directory
        os.removedirs(cache_path)
    def test_create_directory(self):
        """
        Test to create a new directory.
        """
        # set up
        cache_path = "/tmp/kalliope/tests/testDirectory"
        if os.path.exists(cache_path):
            os.removedirs(cache_path)

        # Test FileManager.create_directory
        FileManager.create_directory(cache_path)
        self.assertTrue(os.path.exists(cache_path),
                        "Fail creating a directory to the path ")

        # Remove the directory
        os.removedirs(cache_path)
示例#8
0
    def __init__(self, app, port=5000, brain=None, allowed_cors_origin=False):
        """

        :param app: Flask API
        :param port: Port to listen
        :param brain: Brain object
        :type brain: Brain
        """
        super(FlaskAPI, self).__init__()
        self.app = app
        self.port = port
        self.brain = brain
        self.allowed_cors_origin = allowed_cors_origin

        # get current settings
        sl = SettingLoader()
        self.settings = sl.settings

        # api_response sent by the Order Analyser when using the /synapses/start/audio URL
        self.api_response = None
        # boolean used to notify the main process that we get the list of returned synapse
        self.order_analyser_return = False

        # configure the upload folder
        app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
        # create the temp folder
        FileManager.create_directory(UPLOAD_FOLDER)

        # Flask configuration remove default Flask behaviour to encode to ASCII
        self.app.url_map.strict_slashes = False
        self.app.config['JSON_AS_ASCII'] = False

        if self.allowed_cors_origin is not False:
            cors = CORS(app,
                        resources={r"/*": {
                            "origins": allowed_cors_origin
                        }},
                        supports_credentials=True)

        # Add routing rules
        self.app.add_url_rule('/',
                              view_func=self.get_main_page,
                              methods=['GET'])
        self.app.add_url_rule('/synapses',
                              view_func=self.get_synapses,
                              methods=['GET'])
        self.app.add_url_rule('/synapses/<synapse_name>',
                              view_func=self.get_synapse,
                              methods=['GET'])
        self.app.add_url_rule('/synapses/start/id/<synapse_name>',
                              view_func=self.run_synapse_by_name,
                              methods=['POST'])
        self.app.add_url_rule('/synapses/start/order',
                              view_func=self.run_synapse_by_order,
                              methods=['POST'])
        self.app.add_url_rule('/synapses/start/audio',
                              view_func=self.run_synapse_by_audio,
                              methods=['POST'])
        self.app.add_url_rule('/shutdown/',
                              view_func=self.shutdown_server,
                              methods=['POST'])
示例#9
0
    def __init__(self, app, port=5000, brain=None, allowed_cors_origin=False):
        """

        :param app: Flask API
        :param port: Port to listen
        :param brain: Brain object
        :type brain: Brain
        """
        super(FlaskAPI, self).__init__()
        self.app = app
        self.port = port
        self.brain = brain
        self.allowed_cors_origin = allowed_cors_origin

        # get current settings
        sl = SettingLoader()
        self.settings = sl.settings

        # api_response sent by the Order Analyser when using the /synapses/start/audio URL
        self.api_response = None
        # boolean used to notify the main process that we get the list of returned synapse
        self.order_analyser_return = False

        # configure the upload folder
        app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
        # create the temp folder
        FileManager.create_directory(UPLOAD_FOLDER)

        # Flask configuration remove default Flask behaviour to encode to ASCII
        self.app.url_map.strict_slashes = False
        self.app.config['JSON_AS_ASCII'] = False

        if self.allowed_cors_origin is not False:
            CORS(app, resources={r"/*": {"origins": allowed_cors_origin}}, supports_credentials=True)

        # Add routing rules
        self.app.add_url_rule('/', view_func=self.get_main_page, methods=['GET'])

        # Synapses
        self.app.add_url_rule('/synapses', view_func=self.get_synapses, methods=['GET'])
        self.app.add_url_rule('/synapses/<synapse_name>', view_func=self.get_synapse, methods=['GET'])
        self.app.add_url_rule('/synapses/start/id/<synapse_name>', view_func=self.run_synapse_by_name, methods=['POST'])
        self.app.add_url_rule('/synapses/start/order', view_func=self.run_synapse_by_order, methods=['POST'])
        self.app.add_url_rule('/synapses/start/audio', view_func=self.run_synapse_by_audio, methods=['POST'])

        # Life Cycle
        self.app.add_url_rule('/shutdown/', view_func=self.shutdown_server, methods=['POST'])

        # Settings
        self.app.add_url_rule('/settings', view_func=self.get_current_settings, methods=['GET'])
        self.app.add_url_rule('/settings/deaf/', view_func=self.get_deaf, methods=['GET'])
        self.app.add_url_rule('/settings/deaf/', view_func=self.set_deaf, methods=['POST'])
        self.app.add_url_rule('/settings/mute/', view_func=self.get_mute, methods=['GET'])
        self.app.add_url_rule('/settings/mute/', view_func=self.set_mute, methods=['POST'])
        self.app.add_url_rule('/settings/ambient_noise_second/', view_func=self.get_ambient_noise_second,
                              methods=['GET'])
        self.app.add_url_rule('/settings/ambient_noise_second/', view_func=self.set_adjust_for_ambient_noise_second,
                              methods=['POST'])
        self.app.add_url_rule('/settings/energy_threshold/', view_func=self.get_energy_threshold,
                              methods=['GET'])
        self.app.add_url_rule('/settings/energy_threshold/', view_func=self.set_energy_threshold,
                              methods=['POST'])
        self.app.add_url_rule('/settings/default_tts/', view_func=self.get_default_tts,
                              methods=['GET'])
        self.app.add_url_rule('/settings/default_tts/', view_func=self.set_default_tts,
                              methods=['POST'])
        self.app.add_url_rule('/settings/default_stt/', view_func=self.get_default_stt,
                              methods=['GET'])
        self.app.add_url_rule('/settings/default_stt/', view_func=self.set_default_stt,
                              methods=['POST'])
        self.app.add_url_rule('/settings/default_player/', view_func=self.get_default_player,
                              methods=['GET'])
        self.app.add_url_rule('/settings/default_player/', view_func=self.set_default_player,
                              methods=['POST'])
        self.app.add_url_rule('/settings/default_trigger/', view_func=self.get_default_trigger,
                              methods=['GET'])
        self.app.add_url_rule('/settings/default_trigger/', view_func=self.set_default_trigger,
                              methods=['POST'])
        self.app.add_url_rule('/settings/hooks/', view_func=self.get_hooks,
                              methods=['GET'])
        self.app.add_url_rule('/settings/hooks/', view_func=self.set_hooks,
                              methods=['POST'])
        self.app.add_url_rule('/settings/variables/', view_func=self.get_variables,
                              methods=['GET'])
        self.app.add_url_rule('/settings/variables/', view_func=self.set_variables,
                              methods=['POST'])