def recognize_att(self, audio_data, app_key, app_secret, language = "en-US", show_all = False):
    authorization_url = "https://api.att.com/oauth/v4/token"
    authorization_body = "client_id={0}&client_secret={1}&grant_type=client_credentials&scope=SPEECH".format(app_key, app_secret)
    try: authorization_response = urlopen(authorization_url, data = authorization_body.encode("utf-8"))
    except __HOLE__ as e: raise RequestError("credential request failed: {0}".format(getattr(e, "reason", "status {0}".format(e.code))))
    except URLError as e: raise RequestError("credential connection failed: {0}".format(e.reason))
    authorization_text = authorization_response.read().decode("utf-8")
    authorization_bearer = json.loads(authorization_text).get("access_token")
    if authorization_bearer is None: raise RequestError("missing OAuth access token in requested credentials")
    wav_data = audio_data.get_wav_data(convert_rate = 8000 if audio_data.sample_rate < 16000 else 16000, convert_width = 2)
    request = Request("https://api.att.com/speech/v3/speechToText", data = wav_data, headers = {"Authorization": "Bearer {0}".format(authorization_bearer), "Content-Language": language, "Content-Type": "audio/wav"})
    try: response = urlopen(request)
    except HTTPError as e: raise RequestError("recognition request failed: {0}".format(getattr(e, "reason", "status {0}".format(e.code))))
    except URLError as e: raise RequestError("recognition connection failed: {0}".format(e.reason))
    result = json.loads(response.read().decode("utf-8"))
    if show_all: return result
    if "Recognition" not in result or "NBest" not in result["Recognition"]: raise UnknownValueError()
    for entry in result["Recognition"]["NBest"]:
        if entry.get("Grade") == "accept" and "ResultText" in entry: return entry["ResultText"]
        raise UnknownValueError() # no transcriptions available
dataset/ETHPy150Open Uberi/speech_recognition/speech_recognition/__init__.py/recognize_att