Beispiel #1
0
 def initialize(self):
     self.engine = IntentDeterminationEngine()
     self.enable_fallback = self.settings.get('enable_fallback_ex') \
         if self.settings.get('enable_fallback_ex') is not None else True
     self.public_path = self.settings.get('public_path_ex') \
         if self.settings.get('public_path_ex') else self.file_system.path+"/public"
     self.local_path = self.settings.get('local_path_ex') \
         if self.settings.get('local_path_ex') else self.file_system.path+"/private"
     self.allow_category = self.settings.get('allow_category_ex') \
         if self.settings.get('allow_category_ex') else "humor,love,science"
     LOG.debug('local path enabled: %s' % self.local_path)
     self.save_path = self.file_system.path+"/mycroft-skills"
     self.saved_utt = ""
     self.save_answer = ""
     if self.enable_fallback is True:
         self.register_fallback(self.handle_fallback, 6)
         self.register_fallback(self.handle_save_fallback, 99)
     ############## todo: fallback load skill intents
         self.add_event('speak',
                         self.save_action)
     LOG.debug('Learning-skil-fallback enabled: %s' % self.enable_fallback)
     skillfolder = Configuration.get()['skills']['directory']
     self.lang_paths = []
     if 'translations_dir' in Configuration.get(): ##path of second language files
         self.lang_paths.append(Configuration.get()['translations_dir'])
         self.log.info("set lang path to translation_dir")
     if os.path.isdir(os.path.expanduser(skillfolder+"/PootleSync/mycroft-skills")):
         self.lang_paths.append(os.path.expanduser(skillfolder+"/PootleSync/mycroft-skills"))
         self.log.info("set lang path to PootleSync")
     ##intents
     self.register_intent_file('will_let_you_know.intent', self.will_let_you_know_intent)
     self.register_intent_file('say.differently.intent', self.say_differently_intent)
     self.register_intent_file('work.on.dialog.intent', self.work_on_dialog)
     self.register_intent_file('something_for_my_skill.intent', self.something_for_my_skill_intent)
    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})
Beispiel #3
0
 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_how_polluted(self, message):
     if message.data.get('place') is not None:
         city = message.data.get('place')
     else:
         config = Configuration.get()
         city = config['location']['city']['name']
     pollutant = 'pm 2.5'
     self.waqi_query_and_report(city, pollutant)
Beispiel #5
0
 def handle_get_listener(self, message):
     try:
         from mycroft.configuration.config import Configuration
         module = Configuration.get()['hotwords']['hey mycroft']['module']
         name = module.replace('pocketsphinx', 'pocket sphinx')
         self.speak_dialog('get.listener', data={'listener': name})
     except (NameError, SyntaxError, ImportError):
         self.speak_dialog('must.update')
    def handle_where_are_you(self, message):
        from mycroft.configuration.config import Configuration
        config = Configuration.get()
        data = {
            "city": config["location"]["city"]["name"],
            "state": config["location"]["city"]["state"]["name"],
            "country": config["location"]["city"]["state"]["country"]["name"]
        }

        self.speak_dialog("i.am.at", data)
Beispiel #7
0
 def __init__(self,
              emitter=None,
              skills_config=None,
              defaults_url=None,
              modules_url=None):
     self.skills_config = skills_config or Configuration.get().get(
         "skills", {})
     self.skills_dir = self.skills_config.get(
         "directory") or '/opt/mycroft/skills'
     self.modules_url = modules_url or self.SKILLS_MODULES
     self.defaults_url = defaults_url or self.SKILLS_DEFAULTS_URL
     self.emitter = emitter
     self.skills = {}
     self.default_skills = {}
     self.installed_skills = []
     self.platform = Configuration.get().get("enclosure",
                                             {}).get("platform", "desktop")
     LOG.info("platform: " + self.platform)
     self.prepare_msm()
