def main(ready_hook=on_ready, error_hook=on_error, stopping_hook=on_stopping): # Read the system configuration """Launch one of the available enclosure implementations. This depends on the configured platform and can currently either be mycroft_mark_1 or mycroft_mark_2, if unconfigured a generic enclosure with only the GUI bus will be started. """ # Read the system configuration system_config = LocalConf(SYSTEM_CONFIG) platform = system_config.get("enclosure", {}).get("platform") enclosure = create_enclosure(platform) if enclosure: try: LOG.debug("Enclosure started!") reset_sigint_handler() create_daemon(enclosure.run) ready_hook() wait_for_exit_signal() stopping_hook() except Exception as e: print(e) else: LOG.info("No enclosure available for this hardware, running headless")
def change_to_pico(self): conf = LocalConf(USER_CONFIG) conf["tts"] = { "module": "ovos-tts-plugin-pico" } conf.store() self.bus.emit(Message("configuration.patch", {"config": conf}))
def main(): # Read the system configuration system_config = LocalConf(SYSTEM_CONFIG) platform = system_config.get("enclosure", {}).get("platform") if platform == "mycroft_mark_1": LOG.debug("Creating Mark I Enclosure") from mycroft.client.enclosure.mark1 import EnclosureMark1 enclosure = EnclosureMark1() elif platform == "mycroft_mark_2": LOG.debug("Creating Mark II Enclosure") from mycroft.client.enclosure.mark2 import EnclosureMark2 enclosure = EnclosureMark2() else: LOG.debug("Creating generic enclosure, platform='{}'".format(platform)) # TODO: Mechanism to load from elsewhere. E.g. read a script path from # the mycroft.conf, then load/launch that script. from mycroft.client.enclosure.generic import EnclosureGeneric enclosure = EnclosureGeneric() if enclosure: try: LOG.debug("Enclosure started!") enclosure.run() except Exception as e: print(e) finally: sys.exit() else: LOG.debug("No enclosure available for this hardware, running headless")
def change_to_mimic2(self): conf = LocalConf(USER_CONFIG) conf["tts"] = { "module": "mimic2" } conf.store() self.bus.emit(Message("configuration.patch", {"config": conf}))
def __init__(self, key_phrase="hey mycroft", config=None, lang="en-us"): super(PreciseHotword, self).__init__(key_phrase, config, lang) from precise_runner import (PreciseRunner, PreciseEngine, ReadWriteStream) local_conf = LocalConf(USER_CONFIG) if local_conf.get('precise', {}).get('dist_url') == \ 'http://bootstrap.mycroft.ai/artifacts/static/daily/': del local_conf['precise']['dist_url'] local_conf.store() Configuration.updated(None) self.download_complete = True self.show_download_progress = Timer(0, lambda: None) precise_config = Configuration.get()['precise'] precise_exe = self.install_exe(precise_config['dist_url']) self.precise_model = self.install_model( precise_config['model_url'], key_phrase.replace(' ', '-')).replace('.tar.gz', '.pb') self.has_found = False self.stream = ReadWriteStream() def on_activation(): self.has_found = True self.runner = PreciseRunner(PreciseEngine(precise_exe, self.precise_model), stream=self.stream, on_activation=on_activation) self.runner.start()
def deactivate_deprecated(self, message=None): # Deactivate official skill # TODO depending on https://github.com/MycroftAI/skill-speak/issues/24 # code bellow can be removed skills_config = self.config_core.get("skills", {}) blacklisted_skills = skills_config.get("blacklisted_skills", []) config = LocalConf(USER_CONFIG) blacklisted_skills += config.get("skills", {}).get("blacklisted_skills", []) store = False for skill in ["skill-repeat-recent", "mycroft-speak.mycroftai"]: if skill not in blacklisted_skills: self.log.info("Parrot skill blacklisted conflicting skill " + skill) self.bus.emit( Message('skillmanager.deactivate', {"skill": skill})) blacklisted_skills.append(skill) if "skills" not in config: config["skills"] = {} if "blacklisted_skills" not in config["skills"]: config["skills"]["blacklisted_skills"] = [] config["skills"]["blacklisted_skills"] += blacklisted_skills store = True if store: config.store()
def change_to_chromium(self): conf = LocalConf(USER_CONFIG) conf["stt"] = { "module": "ovos-stt-plugin-chromium" } conf.store() self.bus.emit(Message("configuration.patch", {"config": conf}))
def blacklist_default_skill(self): # load the current list of already blacklisted skills blacklist = self.config_core["skills"]["blacklisted_skills"] # check the folder name (skill_id) of the skill you want to replace skill_id = "mycroft-fallback-duck-duck-go.mycroftai" # add the skill to the blacklist if skill_id not in blacklist: self.log.debug("Blacklisting official mycroft skill") blacklist.append(skill_id) # load the user config file (~/.mycroft/mycroft.conf) conf = LocalConf(USER_CONFIG) if "skills" not in conf: conf["skills"] = {} # update the blacklist field conf["skills"]["blacklisted_skills"] = blacklist # save the user config file conf.store() # tell the intent service to unload the skill in case it was loaded already # this should avoid the need to restart self.bus.emit(Message("detach_skill", {"skill_id": skill_id}))
def change_to_kaldi(self): conf = LocalConf(USER_CONFIG) conf["stt"] = { "module": "ovos-stt-plugin-vosk-streaming", "ovos-stt-plugin-vosk-streaming": { "model": expanduser( "~/.local/share/vosk/vosk-model-small-en-us-0.15") } } conf.store() self.bus.emit(Message("configuration.patch", {"config": conf}))
def change_to_larynx(self): conf = LocalConf(USER_CONFIG) conf["tts"] = { "module": "neon-tts-plugin-larynx-server", "neon-tts-plugin-larynx-server": { "host": "http://tts.neon.ai", "voice": "mary_ann", "vocoder": "hifi_gan/vctk_small" } } conf.store() self.bus.emit(Message("configuration.patch", {"config": conf}))
def change_voice(self, engine, voice): self.selected_voice = (engine, voice) if engine == "polly": voice = voice.capitalize() tts_config = self.config_core.get("tts", {}) tts_config["module"] = engine if engine not in tts_config: tts_config[engine] = {} tts_config[engine]["voice"] = voice tts_config[engine]["lang"] = self.lang config = LocalConf(USER_CONFIG) config["tts"] = tts_config config.store() self.bus.emit(Message("configuration.updated")) self.speak_dialog("engine.changed", {"engine": engine, "voice": voice})
def __init__(self, key_phrase="hey mycroft", config=None, lang="en-us"): super().__init__(key_phrase, config, lang) global install_package from petact import install_package from precise_runner import (PreciseRunner, PreciseEngine, ReadWriteStream) local_conf = LocalConf(USER_CONFIG) if (local_conf.get('precise', {}).get('dist_url') == 'http://bootstrap.mycroft.ai/artifacts/static/daily/'): del local_conf['precise']['dist_url'] local_conf.store() Configuration.updated(None) self.download_complete = True self.show_download_progress = Timer(0, lambda: None) precise_config = Configuration.get()['precise'] precise_exe = self.update_precise(precise_config) local_model = self.config.get('local_model_file') if local_model: self.precise_model = expanduser(local_model) else: self.precise_model = self.install_model( precise_config['model_url'], key_phrase.replace(' ', '-')).replace('.tar.gz', '.pb') self.has_found = False self.stream = ReadWriteStream() def on_activation(): self.has_found = True trigger_level = self.config.get('trigger_level', 3) sensitivity = self.config.get('sensitivity', 0.5) self.runner = PreciseRunner( PreciseEngine(precise_exe, self.precise_model), trigger_level, sensitivity, stream=self.stream, on_activation=on_activation, ) self.runner.start()
def make_priority(self): if not self.skill_id: # might not be set yet.... return # load the current list of priority skills priority_list = self.config_core["skills"]["priority_skills"] # add the skill to the priority list if self.skill_id not in priority_list: priority_list.insert(0, self.skill_id) # load the user config file (~/.mycroft/mycroft.conf) conf = LocalConf(USER_CONFIG) if "skills" not in conf: conf["skills"] = {} # update the priority skills field conf["skills"]["priority_skills"] = priority_list # save the user config file conf.store()
def __init__(self, key_phrase="hey mycroft", config=None, lang="en-us"): super(PreciseHotword, self).__init__(key_phrase, config, lang) from precise_runner import ( PreciseRunner, PreciseEngine, ReadWriteStream ) local_conf = LocalConf(USER_CONFIG) if local_conf.get('precise', {}).get('dist_url') == \ 'http://bootstrap.mycroft.ai/artifacts/static/daily/': del local_conf['precise']['dist_url'] local_conf.store() Configuration.updated(None) self.download_complete = True self.show_download_progress = Timer(0, lambda: None) precise_config = Configuration.get()['precise'] precise_exe = self.install_exe(precise_config['dist_url']) local_model = self.config.get('local_model_file') if local_model: self.precise_model = expanduser(local_model) else: self.precise_model = self.install_model( precise_config['model_url'], key_phrase.replace(' ', '-') ).replace('.tar.gz', '.pb') self.has_found = False self.stream = ReadWriteStream() def on_activation(): self.has_found = True self.runner = PreciseRunner( PreciseEngine(precise_exe, self.precise_model), stream=self.stream, on_activation=on_activation ) self.runner.start()
def enable_selene(self): config = { "stt": {"module": "mycroft"}, "server": { "url": "https://api.mycroft.ai", "version": "v1" }, "listener": { "wake_word_upload": { "url": "https://training.mycroft.ai/precise/upload" } } } conf = LocalConf(USER_CONFIG) conf.update(config) conf.store() self.using_mock = False self.bus.emit(Message("configuration.patch", {"config": config}))
def enable_mock(self): url = "http://0.0.0.0:{p}".format(p=CONFIGURATION["backend_port"]) version = CONFIGURATION["api_version"] config = { "server": { "url": url, "version": version }, # no web ui to set location, best guess from ip address # should get at least timezone right "location": ip_geolocate("0.0.0.0"), "listener": { "wake_word_upload": { "url": "http://0.0.0.0:{p}/precise/upload".format( p=CONFIGURATION["backend_port"]) } } } conf = LocalConf(USER_CONFIG) conf.update(config) conf.store() self.using_mock = True self.bus.emit(Message("configuration.patch", {"config": config}))
def __init__(self, key_phrase="hey mycroft", config=None, lang="en-us"): super().__init__(key_phrase, config, lang) from precise_runner import ( PreciseRunner, PreciseEngine, ReadWriteStream ) # We need to save to a writeable location, but the key we need # might be stored in a different, unwriteable, location # Make sure we pick the key we need from wherever it's located, # but save to a writeable location only local_conf = LocalConf( join(xdg.BaseDirectory.xdg_config_home, 'mycroft', 'mycroft.conf') ) for conf_dir in xdg.BaseDirectory.load_config_paths('mycroft'): conf = LocalConf(join(conf_dir, 'mycroft.conf')) # If the current config contains the precise key use it, # otherwise continue to the next file if conf.get('precise', None) is not None: local_conf['precise'] = conf.get('precise', None) break # If the key is not found yet, it might still exist on the old # (deprecated) location if local_conf.get('precise', None) is None: local_conf = LocalConf(OLD_USER_CONFIG) if not local_conf.get('precise', {}).get('use_precise', True): raise PreciseUnavailable if (local_conf.get('precise', {}).get('dist_url') == 'http://bootstrap.mycroft.ai/artifacts/static/daily/'): del local_conf['precise']['dist_url'] local_conf.store() Configuration.updated(None) self.download_complete = True self.show_download_progress = Timer(0, lambda: None) precise_config = Configuration.get()['precise'] precise_exe = self.update_precise(precise_config) local_model = self.config.get('local_model_file') if local_model: self.precise_model = expanduser(local_model) else: self.precise_model = self.install_model( precise_config['model_url'], key_phrase.replace(' ', '-') ).replace('.tar.gz', '.pb') self.has_found = False self.stream = ReadWriteStream() def on_activation(): self.has_found = True trigger_level = self.config.get('trigger_level', 3) sensitivity = self.config.get('sensitivity', 0.5) self.runner = PreciseRunner( PreciseEngine(precise_exe, self.precise_model), trigger_level, sensitivity, stream=self.stream, on_activation=on_activation, ) self.runner.start()
def process(self, data): # TODO: Look into removing this emit altogether. # We need to check if any other serial bus messages # are handled by other parts of the code if "mycroft.stop" not in data: self.bus.emit(Message(data)) if "Command: system.version" in data: # This happens in response to the "system.version" message # sent during the construction of Enclosure() self.bus.emit(Message("enclosure.started")) if "mycroft.stop" in data: if has_been_paired(): create_signal('buttonPress') self.bus.emit(Message("mycroft.stop")) if "volume.up" in data: self.bus.emit(Message("mycroft.volume.increase", {'play_sound': True})) if "volume.down" in data: self.bus.emit(Message("mycroft.volume.decrease", {'play_sound': True})) if "system.test.begin" in data: self.bus.emit(Message('recognizer_loop:sleep')) if "system.test.end" in data: self.bus.emit(Message('recognizer_loop:wake_up')) if "mic.test" in data: mixer = Mixer() prev_vol = mixer.getvolume()[0] mixer.setvolume(35) self.bus.emit(Message("speak", { 'utterance': "I am testing one two three"})) time.sleep(0.5) # Prevents recording the loud button press record("/tmp/test.wav", 3.0) mixer.setvolume(prev_vol) play_wav("/tmp/test.wav").communicate() # Test audio muting on arduino subprocess.call('speaker-test -P 10 -l 0 -s 1', shell=True) if "unit.shutdown" in data: # Eyes to soft gray on shutdown # self.bus.emit(Message("enclosure.eyes.color", # {'r': 70, 'g': 65, 'b': 69})) # self.bus.emit( # Message("enclosure.eyes.timedspin", # {'length': 12000})) # self.bus.emit(Message("enclosure.mouth.reset")) time.sleep(0.5) # give the system time to pass the message self.bus.emit(Message("system.shutdown")) if "unit.reboot" in data: # Eyes to soft gray on reboot # self.bus.emit(Message("enclosure.eyes.color", # {'r': 70, 'g': 65, 'b': 69})) # self.bus.emit(Message("enclosure.eyes.spin")) # self.bus.emit(Message("enclosure.mouth.reset")) time.sleep(0.5) # give the system time to pass the message self.bus.emit(Message("system.reboot")) if "unit.setwifi" in data: self.bus.emit(Message("system.wifi.setup", {'lang': self.lang})) if "unit.factory-reset" in data: self.bus.emit(Message("speak", { 'utterance': mycroft.dialog.get("reset to factory defaults")})) subprocess.call( 'rm ~/.mycroft/identity/identity2.json', shell=True) self.bus.emit(Message("system.wifi.reset")) self.bus.emit(Message("system.ssh.disable")) wait_while_speaking() # self.bus.emit(Message("enclosure.mouth.reset")) # self.bus.emit(Message("enclosure.eyes.spin")) # self.bus.emit(Message("enclosure.mouth.reset")) time.sleep(5) # give the system time to process all messages self.bus.emit(Message("system.reboot")) if "unit.enable-ssh" in data: # This is handled by the wifi client self.bus.emit(Message("system.ssh.enable")) self.bus.emit(Message("speak", { 'utterance': mycroft.dialog.get("ssh enabled")})) if "unit.disable-ssh" in data: # This is handled by the wifi client self.bus.emit(Message("system.ssh.disable")) self.bus.emit(Message("speak", { 'utterance': mycroft.dialog.get("ssh disabled")})) if "unit.enable-learning" in data or "unit.disable-learning" in data: enable = 'enable' in data word = 'enabled' if enable else 'disabled' LOG.info("Setting opt_in to: " + word) new_config = {'opt_in': enable} user_config = LocalConf(USER_CONFIG) user_config.merge(new_config) user_config.store() self.bus.emit(Message("speak", { 'utterance': mycroft.dialog.get("learning " + word)}))
def process(self, data): # TODO: Look into removing this emit altogether. # We need to check if any other serial bus messages # are handled by other parts of the code if "mycroft.stop" not in data: self.ws.emit(Message(data)) if "Command: system.version" in data: # This happens in response to the "system.version" message # sent during the construction of Enclosure() self.ws.emit(Message("enclosure.started")) if "mycroft.stop" in data: if has_been_paired(): create_signal('buttonPress') self.ws.emit(Message("mycroft.stop")) if "volume.up" in data: self.ws.emit(Message("mycroft.volume.increase", {'play_sound': True})) if "volume.down" in data: self.ws.emit(Message("mycroft.volume.decrease", {'play_sound': True})) if "system.test.begin" in data: self.ws.emit(Message('recognizer_loop:sleep')) if "system.test.end" in data: self.ws.emit(Message('recognizer_loop:wake_up')) if "mic.test" in data: mixer = Mixer() prev_vol = mixer.getvolume()[0] mixer.setvolume(35) self.ws.emit(Message("speak", { 'utterance': "I am testing one two three"})) time.sleep(0.5) # Prevents recording the loud button press record("/tmp/test.wav", 3.0) mixer.setvolume(prev_vol) play_wav("/tmp/test.wav").communicate() # Test audio muting on arduino subprocess.call('speaker-test -P 10 -l 0 -s 1', shell=True) if "unit.shutdown" in data: # Eyes to soft gray on shutdown self.ws.emit(Message("enclosure.eyes.color", {'r': 70, 'g': 65, 'b': 69})) self.ws.emit( Message("enclosure.eyes.timedspin", {'length': 12000})) self.ws.emit(Message("enclosure.mouth.reset")) time.sleep(0.5) # give the system time to pass the message self.ws.emit(Message("system.shutdown")) if "unit.reboot" in data: # Eyes to soft gray on reboot self.ws.emit(Message("enclosure.eyes.color", {'r': 70, 'g': 65, 'b': 69})) self.ws.emit(Message("enclosure.eyes.spin")) self.ws.emit(Message("enclosure.mouth.reset")) time.sleep(0.5) # give the system time to pass the message self.ws.emit(Message("system.reboot")) if "unit.setwifi" in data: self.ws.emit(Message("system.wifi.setup", {'lang': self.lang})) if "unit.factory-reset" in data: self.ws.emit(Message("speak", { 'utterance': mycroft.dialog.get("reset to factory defaults")})) subprocess.call( 'rm ~/.mycroft/identity/identity2.json', shell=True) self.ws.emit(Message("system.wifi.reset")) self.ws.emit(Message("system.ssh.disable")) wait_while_speaking() self.ws.emit(Message("enclosure.mouth.reset")) self.ws.emit(Message("enclosure.eyes.spin")) self.ws.emit(Message("enclosure.mouth.reset")) time.sleep(5) # give the system time to process all messages self.ws.emit(Message("system.reboot")) if "unit.enable-ssh" in data: # This is handled by the wifi client self.ws.emit(Message("system.ssh.enable")) self.ws.emit(Message("speak", { 'utterance': mycroft.dialog.get("ssh enabled")})) if "unit.disable-ssh" in data: # This is handled by the wifi client self.ws.emit(Message("system.ssh.disable")) self.ws.emit(Message("speak", { 'utterance': mycroft.dialog.get("ssh disabled")})) if "unit.enable-learning" in data or "unit.disable-learning" in data: enable = 'enable' in data word = 'enabled' if enable else 'disabled' LOG.info("Setting opt_in to: " + word) new_config = {'opt_in': enable} user_config = LocalConf(USER_CONFIG) user_config.merge(new_config) user_config.store() self.ws.emit(Message("speak", { 'utterance': mycroft.dialog.get("learning " + word)}))