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.

config.py 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # This is part of Kaylee
  2. # -- this code is licensed GPLv3
  3. # Copyright 2013 Jezra
  4. # Copyright 2015 Clayton G. Hobbs
  5. import json
  6. import os
  7. from argparse import ArgumentParser, Namespace
  8. from gi.repository import GLib
  9. class Config:
  10. conf_dir = os.path.expanduser(os.path.join(GLib.get_user_config_dir(),
  11. "blather"))
  12. opt_file = os.path.join(conf_dir, "options.json")
  13. def __init__(self):
  14. # Set up the argument parser
  15. self.parser = ArgumentParser()
  16. self.parser.add_argument("-i", "--interface", type=str,
  17. dest="interface", action='store',
  18. help="Interface to use (if any). 'g' for GTK or 'gt' for GTK" +
  19. " system tray icon")
  20. self.parser.add_argument("-c", "--continuous",
  21. action="store_true", dest="continuous", default=False,
  22. help="starts interface with 'continuous' listen enabled")
  23. self.parser.add_argument("-p", "--pass-words",
  24. action="store_true", dest="pass_words", default=False,
  25. help="passes the recognized words as arguments to the shell" +
  26. " command")
  27. self.parser.add_argument("-H", "--history", type=int,
  28. action="store", dest="history",
  29. help="number of commands to store in history file")
  30. self.parser.add_argument("-m", "--microphone", type=int,
  31. action="store", dest="microphone", default=None,
  32. help="Audio input card to use (if other than system default)")
  33. self.parser.add_argument("--valid-sentence-command", type=str,
  34. dest="valid_sentence_command", action='store',
  35. help="command to run when a valid sentence is detected")
  36. self.parser.add_argument("--invalid-sentence-command", type=str,
  37. dest="invalid_sentence_command", action='store',
  38. help="command to run when an invalid sentence is detected")
  39. # Read the configuration file
  40. with open(self.opt_file, 'r') as f:
  41. self.options = json.load(f)
  42. self.options = Namespace(**self.options)
  43. # Parse command-line arguments, overriding config file as appropriate
  44. self.args = self.parser.parse_args(namespace=self.options)