def init_oral_process(SessionId,RefText,base64_data):
    # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
    cred = credential.Credential("AKIDxe5GDPX6aonW1G78hyzmLglpeFagr9Vc", "A9uRkpfFZpqb6MQEm48xVaTs0ub3GDtK")

    # 实例化一个http选项,可选的,没有特殊需求可以跳过。
    httpProfile = HttpProfile()
    httpProfile.reqMethod = "POST"  # post请求(默认为post请求)
    httpProfile.reqTimeout = 30  # 请求超时时间,单位为秒(默认60秒)
    httpProfile.endpoint = "soe.tencentcloudapi.com"  # 指定接入地域域名(默认就近接入)
    httpProfile.keepAlive = True

    # 实例化一个client选项,可选的,没有特殊需求可以跳过。
    clientProfile = ClientProfile()
    clientProfile.signMethod = "TC3-HMAC-SHA256"  # 指定签名算法(默认为HmacSHA256)
    clientProfile.unsignedPayload = True
    clientProfile.httpProfile = httpProfile

    client = soe_client.SoeClient(cred, "", clientProfile)
    req = models.InitOralProcessRequest()
    req.SessionId = SessionId
    req.RefText = RefText
    req.WorkMode = 1
    req.EvalMode = 0
    req.ScoreCoeff = 1.0

    resp = client.InitOralProcess(req)

    # 输出json格式的字符串回包
    print("初始化:%s" % resp.to_json_string())
    transmit(SessionId,base64_data)
def InitOral(text):

    try:
        # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
        cred = credential.Credential("AKIDb7SivKPjOsM9wYuYufbR6kCd8Yj1dA95",
                                     "yWmqsjR1qW0UmzARRfjcQ3byHEoDRZXl")

        # 实例化一个http选项,可选的,没有特殊需求可以跳过。
        httpProfile = HttpProfile()
        httpProfile.reqMethod = "POST"  # post请求(默认为post请求)
        httpProfile.reqTimeout = 30  # 请求超时时间,单位为秒(默认60秒)
        httpProfile.endpoint = "soe.tencentcloudapi.com"  # 指定接入地域域名(默认就近接入)

        # 实例化一个client选项,可选的,没有特殊需求可以跳过。
        clientProfile = ClientProfile()
        clientProfile.signMethod = "HmacSHA256"  # 指定签名算法(默认为HmacSHA256)
        clientProfile.httpProfile = httpProfile

        client = soe_client.SoeClient(cred, "", clientProfile)
        req = models.InitOralProcessRequest()
        req.SessionId = "stress_test_956938"
        req.RefText = "Actually, he has over a million subscribers."
        req.WorkMode = 0
        req.EvalMode = 1
        req.ScoreCoeff = 3.5

        headerDict = addPublicParameter("InitOralProcess")
        headerDict["SessionId"] = "zhm1213"
        headerDict["RefText"] = text
        headerDict["WorkMode"] = 0
        headerDict["EvalMode"] = 1
        headerDict["ScoreCoeff"] = 3.5
        strJson = json.dumps(headerDict)
        req.from_json_string(strJson)

        resp = client.InitOralProcess(req)

        # 输出json格式的字符串回包
        print("%s" % resp.to_json_string())

    except TencentCloudSDKException as err:
        print("%s" % err)
Пример #3
0
def transmit_oral_process(sessionId,
                          userVoiceData):  #  语音段唯一标识,一个完整语音一个SessionId。
    try:
        # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
        cred = credential.Credential(secretId, secretKey)

        # 实例化一个http选项,可选的,没有特殊需求可以跳过。
        httpProfile = HttpProfile()
        httpProfile.reqMethod = "POST"  # post请求(默认为post请求)
        httpProfile.reqTimeout = 30  # 请求超时时间,单位为秒(默认60秒)
        httpProfile.endpoint = "soe.tencentcloudapi.com"  # 指定接入地域域名(默认就近接入)

        clientProfile = ClientProfile()
        clientProfile.signMethod = "TC3-HMAC-SHA256"  # 指定签名算法(默认为HmacSHA256)
        clientProfile.unsignedPayload = True
        clientProfile.httpProfile = httpProfile

        client = soe_client.SoeClient(cred, "", clientProfile)
        req = models.TransmitOralProcessRequest()
        req.SessionId = sessionId
        req.VoiceFileType = 2  # 语音文件类型 1:raw, 2:wav, 3:mp3(三种格式目前仅支持16k采样率16bit编码单声道
        req.SeqId = 1  # 流式数据包的序号,从1开始,当IsEnd字段为1后后续序号无意义,当
        #IsLongLifeSession不为1且为非流式模式时无意义。
        req.VoiceEncodeType = 1  # 语音编码类型 1:pcm。
        req.IsEnd = 1  #  是否传输完毕标志,若为0表示未完毕,若为1则传输完毕开始评估,非流式模式下无意义

        req.UserVoiceData = userVoiceData  # 当前数据包数据, 流式模式下数据包大小可以按需设置,数据包大小必须 >= 4K,且必
        #须保证分片帧完整(16bit的数据必须保证音频长度为偶数),编码格式要求为BASE64。

        # process
        resp = client.TransmitOralProcess(req)

        # 输出json格式的字符串回包
        print("%s" % resp.to_json_string())

    except TencentCloudSDKException as err:
        print("%s" % err)
