Пример #1
0
    def say(self, message):
        """
        USe TTS to speak out loud the Message.
        A message can be a string, a list or a dict
        If it's a string, simply use the TTS with the message
        If it's a list, we select randomly a string in the list and give it to the TTS
        If it's a dict, we use the template given in parameter to create a string that we give to the TTS
        :param message: Can be a String or a dict or a list

        .. raises:: TTSModuleNotFound
        """
        logger.debug("[NeuronModule] Say() called with message: %s" % message)

        tts_message = None

        # we can save parameters from the neuron in memory
        Cortex.save_neuron_parameter_in_memory(self.intelora_memory, message)

        if isinstance(message, str) or isinstance(message, six.text_type):
            logger.debug("[NeuronModule] message is string")
            tts_message = message

        if isinstance(message, list):
            logger.debug("[NeuronModule] message is list")
            tts_message = random.choice(message)

        if isinstance(message, dict):
            logger.debug("[NeuronModule] message is dict")
            tts_message = self._get_message_from_dict(message)

        if tts_message is not None:
            logger.debug("[NeuronModule] tts_message to say: %s" % tts_message)
            self.tts_message = tts_message
            Utils.print_success(tts_message)

            # process the audio only if the no_voice flag is false
            if self.no_voice:
                logger.debug(
                    "[NeuronModule] no_voice is True, Intelora is muted")
            else:
                logger.debug(
                    "[NeuronModule] no_voice is False, make Intelora speaking")
                HookManager.on_start_speaking()
                # get the instance of the TTS module
                tts_folder = None
                if self.settings.resources:
                    tts_folder = self.settings.resources.tts_folder
                tts_module_instance = Utils.get_dynamic_class_instantiation(
                    package_name="tts",
                    module_name=self.tts.name,
                    parameters=self.tts.parameters,
                    resources_dir=tts_folder)

                # generate the audio file and play it
                tts_module_instance.say(tts_message)
                HookManager.on_stop_speaking()
Пример #2
0
    def test_get_dynamic_class_instantiation(self):
        """
        Test that an instance as been instantiate properly.
        """
        sl = SettingLoader()
        sl.settings.resource_dir = '/var/tmp/test/resources'

        neuron = Neuron(name='Say', parameters={'message': 'test dynamic class instantiate'})
        self.assertTrue(isinstance(Utils.get_dynamic_class_instantiation(package_name="neurons",
                                                                         module_name=neuron.name.capitalize(),
                                                                         parameters=neuron.parameters,
                                                                         resources_dir='/var/tmp/test/resources'),
                                   Say),
                        "Fail instantiate a class")
Пример #3
0
    def launch_neuron(cls, neuron):
        """
        Start a neuron plugin
        :param neuron: neuron object
        :type neuron: Neuron
        :return:
        """
        logger.debug("Run neuron: \"%s\"" % (neuron.__str__()))
        settings = cls.load_settings()
        neuron_folder = None
        if settings.resources:
            neuron_folder = settings.resources.neuron_folder

        return Utils.get_dynamic_class_instantiation(
            package_name="neurons",
            module_name=neuron.name,
            parameters=neuron.parameters,
            resources_dir=neuron_folder)
Пример #4
0
    def load_stt_plugin(self):
        if self.stt is None:
            self.stt_module_name = self.settings.default_stt_name

        logger.debug("[OrderListener] stt module name : %s" % self.stt_module_name)
        for stt_object in self.settings.stts:
            if stt_object.name == self.stt_module_name:
                stt_object.parameters["callback"] = self.callback
                # add the audio file path to the list of parameter if set
                if self.audio_file_path is not None:
                    stt_object.parameters["audio_file_path"] = self.audio_file_path

                stt_folder = None
                if self.settings.resources:
                    stt_folder = self.settings.resources.stt_folder
                return Utils.get_dynamic_class_instantiation(package_name='stt',
                                                             module_name=stt_object.name.capitalize(),
                                                             parameters=stt_object.parameters,
                                                             resources_dir=stt_folder)