def config(self, name, message): from mycroft.configuration.config import ( LocalConf, USER_CONFIG, Configuration ) module = "precise".replace(' ', '') module = module.replace('default', 'pocketsphinx') precise_file = self.select_precise_file(name, message) if precise_file == None: self.log.info("precise file "+name+" not found") return else: self.log.info("set precise file: "+precise_file) wake_word = name self.log.info("set precise WakeWord:"+name) new_config = {"listener": {"wake_word": name, "record_wake_words": "true"}, "hotwords": {wake_word: {"module": module, "threshold": "1e-90", "lang": self.lang,"local_model_file": precise_file}} } user_config = LocalConf(USER_CONFIG) user_config.merge(new_config) user_config.store() self.bus.emit(Message('configuration.updated')) if module == 'precise': engine_folder = expanduser('~/.mycroft/precise/precise-engine') if not os.path.isdir(engine_folder): self.speak_dialog('download.started') return self.speak_dialog('end.calculating', data={'name': name})
def handle_rate_speech(self, message): from mycroft.configuration.config import (LocalConf, Configuration, USER_CONFIG) user_config = LocalConf(USER_CONFIG) LOG.info(str(user_config)) user_level = message.data.get('ratelevel') LOG.info(user_level) rate_var = self.get_rate_var(user_level) if (rate_var == "error"): self.speak_dialog("invalidInput", {'userLevel': user_level}) else: new_config = { "tts": { "mimic": { "duration_stretch": str(rate_var) } } } user_config.merge(new_config) user_config.store() LOG.info(str(LocalConf(USER_CONFIG))) self.bus.emit(Message('configuration.updated')) self.speak_dialog("rate.speech", {'rateLevel': user_level})
def handle_change_lang_intent(self, message): lang = message.data.get("lang", self.lang) if self.validate_language(lang): if lang[:2] in self.lang_map and lang not in self.lang_map: lang = lang[:2] elif lang not in self.lang_map: for l in self.lang_map: if self.lang_map[l].lower() == lang.lower(): lang = l break lang_name = lang if lang_name in self.lang_map: lang_name = self.lang_map[lang_name] self.speak_dialog("new_lang", {"language": lang_name}) conf = LocalConf(USER_CONFIG) conf['lang'] = lang stt = self.config_core["stt"] stt["module"] = "google" if "google" not in stt: stt["google"] = {} if "credential" not in stt["google"]: stt["google"] = {"credential": {}} if "token" not in stt["google"]["credential"]: stt["google"][ "credential"] = "AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw" conf["stt"] = "google" tts = self.config_core["tts"] tts["module"] = "google" conf["tts"] = tts conf.store() self.emitter.emit(message.reply("mycroft.reboot", {})) else: self.speak_dialog("invalid_language", {"language": self.lang})
def from_ip_db(self, ip=None, update=True): self.log.info("Retrieving location data from ip database") ip = ip or self.get_ip() g = pygeoip.GeoIP(self.settings["geo_ip_db"]) data = g.record_by_addr(ip) or {} city = data.get("city", "") region_code = data.get("region_code", "") country_code = data.get("country_code", "") country_name = data.get("country_name", "") region = city longitude = data.get("longitude", "") latitude = data.get("latitude", "") timezone = data.get("time_zone", "") city_code = data.get("postal_code", "") data = self.build_location_dict(city, region_code, country_code, country_name, region, longitude, latitude, timezone, city_code) config = {"location": data, "address": city + ", " + country_name} if update: self.emitter.emit( Message("configuration.patch", {"config": config})) self.config_core["location"] = data conf = LocalConf(USER_CONFIG) conf['location'] = data conf.store() return config
def set_single_thread(self, update): new_config = {'padatious': {'single_thread': update}} user_config = LocalConf(USER_CONFIG) user_config.merge(new_config) user_config.store() self.log.info('Setting padatious single_thread = ' + str(update)) self.bus.emit(Message('configuration.updated'))
def reset_location(self, dummy=None): if not self.settings["tracking"]: self.emitter.emit( Message("configuration.patch", {"config": self.home_location})) conf = LocalConf(USER_CONFIG) conf['location'] = self.home_location conf.store()
def handle_set_listener(self, message): from mycroft.configuration.config import (LocalConf, USER_CONFIG, Configuration) module = message.data['ListenerType'].replace(' ', '') module = module.replace('default', 'pocketsphinx') name = module.replace('pocketsphinx', 'pocket sphinx') if self.get_listener() == module: self.speak_dialog('listener.same', data={'listener': name}) return wake_word = Configuration.get()['listener']['wake_word'] new_config = {'hotwords': {wake_word: {'module': module}}} user_config = LocalConf(USER_CONFIG) user_config.merge(new_config) user_config.store() self.bus.emit(Message('configuration.updated')) if module == 'precise': engine_folder = expanduser('~/.mycroft/precise/precise-engine') if not isdir(engine_folder): self.speak_dialog('download.started') return self.speak_dialog('set.listener', data={'listener': name})
def _sync_wake_beep_setting(self): """ Update "use beep" global config from skill settings. """ config = Configuration.get() use_beep = self.settings.get("use_listening_beep", False) if not config["confirm_listening"] == use_beep: # Update local (user) configuration setting new_config = {"confirm_listening": use_beep} user_config = LocalConf(USER_CONFIG) user_config.merge(new_config) user_config.store() self.bus.emit(Message("configuration.updated"))
def save_upgrade_permission(self, ver): # Build version as float, e.g. [18,8,999] as 18.8 float_ver = ver[0] + ver[1] / 10 # assumes minor is <= 9 new_conf_values = {"max_allowed_core_version": float_ver} # Save under the user (e.g. ~/.mycroft/mycroft.conf) user_config = LocalConf(USER_CONFIG) user_config.merge(new_conf_values) user_config.store() # Notify all processes to update their loaded configs self.bus.emit(Message('configuration.updated'))
def _sync_wake_beep_setting(self): from mycroft.configuration.config import (LocalConf, USER_CONFIG, Configuration) config = Configuration.get() use_beep = self.settings.get("use_listening_beep") == "true" if not config['confirm_listening'] == use_beep: # Update local (user) configuration setting new_config = {'confirm_listening': use_beep} user_config = LocalConf(USER_CONFIG) user_config.merge(new_config) user_config.store() self.emitter.emit(Message('configuration.updated'))
def _sync_wake_beep_setting(self): """ Update "use beep" global config from skill settings. """ from mycroft.configuration.config import (LocalConf, USER_CONFIG, Configuration) config = Configuration.get() use_beep = self.settings.get('use_listening_beep') is True if not config['confirm_listening'] == use_beep: # Update local (user) configuration setting new_config = {'confirm_listening': use_beep} user_config = LocalConf(USER_CONFIG) user_config.merge(new_config) user_config.store() self.bus.emit(Message('configuration.updated'))
def _disable_listen_beep(self): user_config = LocalConf(USER_CONFIG) if 'user_beep_setting' not in self.settings: # Save any current local config setting self.settings['user_beep_setting'] = ( user_config.get("confirm_listening", None)) # Disable in local config user_config.merge({"confirm_listening": False}) user_config.store() # Notify all processes to update their loaded configs self.bus.emit(Message('configuration.updated'))
def bind_engine(self, engine, priority=4): conf = LocalConf(USER_CONFIG) priority_skills = Configuration.get().get("skills", {}).get( "priority_skills", []) priority_skills.append(self._dir.split("/")[-1]) conf.store() self.priority = priority self.engine = engine self.config = engine.config self.register_messages(engine.name) self.register_fallback(self.handle_fallback, self.priority) self.finished_training_event = Event() self.finished_initial_train = False self.train_delay = self.config.get('train_delay', 4) self.train_time = get_time() + self.train_delay
def _restore_listen_beep(self): if 'user_beep_setting' in self.settings: # Wipe from local config new_conf_values = {"confirm_listening": False} user_config = LocalConf(USER_CONFIG) if (self.settings["user_beep_setting"] is None and "confirm_listening" in user_config): del user_config["confirm_listening"] else: user_config.merge({"confirm_listening": self.settings["user_beep_setting"]}) user_config.store() # Notify all processes to update their loaded configs self.bus.emit(Message('configuration.updated')) del self.settings["user_beep_setting"]
def handle_set_listener(self, message): try: from mycroft.configuration.config import (LocalConf, USER_CONFIG, Configuration) module = message.data['ListenerType'].replace(' ', '') module = module.replace('default', 'pocketsphinx') name = module.replace('pocketsphinx', 'pocket sphinx') config = Configuration.get() if config['hotwords']['hey mycroft']['module'] == module: self.speak_dialog('listener.same', data={'listener': name}) return new_config = { 'precise': { 'dist_url': 'http://bootstrap.mycroft.ai/' 'artifacts/static/daily/' }, 'hotwords': { 'hey mycroft': { 'module': module } } } user_config = LocalConf(USER_CONFIG) user_config.merge(new_config) user_config.store() self.emitter.emit(Message('configuration.updated')) if module == 'precise': exe_path = expanduser('~/.mycroft/precise/precise-stream') if isfile(exe_path): self.enclosure.mouth_text('Checking version...') version = check_output([exe_path, '-v'], stderr=STDOUT) if version.strip() == '0.1.0': os.remove(exe_path) self.enclosure.mouth_reset() else: self.speak_dialog('download.started') return self.speak_dialog('set.listener', data={'listener': name}) except (NameError, SyntaxError, ImportError): self.speak_dialog('must.update')
def from_wifi(self, update=True): if not self.settings["google_geolocate_key"]: self.speak("you need a google geolocation services api key " "in order to use wifi geolocation") self.log.error("you need a google geolocation services api key " "in order to use wifi geolocation") return {} lat, lon, accuracy = wifi_geolocate( api=self.settings["google_geolocate_key"], sudo=self.settings["wifi_sudo"]) LOG.info("\nlatitude: " + str(lat) + "\nlongitude: " + str(lon) + "\naccuracy (meters) : " + str(accuracy)) data = reverse_geolocate(lat, lon) data["accuracy"] = accuracy LOG.info("reverse geocoding data: " + str(data)) location = self.location.copy() location["address"] = data["address"] if data.get("zip"): location["city"]["code"] = data["zip"] else: location["city"]["code"] = data["city"] location["city"]["name"] = data["city"] location["city"]["state"]["name"] = data["state"] # TODO state code location["city"]["state"]["code"] = data["state"] location["city"]["state"]["country"]["name"] = data["country"] # TODO country code location["city"]["state"]["country"]["code"] = data["country"] location["coordinate"]["latitude"] = data["latitude"] location["coordinate"]["longitude"] = data["longitude"] timezone = get_timezone(data["latitude"], data["longitude"]) # TODO timezone name location["timezone"]["name"] = timezone location["timezone"]["code"] = timezone config = {"location": location} if update: self.emitter.emit( Message("configuration.patch", {"config": config})) self.config_core["location"] = location conf = LocalConf(USER_CONFIG) conf['location'] = location conf.store() return config
def handle_disable_precise_dev(self, message): from mycroft.configuration.config import (LocalConf, USER_CONFIG) for item in glob(expanduser('~/.mycroft/precise/precise-engine*')): self.log.info('Removing: {}...'.format(item)) if isdir(item): rmtree(item) else: os.remove(item) local_conf = LocalConf(USER_CONFIG) pconfig = local_conf.get('precise', {}) if pconfig.get('dist_url') == self.PRECISE_DEV_DIST_URL: del pconfig['dist_url'] if pconfig.get('model_url') == self.PRECISE_DEV_MODEL_URL: del pconfig['model_url'] local_conf.store() self.bus.emit(Message('configuration.updated')) self.speak_dialog('precise.devmode.disabled')
def handle_level_decrease(self, message): from mycroft.configuration.config import (LocalConf, USER_CONFIG) new_rate = self.curr_level + 0.10 if new_rate <= 2.0 and new_rate > 0.1: new_config = { "tts": { "mimic": { "duration_stretch": str(new_rate) } } } user_config = LocalConf(USER_CONFIG) user_config.merge(new_config) user_config.store() self.curr_level = new_rate self.bus.emit(Message('configuration.updated')) self.speak_dialog('updatedLevel', {'directionChange': 'decreased'}) else: self.speak_dialog("invalidLevel")
def save_wakewords(self): from mycroft.configuration.config import (LocalConf, USER_CONFIG, Configuration) record = Configuration.get()['listener']['record_wake_words'] if self.settings["savewakewords"] is True: free_mb = psutil.disk_usage('/')[2] / 1024 / 1024 if free_mb <= self.settings["min_free_disk"]: self.log.info("no space: deactivate recording") new_config = {"listener": {"record_wake_words": "true"}} user_config = LocalConf(USER_CONFIG) user_config.merge(new_config) user_config.store() if record == "false": new_config = {"listener": {"record_wake_words": "true"}} self.log.info("set wake word recording") user_config = LocalConf(USER_CONFIG) user_config.merge(new_config) user_config.store() self.settings.update else: if record == "true": new_config = {"listener": {"record_wake_words": "false"}} self.log.info("unset wake word recording") user_config = LocalConf(USER_CONFIG) user_config.merge(new_config) user_config.store() self.settings.update
def handle_use_precise_dev(self, message): from mycroft.configuration.config import (LocalConf, USER_CONFIG, Configuration) wake_word = Configuration.get()['listener']['wake_word'] new_config = { 'precise': { "dist_url": self.PRECISE_DEV_DIST_URL, "model_url": self.PRECISE_DEV_MODEL_URL }, 'hotwords': { wake_word: { 'module': 'precise', 'sensitivity': 0.5 } } } user_config = LocalConf(USER_CONFIG) user_config.merge(new_config) user_config.store() self.bus.emit(Message('configuration.updated')) self.speak_dialog('precise.devmode.enabled')
def update_skills_config(self, config=None): conf = LocalConf(USER_CONFIG) conf['skills'] = config or self.skills_config conf.store() self.send_message("skills.config.updated")
def from_remote_ip(self, update=True): self.log.info("Retrieving location data from ip address api") if connected(): response = requests.get("https://ipapi.co/json/").json() response = json.loads(response) city = response.body.get("city") region_code = response.body.get("region_code") country = response.body.get("country") country_name = response.body.get("country_name") region = response.body.get("region") lon = response.body.get("longitude") lat = response.body.get("latitude") timezone = response.body.get("timezone") if timezone is None: timezone_data = self.location.get( "timezone", self.home_location.get("timezone", {})) else: timezone_data = { "code": timezone, "name": timezone, "dstOffset": 3600000, "offset": -21600000 } region_data = { "code": region_code, "name": region, "country": { "code": country, "name": country_name } } city_data = { "code": city, "name": city, "state": region_data, "region": region_data } coordinate_data = {"latitude": float(lat), "longitude": float(lon)} location_data = { "city": city_data, "coordinate": coordinate_data, "timezone": timezone_data } config = { "location": location_data, "address": city + ", " + country_name } if update: self.emitter.emit( Message("configuration.patch", {"config": config})) self.config_core["location"] = location_data conf = LocalConf(USER_CONFIG) conf['location'] = location_data conf.store() return config else: self.log.warning("No internet connection, could not update " "location from ip address") return {}
def _update_config(self, config): from mycroft.configuration.config import (LocalConf, USER_CONFIG) user_config = LocalConf(USER_CONFIG) user_config.merge(config) user_config.store() self.bus.emit(Message('configuration.updated'))