neurotransmitter.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 audio
  17. def _links_content_ok(self):
  18. """
  19. Check the content of the links parameter
  20. :return:
  21. """
  22. if self.links is None:
  23. raise MissingParameterException("links parameter required and must contain at least one link")
  24. for el in self.links:
  25. if "synapse" not in el:
  26. raise MissingParameterException("Links must contain a synapse name: %s" % el)
  27. if "answers" not in el:
  28. raise MissingParameterException("Links must contain answers: %s" % el)
  29. return True