from tencentcloud.common import credential
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
# 导入对应产品模块的client models。
# from tencentcloud.cvm.v20170312 import cvm_client, models
from tencentcloud.tts.v20190823 import tts_client, models
import json
def speak(text):
    try:
        # 实例化一个认证对象，入参需要传入腾讯云账户secretId，secretKey
        cred = credential.Credential("AKIDXtztXtxHbfSfWBfmkTw71mJZfV4M9Bow", "NTUfhMs04MVWgh7PVXQ8jAc4aKxSo28E")

        # 实例化要请求产品(以cvm为例)的client对象
        # client = cvm_client.CvmClient(cred, "ap-beijing")
        client1 = tts_client.TtsClient(cred, "ap-beijing")
        # 实例化一个请求对象
        # req = models.DescribeZonesRequest()
        req = models.TextToVoiceRequest()
        req.Text = text
        req.ModelType = 2
        req.Speed = 0
        req.SessionId = "123"
        # 通过client对象调用想要访问的接口，需要传入请求对象

        resp = client1.TextToVoice(req)
        # 输出json格式的字符串回包
        # print(json.loads(resp.to_json_string())['Audio'] )
        # print(type(resp.to_json_string()))
        return json.loads(resp.to_json_string())['Audio']


    except TencentCloudSDKException as err:
        print(err)

speak('我是')