main.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import logging
  2. import sys
  3. import signal
  4. import input_sources
  5. import output
  6. import services
  7. import util.curses_util
  8. import conf
  9. _INTERRUPTED = False
  10. def _signal_handler(*_):
  11. global _INTERRUPTED
  12. _INTERRUPTED = True
  13. def _interrupt_callback():
  14. global _INTERRUPTED
  15. return _INTERRUPTED
  16. def _init_logging():
  17. if conf.LOGFILE is not None:
  18. logging.basicConfig(filename=conf.LOGFILE)
  19. logging.getLogger().setLevel(logging.DEBUG)
  20. def cb():
  21. print 'CB!'
  22. def test():
  23. import snowboy.snowboydecoder
  24. model = 'resources/snowboy/alexa.umdl'
  25. detector = snowboy.snowboydecoder.HotwordDetector(model, sensitivity=0.5)
  26. print 'a'
  27. detector.start(detected_callback=cb, interrupt_check=_interrupt_callback)
  28. print 'b'
  29. detector.terminate()
  30. print 'c'
  31. def _run(cclient):
  32. _init_logging()
  33. signal.signal(signal.SIGINT, _signal_handler)
  34. output.init_services(cclient)
  35. input_sources.launch_input_sources(cclient)
  36. services.launch_services(cclient, _interrupt_callback)
  37. if __name__ == "__main__":
  38. if False:
  39. test()
  40. else:
  41. cclient = util.curses_util.CursesClient()
  42. cclient.title = 'voice_control'
  43. cclient.show_cursor = False
  44. input_sources.CURSES_CLIENT = cclient
  45. output.CURSES_CLIENT = cclient
  46. cclient.run(_run, intercept_output_streams=True, cclient=cclient)