import time
import json


async def stt(ws, upload_id):
    """Send a speech-to-text request on an established websocket connection.

    :param ws: an established websocket connection
    :param upload_id: the upload identifier returned by upload().
    :return: the STT response.
       >>> if resp['payload']['success'] is True then resp['payload']['text']  # contains the transcribed audio.
       >>> if resp['payload']['success'] is False then resp['payload']['reason']  # contains the failure reason.
    """
    stt_request = {
        'emit':    "stt",
        'payload': {
            'upload_id': upload_id,
            'timestamp': int(time.time())
        }
    }
    await ws.send(json.dumps(stt_request))
    return json.loads(await ws.recv())