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.

__init__.py 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. class PluginBase():
  6. """Base class for Kaylee plugins
  7. Each Kaylee plugin module must define a subclass of this class, named
  8. ``Plugin``.
  9. """
  10. def __init__(self, config, name):
  11. """Initialize the plugin
  12. All strings to be included in the corpus should be elements of
  13. ``corpus_strings`` by the end of __init__'s execution. Note however
  14. that the words required for number support are automatically included,
  15. so they need not be listed explicitly on a per-plugin basis.
  16. """
  17. super().__init__()
  18. self.config = config
  19. self.name = name
  20. self.options = config.plugins[name]
  21. self.corpus_strings = set()
  22. def get_handler(self, text):
  23. """Return a handler for the given text
  24. This method returns a Handler object which handles the command when
  25. called. If the plugin does not recognize the command at all, this
  26. method must return None instead. The method must also return None if
  27. the command is recognized, but for some reason would not perform any
  28. action currently, e.g. "pause music" when no music player is running.
  29. """
  30. return None
  31. class Handler:
  32. """Base class for Kaylee plugin handlers
  33. Plugins should subclass this for their own command handlers.
  34. """
  35. def __init__(self, confidence):
  36. """Initialize the handler
  37. The confidence with which this handler will handle the command must be
  38. passed as ``confidence``, a floating-point number in (0, 1]. A
  39. confidence of 1 indicates that the handler is definitely supposed to
  40. handle the command it was created for. Values between 0 and 1 may be
  41. used to indicate that the plugin may be able to handle the command,
  42. but it was misunderstood by the speech recognition system.
  43. """
  44. self.confidence = confidence
  45. def __call__(self, tts):
  46. """Handle the command
  47. When called, ``tts`` is a function which takes a string as its only
  48. parameter and passes it to Kaylee's configured text-to-speech system.
  49. """