test.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import sys
  2. import logging
  3. def _test_audio_in():
  4. import speech_recognition as sr
  5. with sr.Microphone() as source:
  6. recognizer = sr.Recognizer()
  7. recognizer.energy_threshold = 2000
  8. recognizer.listen(source)
  9. def _test_audio_out():
  10. import output.audio_output
  11. logging.info('Creating audio output service...')
  12. service = output.audio_output.AudioOutput()
  13. logging.info('Calling .success()...')
  14. service.success()
  15. logging.info('Calling .failure()...')
  16. service.failure()
  17. logging.info('Calling .tts("Hello World")...')
  18. service.tts('Hello World')
  19. logging.info('Done.')
  20. def run():
  21. if len(sys.argv) == 1:
  22. print '\n'.join([
  23. '1. Audio output',
  24. '2. Audio input',
  25. ])
  26. return
  27. choice = sys.argv[1]
  28. if choice == '1':
  29. _test_audio_out()
  30. elif choice == '2':
  31. _test_audio_in()
  32. if __name__ == "__main__":
  33. logging.basicConfig(stream=sys.stdout)
  34. logging.getLogger().setLevel(logging.DEBUG)
  35. run()