neurotransmitter.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import logging
  2. from core.NeuronModule import NeuronModule, MissingParameterException
  3. logging.basicConfig()
  4. logger = logging.getLogger("kalliope")
  5. class Neurotransmitter(NeuronModule):
  6. def __init__(self, **kwargs):
  7. super(Neurotransmitter, self).__init__(**kwargs)
  8. # get links
  9. self.links = kwargs.get('links', None)
  10. # do some check
  11. if self._links_content_ok():
  12. # the brain seems fine, we call the stt to get an audio
  13. self.get_audio_from_stt(callback=self.callback)
  14. def callback(self, audio):
  15. logger.debug("Neurotransmitter, receiver audio from STT: %s" % audio)
  16. print self.links
  17. for el in self.links:
  18. if audio in el["answers"]:
  19. print "found"
  20. self.run_synapse_ny_name(el["synapse"])
  21. # we don't need to check to rest of answer
  22. break
  23. def _links_content_ok(self):
  24. """
  25. Check the content of the links parameter
  26. :return:
  27. """
  28. if self.links is None:
  29. raise MissingParameterException("links parameter required and must contain at least one link")
  30. for el in self.links:
  31. if "synapse" not in el:
  32. raise MissingParameterException("Links must contain a synapse name: %s" % el)
  33. if "answers" not in el:
  34. raise MissingParameterException("Links must contain answers: %s" % el)
  35. return True