Somewhat fancy voice command recognition software
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. import subprocess
  6. from .pluginbase import PluginBase
  7. from ..numbers import NumberParser
  8. class Plugin(PluginBase):
  9. def __init__(self, config, name):
  10. super().__init__(config, name)
  11. self.number_parser = NumberParser()
  12. self.commands = self.options
  13. for voice_cmd in self.commands.keys():
  14. self.corpus_strings.add(voice_cmd.strip().replace('%d', ''))
  15. def _run_command(self, cmd):
  16. """Print the command, then run it"""
  17. print(cmd)
  18. subprocess.call(cmd, shell=True)
  19. def recognizer_finished(self, recognizer, text):
  20. """Process a recognized voice command
  21. Recognized commands have the corresponding shell commands executed,
  22. possibly with number(s) substituted.
  23. """
  24. numt, nums = self.number_parser.parse_all_numbers(text)
  25. # Is there a matching command?
  26. if text in self.commands:
  27. self.emit('processed', text)
  28. cmd = self.commands[text]
  29. self._run_command(cmd)
  30. return True
  31. # Is there a matching command with numbers substituted?
  32. elif numt in self.commands:
  33. self.emit('processed', text)
  34. cmd = self.commands[numt]
  35. cmd = cmd.format(*nums)
  36. self._run_command(cmd)
  37. return True
  38. else:
  39. return False