Пример #4
0
def init_oral_process(text, sessionId):  #  语音段唯一标识,一个完整语音一个SessionId。
    try:
        # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
        cred = credential.Credential(secretId, secretKey)

        # 实例化一个http选项,可选的,没有特殊需求可以跳过。
        httpProfile = HttpProfile()
        httpProfile.reqMethod = "POST"  # post请求(默认为post请求)
        httpProfile.reqTimeout = 30  # 请求超时时间,单位为秒(默认60秒)
        httpProfile.endpoint = "soe.tencentcloudapi.com"  # 指定接入地域域名(默认就近接入)

        # 实例化一个client选项,可选的,没有特殊需求可以跳过。
        clientProfile = ClientProfile()
        clientProfile.signMethod = "TC3-HMAC-SHA256"  # 指定签名算法(默认为HmacSHA256)
        clientProfile.unsignedPayload = True
        clientProfile.httpProfile = httpProfile

        client = soe_client.SoeClient(cred, "", clientProfile)
        req = models.InitOralProcessRequest()
        #req.SessionId = "stress_test_956938"
        req.SessionId = sessionId
        req.RefText = text  # refer 的文本
        req.WorkMode = 1  # workMode  语音输入模式,0:流式分片,1:非流式一次性评估
        req.EvalMode = 1  # EvalMode 评估模式,0:词模式,,1::句子模式,2:段落模式,3:自由说模式,当为词模式
        #评估时,能够提供每个音节的评估信息,当为句子模式时,能够提供完整度和流利度信息。
        req.ScoreCoeff = 3.5
        # ScoreCoeff 评价苛刻指数,取值为[1.0 - 4.0]范围内的浮点数,用于平滑不同年龄段的分数,1.0
        #为小年龄段,4.0为最高年龄段

        resp = client.InitOralProcess(req)

        # 输出json格式的字符串回包
        print("%s" % resp.to_json_string())

    except TencentCloudSDKException as err:
        print("%s" % err)
Пример #5
0
                                 os.environ.get("TENCENTCLOUD_SECRET_KEY"))

    # 实例化一个http选项,可选的,没有特殊需求可以跳过。
    httpProfile = HttpProfile()
    httpProfile.reqMethod = "POST"  # post请求(默认为post请求)
    httpProfile.reqTimeout = 30  # 请求超时时间,单位为秒(默认60秒)
    httpProfile.endpoint = "soe.tencentcloudapi.com"  # 指定接入地域域名(默认就近接入)
    httpProfile.keepAlive = True

    # 实例化一个client选项,可选的,没有特殊需求可以跳过。
    clientProfile = ClientProfile()
    clientProfile.signMethod = "TC3-HMAC-SHA256"  # 指定签名算法(默认为HmacSHA256)
    clientProfile.unsignedPayload = True
    clientProfile.httpProfile = httpProfile

    client = soe_client.SoeClient(cred, "", clientProfile)
    req = models.InitOralProcessRequest()
    req.SessionId = "stress_test_956938"
    req.RefText = "since"
    req.WorkMode = 0
    req.EvalMode = 1
    req.ScoreCoeff = 3.5

    resp = client.InitOralProcess(req)

    # 输出json格式的字符串回包
    print("%s" % resp.to_json_string())

except TencentCloudSDKException as err:
    print("%s" % err)