Beispiel #8
0
 def initialize(self):
     if self.settings.get('lang_path') is not "":
         self.lang_path = self.settings.get('lang_path')
         self.log.info("found user folder")
     elif 'translations_dir' in Configuration.get():
         self.lang_path = Configuration.get()['translations_dir']
         self.log.info("found transaltion folder")
     else:
         self.lang_path = self.file_system.path + "/mycroft-skills/"
         self.log.info("set default language path")
     synctimer = self.settings.get('synctimer') \
         if self.settings.get('synctimer') else 0
     if synctimer >= 1:
         sync = synctimer * 3600
         self.schedule_repeating_event(self.sync_pootle,
                                       None,
                                       sync,
                                       name='sync_pootle')
         self.log.info("start pootdle event every " +
                       str(self.settings.get('synctimer')) + " h")
    def __init__(self, path=None, debug=False):
        if path is None:
            path = Configuration.get().get("hivemind", {}).get(
                "sql_user_db",
                "sqlite:///" + join(dirname(__file__), "users.db"))
        self.db = create_engine(path)
        self.db.echo = debug

        Session = sessionmaker(bind=self.db)
        self.session = Session()
        Base.metadata.create_all(self.db)
Beispiel #10
0
 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 handle_what_is_pollutant_level(self, message):
     if message.data.get('pollutant') is not None:
         pollutant = message.data.get('pollutant')
     else:
         pollutant = 'pm 2.5'
     if message.data.get('place') is not None:
         city = message.data.get('place')
     else:
         config = Configuration.get()
         city = config['location']['city']['name']
     self.waqi_query_and_report(city, pollutant)
Beispiel #12
0
 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'))
Beispiel #13
0
 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 waqi_query_and_report(self, city, pollutant):
        if self.settings.get('APIKey') is not None:
            reqAQI = requests.get('https://api.waqi.info/feed/' + city +
                                  '/?token=' + self.settings.get('APIKey'))
            objAQI = json.loads(reqAQI.text)
            if objAQI['status'] == 'ok':
                try:
                    value = objAQI['data']['iaqi'][lookup[pollutant]]['v']
                except:
                    self.speak_dialog('pollutant.not.reported', {
                        'pollutant': nice_name[pollutant],
                        'city': city
                    })
                else:
                    config = Configuration.get()
                    station_string = objAQI["data"]["city"]["name"]
                    station = station_string.split(',')[0].split('(')[0]
                    utc_time = now_utc(
                    )  # alternatively, set utc_time to datetime.now(timezone.utc)
                    rec_time = datetime.strptime(
                        objAQI["data"]["time"]["s"] +
                        objAQI["data"]["time"]["tz"].split(':')[0] +
                        objAQI["data"]["time"]["tz"].split(':')[1],
                        "%Y-%m-%d %H:%M:%S%z")
                    rec_time = to_utc(rec_time)
                    timediff = (utc_time - rec_time).total_seconds()
                    if timediff // 3600 >= 3:  # reading is more than 3 hours old
                        self.dialog(
                            'Current readings for this location are not available. Please check back another time.'
                        )
                    else:
                        if city in station:
                            incity = ''
                        else:
                            incity = 'in ' + city
                        self.speak_dialog(
                            'pollutant.level.is', {
                                'pollutant': nice_name[pollutant],
                                'incity': incity,
                                'value': value,
                                'station': station
                            })
                    if nice_name[pollutant] == 'pm 2.5':
                        self.health_advisory(value)

            elif objAQI['data'] == 'Unknown station':
                self.speak_dialog('city.not.reported', {'city': city})
            elif objAQI['data'] == 'Invalid key':
                self.speak_dialog('invalid.key', {'city': city})
        else:
            self.speak_dialog('key.not.found')
