Somewhat fancy voice command recognition software
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

pluginbase.py 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. 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. 'tts' : (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
  13. (GObject.TYPE_STRING,))
  14. }
  15. def __init__(self, config, name):
  16. """Initialize the plugin
  17. All strings to be included in the corpus should be elements of
  18. ``corpus_strings`` by the end of __init__'s execution. Note however
  19. that the words required for number support are automatically included,
  20. so they need not be listed explicitly on a per-plugin basis.
  21. """
  22. super().__init__()
  23. self.config = config
  24. self.name = name
  25. self.options = config.plugins[name]
  26. self.corpus_strings = set()
  27. def confidence(self, text):
  28. """Return the confidence (0-1) with which this plugin can handle text
  29. This method must return 1 if the command is definitely supposed to be
  30. handled by this plugin (text is exactly a sentence configured to
  31. perform some action) and must return 0 if the command is not recognized
  32. at all. The method must also return 0 if the command is recognized,
  33. but for some reason would not perform any action currently, e.g. "pause
  34. music" when no music player is running. Intermediate values may be
  35. used to indicate that text may be a command this plugin should handle,
  36. but was misunderstood by the speech recognition system.
  37. """
  38. return 0
  39. def handle(self, text):
  40. """Process a recognized voice command
  41. This method must return True if the command was handled by the plugin,
  42. and False otherwise. If the plugin wants to speak some words to the
  43. user, it can do so by emitting a ``tts`` signal with the words to be
  44. spoken as its parameter.
  45. """
  46. return False