Ejemplo n.º 1
0
 def handle_update_intent(self, message):
     identity = IdentityManager().get()
     if not identity.owner:
         self.speak_dialog("not.paired")
     else:
         ConfigurationManager.load_remote()
         self.speak_dialog("config.updated")
Ejemplo n.º 2
0
 def handle_update_request(self, message):
     identity = IdentityManager().get()
     if not identity.owner:
         self.speak_dialog("not.paired")
     else:
         rc = RemoteConfiguration()
         rc.update()
         self.speak_dialog("config.updated")
Ejemplo n.º 3
0
 def __init__(self, config=_config, pairing_code=None):
     self.config = config
     self.ws_client = WebsocketClient(host=config.get("host"),
                                      port=config.get("port"),
                                      path=config.get("route"),
                                      ssl=str2bool(config.get("ssl")))
     self.identity_manager = IdentityManager()
     self.identity = self.identity_manager.identity
     self.pairing_code = pairing_code if pairing_code else generate_pairing_code()
Ejemplo n.º 4
0
    def transcribe(self,
                   audio,
                   language="en-US",
                   show_all=False,
                   metrics=None):
        timer = Stopwatch()
        timer.start()
        identity = IdentityManager().get()
        headers = {}
        if identity.token:
            headers['Authorization'] = 'Bearer %s:%s' % (identity.device_id,
                                                         identity.token)

        response = requests.post(config.get("proxy_host") +
                                 "/stt/google_v2?language=%s&version=%s" %
                                 (language, self.version),
                                 audio.get_flac_data(),
                                 headers=headers)

        if metrics:
            t = timer.stop()
            metrics.timer("mycroft.cerberus.proxy.client.time_s", t)
            metrics.timer("mycroft.stt.remote.time_s", t)

        if response.status_code == 401:
            raise CerberusAccessDenied()

        try:
            actual_result = response.json()
        except:
            raise UnknownValueError()

        log.info("STT JSON: " + json.dumps(actual_result))
        if show_all:
            return actual_result

        # return the best guess
        if "alternative" not in actual_result:
            raise UnknownValueError()
        alternatives = actual_result["alternative"]
        if len([alt for alt in alternatives if alt.get('confidence')]) > 0:
            # if there is at least one element with confidence, force it to
            # the front
            alternatives.sort(key=lambda e: e.get('confidence', 0.0),
                              reverse=True)

        for entry in alternatives:
            if "transcript" in entry:
                return entry["transcript"]

        if len(alternatives) > 0:
            log.error("Found %d entries, but none with a transcript." %
                      len(alternatives))

        # no transcriptions available
        raise UnknownValueError()
Ejemplo n.º 5
0
 def query(self, query):
     """
     Query Wolfram|Alpha with query using the v2.0 API
     """
     identity = IdentityManager().get()
     bearer_token = 'Bearer %s:%s' % (identity.device_id, identity.token)
     query = urllib.parse.urlencode(dict(input=query))
     url = 'https://cerberus.mycroft.ai/wolframalpha/v2/query?' + query
     headers = {'Authorization': bearer_token}
     response = requests.get(url, headers=headers)
     if response.status_code == 401:
         raise CerberusAccessDenied()
     return wolframalpha.Result(StringIO(response.content))
Ejemplo n.º 6
0
    def load(config=None):
        RemoteConfiguration.validate_config(config)

        identity = IdentityManager().get()
        config_remote = config.get("remote_configuration", {})
        enabled = str2bool(config_remote.get("enabled", "False"))

        if enabled and identity.token:
            url = config_remote.get("url")
            auth_header = "Bearer %s:%s" % (identity.device_id, identity.token)
            try:
                response = requests.get(url,
                                        headers={"Authorization": auth_header})
                user = response.json()
                RemoteConfiguration.__load_attributes(config, user)
            except Exception as e:
                logger.error("Failed to fetch remote configuration: %s" %
                             repr(e))
        else:
            logger.debug(
                "Device not paired, cannot retrieve remote configuration.")
        return config
Ejemplo n.º 7
0
 def __init__(self, identity=None):
     self.identity = identity or IdentityManager().get()
     self.config_manager = ConfigurationManager()
Ejemplo n.º 8
0
 def owm(self):
     return OWM(API_key=self.config.get('api_key', ''), identity=IdentityManager().get())