todo.py 774 B

1234567891011121314151617181920212223242526272829303132333435
  1. import logging
  2. import base
  3. import tts
  4. import clips
  5. import ears
  6. _LISTEN_TIMEOUT = 600
  7. _GROCERIES = ['milk', 'bread']
  8. class WunderbarTodo(base.BaseFunction):
  9. def _groceries(self):
  10. tts.tts('ready')
  11. lines, terminator = ears.listen_until_terminated(timeout=_LISTEN_TIMEOUT, preferred_phrases=_GROCERIES)
  12. if terminator == 'cancel':
  13. tts.tts('cancelled')
  14. return
  15. else:
  16. items = []
  17. for line in lines:
  18. items.extend([t.strip() for t in line.split(' and ') if t.strip()])
  19. logging.info(items)
  20. tts.tts('ok')
  21. def call(self, trigger=None, **_):
  22. if trigger == 'food':
  23. self._groceries()
  24. else:
  25. tts.tts('Bad trigger')