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.

pluginbase.py 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # This is part of Kaylee
  2. # -- this code is licensed GPLv3
  3. # Copyright 2015-2016 Clayton G. Hobbs
  4. # Portions Copyright 2013 Jezra
  5. from abc import ABCMeta, abstractmethod
  6. from gi.repository import GObject
  7. from gi.types import GObjectMeta
  8. class GObjectABCMeta(ABCMeta, GObjectMeta):
  9. pass
  10. class PluginBase(GObject.Object, metaclass=GObjectABCMeta):
  11. """Base class for Kaylee plugins
  12. Each Kaylee plugin module must define a subclass of this class, named
  13. ``Plugin``.
  14. """
  15. __gsignals__ = {
  16. 'processed' : (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
  17. (GObject.TYPE_STRING,))
  18. }
  19. def __init__(self, config, name):
  20. """Initialize the plugin
  21. All strings to be included in the corpus should be elements of
  22. ``corpus_strings`` by the end of __init__'s execution. Note however
  23. that the words required for number support are automatically included,
  24. so they need not be listed explicitly on a per-plugin basis.
  25. """
  26. super().__init__()
  27. self.config = config
  28. self.name = name
  29. self.corpus_strings = set()
  30. @abstractmethod
  31. def recognizer_finished(self, recognizer, text):
  32. """Process a recognized voice command
  33. This method must return True if the command was handled by the plugin,
  34. and False otherwise. As soon as it has been determined that the
  35. command will be handled, this method must emit a ``processed`` signal
  36. with ``text`` as its parameter.
  37. """
  38. pass