Пример #6
0
def client(key_id, secret):
    try:
        cred = credential.Credential(key_id, secret)

        httpProfile = HttpProfile()
        httpProfile.endpoint = "soe.tencentcloudapi.com"

        clientProfile = ClientProfile()
        clientProfile.httpProfile = httpProfile
        clientProfile.signMethod = "TC3-HMAC-SHA256"
        client = soe_client.SoeClient(cred, "na-ashburn", clientProfile)

        req = models.TransmitOralProcessWithInitRequest()

        speakers_score = {}
        speakers_score["total_word_count"] = 0
        total_count = 0
        for speaker in os.listdir(IN_DIR):
            # if speaker in ['THV','TLV','TNI','TXHC', 'YBAA', 'YDCK','YKWK','ZHAA']:
            speaker_score = defaultdict(lambda: defaultdict(int))
            speaker_score["speaker_word_count"] = 0
            speaker_path = IN_DIR + os.sep + speaker + os.sep + "wav"
            print(f"Start speaker {speaker}")
            count = 0
            for filename in os.listdir(speaker_path):
                file_path = speaker_path + os.sep + filename
                trans_path = IN_DIR + os.sep + speaker + os.sep + "transcript" + os.sep + "gold_transcript"
                transcripts = []
                with open(trans_path) as f:
                    for line in f.readlines():
                        if corpus == 'native':
                            line = line.split('\t')[1]
                        transcripts.append(line.strip())
                if filename.endswith(".wav"):
                    sessionid = f"{speaker}_{count}"
                    wav = wav2base64(file_path)
                    text = transcripts[count]
                    word_count = len(word_tokenize(text))
                    params = rf'{{"SeqId":1,"IsEnd":1,"VoiceFileType":2,"VoiceEncodeType":1,"UserVoiceData":"{wav}","SessionId":"{sessionid}","RefText":"{text}","WorkMode":1,"EvalMode":2,"ScoreCoeff":3.5}}'
                    req.from_json_string(params)

                    resp = client.TransmitOralProcessWithInit(req)
                    feedback = resp.to_json_string()
                    with open(IN_DIR + os.sep + speaker + os.sep + "asa_recent.log", "a") as f:
                        f.write(f"{feedback}\n")
                    feedback = json.loads(feedback)
                    #                         print(resp.to_json_string())
                    speaker_score[f"{speaker}_{count}"]["PronAccuracy"] = feedback["PronAccuracy"]

                    speaker_score[f"{speaker}_{count}"]["PronFluency"] = feedback["PronFluency"]
                    speaker_score[f"{speaker}_{count}"]["PronCompletion"] = feedback["PronCompletion"]
                    speaker_score[f"{speaker}_{count}"]["SuggestedScore"] = feedback["SuggestedScore"]
                    speaker_score[f"{speaker}_{count}"]["word_count"] = word_count
                    speaker_score["speaker_word_count"] += word_count
                    count += 1
                    total_count += 1
                    if count % 10 == 0:
                        print(f"speaker {speaker} {count} / 100")
                    if count == 100:
                        break

            print(f"Finished speaker {speaker}")
            speakers_score[speaker] = speaker_score
            speakers_score["total_word_count"] += speaker_score["speaker_word_count"]

    except TencentCloudSDKException as err:
        print(err)
try:
    # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
    cred = credential.Credential("secretId", "secretKey")

    # 实例化一个http选项,可选的,没有特殊需求可以跳过。
    httpProfile = HttpProfile()
    httpProfile.reqMethod = "GET"  # post请求(默认为post请求)
    httpProfile.reqTimeout = 30  # 请求超时时间,单位为秒(默认60秒)
    httpProfile.endpoint = "soe.ap-shanghai.tencentcloudapi.com"  # 指定接入地域域名(默认就近接入)

    # 实例化一个client选项,可选的,没有特殊需求可以跳过。
    clientProfile = ClientProfile()
    clientProfile.signMethod = "HmacSHA256"  # 指定签名算法(默认为HmacSHA256)
    clientProfile.httpProfile = httpProfile

    client = soe_client.SoeClient(cred, "ap-shanghai", clientProfile)
    req = models.TransmitOralProcessRequest()
    req.SessionId = "stress_test_956938"
    req.VoiceFileType = 1
    req.SeqId = 1
    req.VoiceEncodeType = 1
    req.IsEnd = 0
    req.UserVoiceData = "VWtsR1JxeUpBd0JYUVZaRlptMTBJQkFBQUFBQkFBRUFnRDRBQUFCOUFBQUNBQkFBVEVsVFZCb0FBQUJKVGtaUFNWTkdWQTRBQUFCTVlYWm1OVFl1TVRrdU1UQXdBR1JoZEdGbWlRTUF5"

    resp = client.TransmitOralProcess(req)

    # 输出json格式的字符串回包
    print("%s" % resp.to_json_string())

except TencentCloudSDKException as err:
    print("%s" % err)