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.

simple.py 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. """A simple plugin to serve as an example
  6. This is an extremely minimal Kaylee plugin to serve as an example for
  7. developing more complex plugins. It takes a single configuration
  8. option, "phrase", which is a sentence to be recognized. Once this is
  9. heard, the plugin prints "Simple plugin says: [phrase]".
  10. """
  11. from . import PluginBase, Handler
  12. class Plugin(PluginBase):
  13. """Main class for the simple plugin"""
  14. def __init__(self, config, name):
  15. """Initialize the simple plugin"""
  16. super().__init__(config, name)
  17. self.corpus_strings.add(self.options['phrase'])
  18. def get_handler(self, text):
  19. """Return a handler if and only if the phrase is heard"""
  20. if text == self.options['phrase']:
  21. return SimpleHandler(1, text)
  22. else:
  23. return None
  24. class SimpleHandler(Handler):
  25. """Handler for the simple plugin"""
  26. def __init__(self, confidence, text):
  27. """Store the phrase that was heard"""
  28. super().__init__(confidence)
  29. self.text = text
  30. def __call__(self, tts):
  31. """Print and speak the phrase"""
  32. print("Simple plugin says:", self.text)
  33. tts(self.text)