Somewhat fancy voice command recognition software
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

simple.py 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 .pluginbase import PluginBase
  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 confidence(self, text):
  19. """Return 0 if text is not the phrase, 1 if it is"""
  20. return 1 if text == self.options['phrase'] else 0
  21. def handle(self, text):
  22. """Print and speak the phrase"""
  23. # Is there a matching command?
  24. if self.confidence(text):
  25. print("Simple plugin says:", text)
  26. self.emit('tts', text)
  27. return True
  28. else:
  29. return False