def recognize_api(self, audio_data, client_access_token, language = "en", show_all = False):
        """
        Perform speech recognition on ``audio_data`` (an ``AudioData`` instance), using the api.ai Speech to Text API.

        The api.ai API client access token is specified by ``client_access_token``. Unfortunately, this is not available without `signing up for an account <https://console.api.ai/api-client/#/signup>`__ and creating an api.ai agent. To get the API client access token, go to the agent settings, go to the section titled "API keys", and look for "Client access token". API client access tokens are 32-character lowercase hexadecimal strings.

        Although the recognition language is specified when creating the api.ai agent in the web console, it must also be provided in the ``language`` parameter as an RFC5646 language tag like ``"en"`` (US English) or ``"fr"`` (International French), defaulting to US English. A list of supported language values can be found in the `API documentation <https://api.ai/docs/reference/#languages>`__.

        Returns the most likely transcription if ``show_all`` is false (the default). Otherwise, returns the `raw API response <https://api.ai/docs/reference/#a-namepost-multipost-query-multipart>`__ as a JSON dictionary.

        Raises a ``speech_recognition.UnknownValueError`` exception if the speech is unintelligible. Raises a ``speech_recognition.RequestError`` exception if the speech recognition operation failed, if the key isn't valid, or if there is no internet connection.
        """
        assert isinstance(audio_data, AudioData), "Data must be audio data"
        assert isinstance(client_access_token, str), "`username` must be a string"
        assert isinstance(language, str), "`language` must be a string"

        wav_data = audio_data.get_wav_data(convert_rate = 16000, convert_width = 2) # audio must be 16-bit mono 16 kHz
        url = "https://api.api.ai/v1/query"

        # pick a good multipart boundary; one that is guaranteed not to be in the text
        while True:
            boundary = "{0:>016x}".format(random.randrange(0x10000000000000000)) # generate a random boundary
            if boundary.encode("utf-8") not in wav_data:
                break

        data = (
            b"--" + boundary.encode("utf-8") + b"\r\n" +
            b"Content-Disposition: form-data; name=\"request\"\r\n" +
            b"Content-Type: application/json\r\n" +
            b"\r\n" +
            b"{\"v\": \"20150910\", \"lang\": \"" + language.encode("utf-8") + b"\"}\r\n" +
            b"--" + boundary.encode("utf-8") + b"\r\n" +
            b"Content-Disposition: form-data; name=\"voiceData\"; filename=\"audio.wav\"\r\n" +
            b"Content-Type: audio/wav\r\n" +
            b"\r\n" +
            wav_data + b"\r\n" +
            b"--" + boundary.encode("utf-8") + b"--\r\n"
        )

        request = Request(url, data = data, headers = {
            "Authorization": "Bearer {0}".format(client_access_token),
            "Content-Length": str(len(data)),
            "Expect": "100-continue",
            "Content-Type": "multipart/form-data; boundary={0}".format(boundary)
        })
        try:
            response = urlopen(request)
        except __HOLE__ as e:
            raise RequestError("recognition request failed: {0}".format(getattr(e, "reason", "status {0}".format(e.code)))) # use getattr to be compatible with Python 2.6
        except URLError as e:
            raise RequestError("recognition connection failed: {0}".format(e.reason))
        response_text = response.read().decode("utf-8")
        result = json.loads(response_text)

        # return results
        if show_all: return result
        if "asr" not in result or result["asr"] is None:
            raise UnknownValueError()
        return result["result"]["resolvedQuery"]
dataset/ETHPy150Open Uberi/speech_recognition/speech_recognition/__init__.py/Recognizer.recognize_api