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.

pluginbase.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 gi.repository import GObject
  6. class PluginBase(GObject.Object):
  7. """Base class for Kaylee plugins
  8. Each Kaylee plugin module must define a subclass of this class, named
  9. ``Plugin``.
  10. """
  11. __gsignals__ = {
  12. 'processed' : (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
  13. (GObject.TYPE_STRING,)),
  14. 'tts' : (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
  15. (GObject.TYPE_STRING,))
  16. }
  17. def __init__(self, config, name):
  18. """Initialize the plugin
  19. All strings to be included in the corpus should be elements of
  20. ``corpus_strings`` by the end of __init__'s execution. Note however
  21. that the words required for number support are automatically included,
  22. so they need not be listed explicitly on a per-plugin basis.
  23. """
  24. super().__init__()
  25. self.config = config
  26. self.name = name
  27. self.options = config.plugins[name]
  28. self.corpus_strings = set()
  29. def recognizer_finished(self, recognizer, text):
  30. """Process a recognized voice command
  31. This method must return True if the command was handled by the plugin,
  32. and False otherwise. As soon as it has been determined that the
  33. command will be handled, this method must emit a ``processed`` signal
  34. with ``text`` as its parameter. If the plugin wants to speak some
  35. words to the user, it can do so by emitting a ``tts`` signal with the
  36. words to be spoken as its parameter.
  37. """
  38. return False