def get_list_match_synapse(cls, order, synapse_order_tuple): list_match_synapse = list() for synapse in cls.brain.synapses: if synapse.enabled: for signal in synapse.signals: # we are only concerned by synapse with a order type of signal if signal.name == "order": # get the type of matching expected, by default "normal" expected_matching_type = "normal" signal_order = None if isinstance(signal.parameters, str) or isinstance(signal.parameters, six.text_type): signal_order = signal.parameters if isinstance(signal.parameters, dict): try: signal_order = signal.parameters["text"] except KeyError: logger.debug("[OrderAnalyser] Warning, missing parameter 'text' in order. " "Order will be skipped") continue expected_matching_type = cls.get_matching_type(signal) order = cls.order_correction(order, signal) if cls.is_order_matching(user_order=order, signal_order=signal_order, expected_order_type=expected_matching_type): # the order match the synapse, we add it to the returned list logger.debug("Order found! Run synapse name: %s" % synapse.name) Utils.print_info("Brain: order recognized") Utils.print_success(" * Running synapse \"%s\"" % synapse.name) list_match_synapse.append(synapse_order_tuple(synapse=synapse, order=signal_order)) return list_match_synapse
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.brain_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_info("Player Engine: " + tts_message) # save in brain memory the last tts message Cortex.save("brain_last_tts_message", tts_message) # process the audio only if the mute flag is false if self.settings.options.mute: logger.debug("[NeuronModule] mute is True, Brain.ai is muted") else: logger.debug( "[NeuronModule] mute is False, make Brain.ai 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()