def __init__(self, options, status_file, macros_dir, sentences_dir, dictionaries_dir, models_dir): self.options = options self.macros_dir = macros_dir self.sentences_dir = sentences_dir self.dictionaries_dir = dictionaries_dir self.models_dir = models_dir #TODO read this form configuration file self.mode = self.__SYSTEM self.default_macro_file = 'system' self.status_file = status_file Helpers.write_in_file(self.status_file, self.mode) self.previous_hyp = "" self.init_macros() if self.options.generate or not os.listdir(self.sentences_dir) or not os.listdir(self.dictionaries_dir) or not os.listdir(self.models_dir): print("Creating dictionaries and models") SentencesGenerator.generate_sentences_files(self.sentences_dir, self.macros, self.passwords, self.usernames) DictionaryCreator.create_dictionaries_and_models(self.macros, self.sentences_dir, self.dictionaries_dir, self.models_dir) self.xmacro_writer = XmacroWriter() #TODO espeak as subprocess # espeak = subprocess.Popen("espeak -v " + self.macros['properties']['LANG'] , stdin=subprocess.PIPE, stdout=devnull, bufsize=1, close_fds=True) # self.espeak_pipe = espeak.stdin self.init_gst(self.default_macro_file) # or self.mode --- the names are the same self.gui_output = None self.mode_output = None self.say("I am ready for taking commands")
def change_mode(self, mode, load_file=False): self.mode = mode self.mode_output.set_text(mode) Helpers.write_in_file(self.status_file, self.mode) if load_file: self.pipeline.set_state(gst.STATE_NULL) if self.mode == self.__LISTENING: self.init_gst(self.__SYSTEM) else: self.init_gst(self.mode)
def change_mode(self, mode, load_file = False): self.mode = mode self.mode_output.set_text(mode) Helpers.write_in_file(self.status_file, self.mode) if load_file: self.pipeline.set_state(gst.STATE_NULL) if self.mode == self.__LISTENING: self.init_gst(self.__SYSTEM) else: self.init_gst(self.mode)
def __init__(self, options, status_file, macros_dir, sentences_dir, dictionaries_dir, models_dir): self.options = options self.macros_dir = macros_dir self.sentences_dir = sentences_dir self.dictionaries_dir = dictionaries_dir self.models_dir = models_dir #TODO read this form configuration file self.mode = self.__SYSTEM self.default_macro_file = 'system' self.status_file = status_file Helpers.write_in_file(self.status_file, self.mode) self.previous_hyp = "" self.init_macros() if self.options.generate or not os.listdir( self.sentences_dir) or not os.listdir( self.dictionaries_dir) or not os.listdir(self.models_dir): print("Creating dictionaries and models") SentencesGenerator.generate_sentences_files( self.sentences_dir, self.macros, self.passwords, self.usernames) DictionaryCreator.create_dictionaries_and_models( self.macros, self.sentences_dir, self.dictionaries_dir, self.models_dir) self.xmacro_writer = XmacroWriter() #TODO espeak as subprocess # espeak = subprocess.Popen("espeak -v " + self.macros['properties']['LANG'] , stdin=subprocess.PIPE, stdout=devnull, bufsize=1, close_fds=True) # self.espeak_pipe = espeak.stdin self.init_gst( self.default_macro_file) # or self.mode --- the names are the same self.gui_output = None self.mode_output = None self.say("I am ready for taking commands")
def __init__(self): # TODO maybe remove parser in new file parser = OptionParser() parser.add_option("-q", "--quiet", dest="quiet", action='store_true', default=False, help="Don't print anything") parser.add_option("-g", "--generate", dest="generate", action='store_true', default=False, help="Force generating sentences and dictionaries") parser.add_option("-s", "--no_sound", dest="espeak_output", action='store_false', default=True, help="No espeak audio messages") parser.add_option("-c", "--create_conf_files", dest="create_conf_files", action='store_true', default=False, help="Create inital configuration files") (self.options, args) = parser.parse_args() vc_dir = os.path.dirname(sys.argv[0]) if vc_dir == '': vc_dir = '.' # Check system core files try: default_macros_dir = Helpers.check_path(vc_dir, 'macros') if not os.path.exists(default_macros_dir + 'system'): raise Exception("Unable to continue: System macro file don't exist in %s!" % (default_macros_dir)) if not os.path.exists(default_macros_dir + 'passwords'): raise Exception("Unable to continue: Passwords macro file don't exist in %s!" % (default_macros_dir)) if not os.path.exists(default_macros_dir + 'usernames'): raise Exception("Unable to continue: User-names macro file don't exist in %s!" % (default_macros_dir)) except Exception as message: print(message) sys.exit(1) vc_conf_dir = Helpers.check_path(os.environ['HOME'], '.voice-control', True) self.macros_dir = Helpers.check_path(vc_conf_dir, 'macros', True) self.sentences_dir = Helpers.check_path(vc_conf_dir, 'sentences', True) self.dictionaries_dir = Helpers.check_path(vc_conf_dir, 'dictionaries', True) self.models_dir = Helpers.check_path(vc_conf_dir, 'models', True) # Check if status file exist if not then is first run status_file = vc_conf_dir + 'mode' if not os.path.exists(status_file) or self.options.create_conf_files: print "Starting first time: Creating macro-files" Helpers.write_in_file(status_file, '') macros, passwords, usernames = ConfigurationReaderWriter.read_macros_directory(default_macros_dir) ConfigurationReaderWriter.write_macros_directory(self.macros_dir, macros, passwords, usernames) self.logic = Logic(self.options, status_file, self.macros_dir, self.sentences_dir, self.dictionaries_dir, self.models_dir) self.window = Window(self.logic)
def write_macros_directory(macros_dir, macros, passwords = None, usernames = None): if passwords != None: Helpers.write_in_file(macros_dir + "passwords", passwords.keys()) if usernames != None: Helpers.write_in_file(macros_dir + "usernames", ConfigurationReaderWriter.__create_list_of_system_actions(usernames)) system_file = macros_dir + "system" Helpers.write_in_file(system_file, '') for key in macros.keys(): if key == 'non_system': for non_system_key in macros['non_system'].keys(): Helpers.write_in_file(macros_dir + non_system_key, ConfigurationReaderWriter.__create_list_of_actions(macros['non_system'][non_system_key])) else: Helpers.append_in_file(system_file, "section " + key + "\n") if key.startswith('window_manager') or key == 'system_wide': Helpers.append_in_file(system_file, ConfigurationReaderWriter.__create_list_of_actions(macros[key])) else: Helpers.append_in_file(system_file, ConfigurationReaderWriter.__create_list_of_system_actions(macros[key]))
def write_macros_directory(macros_dir, macros, passwords=None, usernames=None): if passwords != None: Helpers.write_in_file(macros_dir + "passwords", passwords.keys()) if usernames != None: Helpers.write_in_file( macros_dir + "usernames", ConfigurationReaderWriter.__create_list_of_system_actions(usernames) ) system_file = macros_dir + "system" Helpers.write_in_file(system_file, "") for key in macros.keys(): if key == "non_system": for non_system_key in macros["non_system"].keys(): Helpers.write_in_file( macros_dir + non_system_key, ConfigurationReaderWriter.__create_list_of_actions(macros["non_system"][non_system_key]), ) else: Helpers.append_in_file(system_file, "section " + key + "\n") if key.startswith("window_manager") or key == "system_wide": Helpers.append_in_file(system_file, ConfigurationReaderWriter.__create_list_of_actions(macros[key])) else: Helpers.append_in_file( system_file, ConfigurationReaderWriter.__create_list_of_system_actions(macros[key]) )