import json

from tencentcloud.asr.v20190614 import asr_client, models
from tencentcloud.common import credential
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile

cred = credential.Credential("AKIDqgNp2yqDbqwta1I7nIXXIn21lFTSxk15", "7yZxAE7l9IC7nDVIp52jDQL6csrZ7OQD")
httpProfile = HttpProfile()
httpProfile.endpoint = "asr.tencentcloudapi.com"

clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = asr_client.AsrClient(cred, "", clientProfile)


# {
#   "Response": {
#     "RequestId": "544b708b-27ad-473d-8c76-947625722772",
#     "Data": {
#       "TaskId": 1441277608
#     }
#   }
# }
def send_asr_request(url):
    try:
        req = models.CreateRecTaskRequest()
        params = {
            "EngineModelType": "16k_zh",
            "ChannelNum": 1,
            "ResTextFormat": 1,
            "SourceType": 0,
            "Url": url,
            "ConvertNumMode": 0
        }
        req.from_json_string(json.dumps(params))

        resp = client.CreateRecTask(req)
        return resp

    except TencentCloudSDKException as err:
        print(err)


# {"Data": {"TaskId": 1441277608, "Status": 2, "StatusStr": "success", "Result": "[0:0.000,0:21.248]  八零九零后的女人还在穿着独立赌气不怪老公，不怪闺蜜只怪你手机里没有淘汰APP，在淘汰大多都是源头工厂直销一套只要二三十每个月能省下几百上千一次买个十几套老公也不会说你乱花钱你还在等什么？赶紧点击视频下方
# 立即下载逃遁把漂亮衣服带回家。\n", "ErrorMsg": "", "ResultDetail": [{"FinalSentence": "八零九零后的女人还在穿着独立赌气不怪老公，不怪闺蜜只怪你手机里没有淘汰APP，在淘汰大多都是源头工厂直销一套只要二三十每个月能省下几百上千一次买个十几套老公也不会说你乱花钱你还在等什么？赶紧点击视频下方立即下载逃遁把
# 漂亮衣服带回家。", "SliceSentence": "八 零 九零 后 的 女人 还在 穿着 独立 赌气 不怪 老公 不怪 闺蜜 只 怪你 手机 里 没有 淘汰 APP 在 淘汰 大多 都是 源头 工厂 直销 一套 只要 二 三十 每个月 能 省下 几百 上千 一次 买个 十几 套 老公 也 不会 说 你 乱 花钱 你 还在 等 什么 赶紧 点击 视频 下方 立即 下载 逃遁
#  把 漂亮 衣服 带回 家", "StartMs": 0, "EndMs": 21248, "WordsNum": 64, "Words": [{"Word": "八", "OffsetStartMs": 0, "OffsetEndMs": 180}, {"Word": "零", "OffsetStartMs": 180, "OffsetEndMs": 360}, {"Word": "九零", "OffsetStartMs": 360, "OffsetEndMs": 720}, {"Word": "后", "OffsetStartMs": 720, "OffsetEndMs": 810}, {"Word": "的", "OffsetStartMs": 810, "OffsetEndMs": 900}, {"Word": "女人", "OffsetStartMs": 900, "OffsetEndMs": 1200}, {"Word": "还在", "OffsetStartMs": 1200, "OffsetEndMs": 1620}, {"Word": "穿着", "OffsetStartMs": 1620, "OffsetEndMs": 1860}, {"Word": "独立", "OffsetStartMs": 1860, "OffsetEndMs": 2160}, {"Word": "赌气", "OffsetStartMs": 2160, "OffsetEndMs": 2580}, {"Word": "不怪", "OffsetStartMs": 2580, "OffsetEndMs": 2850}, {"Word": "老公", "OffsetStartMs": 2850, "OffsetEndMs": 3330}, {"Word": "不怪", "OffsetStartMs": 3330, "OffsetEndMs": 3600}, {"Word": "闺蜜", "OffsetStartMs": 30, "OffsetEndMs": 13110}, {"Word": "也", "OffsetStartMs": 13110, "OffsetEndMs": 13230}, {"Word": "不会", "OffsetStartMs": 13230, "OffsetEndMs": 13440}, {"Word": "说", "OffsetStartMs": 13440, "OffsetEndMs": 13560}, {"Word": "你", "OffsetStartMs": 13560, "OffsetEndMs": 13650}, {"Word": "乱", "OffsetStartMs": 13650, "OffsetEndMs": 13860}, {"Word": "花钱", "OffsetStartMs": 13860, "OffsetEndMs": 14250}, {"Word": "你", "OffsetStartMs": 14310, "OffsetEndMs": 14430}, {"Word": "还在", "OffsetStartMs": 14430, "OffsetEndMs": 14640}, {"Word": "等", "OffsetStartMs": 14640, "OffsetEndMs": 14820}, {"Word": "什么", "OffsetStartMs": 14820, "OffsetEndMs": 15090}, {"Word": "赶紧", "OffsetStartMs": 15120, "OffsetEndMs": 15510}, {"Word": "点击", "OffsetStartMs": 15510, "OffsetEndMs": 15870}, {"Word": "视频", "OffsetStartMs": 15870, "OffsetEndMs": 16140}, {"Word": "下方", "OffsetStartMs": 16140, "OffsetEndMs": 16410}, {"Word": "立即", "OffsetStartMs": 16410, "OffsetEndMs": 16650}, {"Word": "下载", "OffsetStartMs": 16650, "OffsetEndMs": 16980}, {"Word": "逃遁", "OffsetStartMs": 16980, "OffsetEndMs": 17310}, {"Word": "把", "OffsetStartMs": 17370, "OffsetEndMs": 17460}, {"Word": "漂亮", "OffsetStartMs": 17460, "OffsetEndMs": 17940}, {"Word": "衣服", "OffsetStartMs": 17940, "OffsetEndMs": 18270}, {"Word": "带回", "OffsetStartMs": 18270, "OffsetEndMs": 18780}, {"Word": "家", "OffsetStartMs": 18780, "OffsetEndMs": 19050}], "SpeechSpeed": 8.3}]}, "RequestId": "d0cb759b-b2a5-4c4b-9ad7-c5da7a485121"}   

def send_task_request(taskId):
    try:
        req = models.DescribeTaskStatusRequest()
        params = {
            "TaskId": taskId
        }
        req.from_json_string(json.dumps(params))

        resp = client.DescribeTaskStatus(req)
        return resp

    except TencentCloudSDKException as err:
        print(err)


if __name__ == '__main__':
    send_task_request(1441277608)
