def audio_analyser_callback(self, order): """ Callback of the OrderListener. Called after the processing of the audio file This method will - call the Order Analyser to analyse the order and launch corresponding synapse as usual. - get a list of launched synapse. - give the list to the main process via self.launched_synapses - notify that the processing is over via order_analyser_return :param order: string order to analyse :return: """ logger.debug("order to process %s" % order) if order is not None: # maybe we have received a null audio from STT engine order_analyser = OrderAnalyser(order, brain=self.brain) synapses_launched = order_analyser.start() self.launched_synapses = synapses_launched else: if self.settings.default_synapse is not None: SynapseLauncher.start_synapse( name=self.settings.default_synapse, brain=self.brain) self.launched_synapses = self.brain.get_synapse_by_name( synapse_name=self.settings.default_synapse) # this boolean will notify the main process that the order have been processed self.order_analyser_return = True
def run_synapse_by_name_with_order(self, order, synapse_name, order_template): """ Run a synapse using its name, and giving an order so it can retrieve its params. Useful for neurotransmitters. :param order: the order to match :param synapse_name: the name of the synapse :param order_template: order_template coming from the neurotransmitter :return: True if a synapse as been found and started using its params """ synapse_to_run = self.brain.get_synapse_by_name( synapse_name=synapse_name) if synapse_to_run: # Make a list with the synapse logger.debug( "[run_synapse_by_name_with_order]-> a synapse has been found %s" % synapse_to_run.name) list_to_run = list() list_to_run.append(synapse_to_run) oa = OrderAnalyser(order=order, brain=self.brain) oa.start(synapses_to_run=list_to_run, external_order=order_template) else: logger.debug( "[NeuronModule]-> run_synapse_by_name_with_order, the synapse has not been found : %s" % synapse_name) return synapse_to_run is not None
def run_synapse_by_order(self): """ Give an order to Kalliope via API like it was from a spoken one Test with curl curl -i --user admin:secret -H "Content-Type: application/json" -X POST -d '{"order":"my order"}' http://localhost:5000/synapses/start/order In case of quotes in the order or accents, use a file cat post.json: {"order":"j'aime"} curl -i --user admin:secret -H "Content-Type: application/json" -X POST --data @post.json http://localhost:5000/order/ :return: """ if not request.get_json() or 'order' not in request.get_json(): abort(400) order = request.get_json('order') if order is not None: # get the order order_to_run = order["order"] oa = OrderAnalyser(order=order_to_run, brain=self.brain) launched_synapses = oa.start() if launched_synapses: # if the list is not empty, we have launched one or more synapses data = jsonify( synapses=[e.serialize() for e in launched_synapses]) return data, 201 else: data = {"error": "The given order doesn't match any synapses"} return jsonify(error=data), 400 else: data = {"error": "order cannot be null"} return jsonify(error=data), 400
def is_order_matching(self, order_said, order_match): oa = OrderAnalyser(order=order_said, brain=self.brain) return oa.spelt_order_match_brain_order_via_table( order_to_analyse=order_match, user_said=order_said)