Beispiel #15
0
def launch(config=None):
    global app, ws, intents, timeout
    config = config or Configuration.get().get("hivemind", {}).get("flask_node", {})
    # connect to internal mycroft
    ws = WebsocketClient()
    ws.on("mycroft.skill.handler.complete", end_wait)
    ws.on("complete_intent_failure", end_wait)
    ws.on("speak", listener)
    event_thread = Thread(target=connect)
    event_thread.setDaemon(True)
    event_thread.start()
    port = config.get("port", 6712)
    timeout = config.get("timeout", timeout)
    intents = MicroIntentService(ws)
    start(app, port)
Beispiel #16
0
 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
Beispiel #17
0
 def handle_update_precise(self, message):
     try:
         from mycroft.configuration.config import Configuration
         module = Configuration.get()['hotwords']['hey mycroft']['module']
         model_file = expanduser('~/.mycroft/precise/hey-mycroft.pb')
         if module != 'precise':
             self.speak_dialog('not.precise')
         if isfile(model_file):
             os.remove(model_file)
             new_conf = {'config': {'rand_val': random.random()}}
             self.emitter.emit(Message('configuration.patch', new_conf))
             self.emitter.emit(Message('configuration.updated'))
             self.speak_dialog('models.updated')
         else:
             self.speak_dialog('models.not.found')
     except (NameError, SyntaxError, ImportError):
         self.speak_dialog('must.update')
Beispiel #18
0
def main():
    config = Configuration.get().get("enclosure", {})
    platform = config.get("platform", "linux").lower()
    if platform.lower().startswith("sense"):
        from sensehat_enclosure import SenseHatEnclosure
        enclosure = SenseHatEnclosure()

        try:
            enclosure.run()
        except Exception as e:
            LOG.error(e)
        finally:
            enclosure.shutdown()
            sys.exit()
    else:
        LOG.error("Config says im running in " + platform + ", sensehat "
                  "enclosure needed")
Beispiel #19
0
    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 __init__(self):
        self.name = "rasa"
        IntentEngine.__init__(self, self.name)
        self.config = Configuration.get().get(self.name, {})
        self.training_data_path = self.config.get(
            "training_data_path", join(dirname(__file__), 'demo-rasa.json'))
        self.rasa_config = self.config.get(
            "config", join(dirname(__file__), 'rasa_config.yml'))
        self.model_path = self.config.get("model_path", expanduser("~/.rasa"))
        if not exists(self.model_path):
            makedirs(self.model_path)

        self.interpreter = None
        self.training_data = {
            "rasa_nlu_data": {
                "regex_features": [],
                "entity_synonyms": [],
                "common_examples": []
            }
        }
Beispiel #21
0
    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')
Beispiel #22
0
 def __init__(self):
     self.name = "padaos"
     IntentEngine.__init__(self, self.name)
     self.config = Configuration.get().get(self.name, {})
     self.container = IntentContainer()
Beispiel #23
0
 def __init__(self):
     self.name = "fuzzy"
     BaseIntentEngine.__init__(self, self.name)
     self.config = Configuration.get().get(self.name, {})
Beispiel #24
0
 def skills_config(self):
     return self._skills_config or Configuration.get().get(
         "skills", {"directory": '/opt/mycroft/skills'})
Beispiel #25
0
 def platform(self):
     return Configuration.get().get("enclosure",
                                    {}).get("platform", "desktop")
Beispiel #26
0
    def __init__(self):
        super(medicationSkill, self).__init__(name="medicationSkill")

        # Initialize working variables used within the skill.
        self.count = 0
        self.myTimeZone = (Configuration.get())["location"]["timezone"]["code"]
Beispiel #27
0
 def get_listener(self):
     """Raises ImportError or KeyError if not supported"""
     from mycroft.configuration.config import Configuration
     wake_word = Configuration.get()['listener']['wake_word']
     ww_config = Configuration.get()['hotwords'].get(wake_word, {})
     return ww_config.get('module', 'pocketsphinx')
Beispiel #28
0
 def initialize(self):
     self.started_by_skill = False
     self.sleeping = False
     self.old_brightness = 30
     self.add_event('mycroft.awoken', self.handle_awoken)
     self.wake_word = Configuration.get()['listener']['wake_word']