Somewhat fancy voice command recognition software
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pluginutils.py 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # This is part of Kaylee
  2. # -- this code is licensed GPLv3
  3. # Copyright 2015-2017 Clayton G. Hobbs
  4. # Portions Copyright 2013 Jezra
  5. """Helper utilities for Kaylee plugins"""
  6. import time
  7. def format_temperature(temperature, precision, unit='degrees Fahrenheit'):
  8. """Format a temperature for the TTS system"""
  9. return f'{temperature:.{precision}f} {unit}'
  10. def format_percent(value):
  11. """Format a floating-point value as a percentage for the TTS system"""
  12. return f'{100*value:.0f} percent'
  13. def format_time(seconds=None):
  14. """Format a time in seconds since the Epoch for the TTS system"""
  15. t = time.localtime(seconds)
  16. # Format each part of the time to be pronounced nicely
  17. hour = time.strftime('%I', t)
  18. if hour[0] == '0':
  19. hour = hour[1]
  20. minute = time.strftime('%M', t)
  21. if minute[0] == '0':
  22. if minute[1] == '0':
  23. minute = "o'clock"
  24. else:
  25. minute = 'O' + minute[1]
  26. ante_post = time.strftime('%p', t)
  27. if ante_post[0] == 'A':
  28. ante_post = 'AE ' + ante_post[1]
  29. elif ante_post[0] == 'P':
  30. ante_post = 'P ' + ante_post[1]
  31. # Put the parts together
  32. return f'{hour} {minute} {ante_post}'