腾讯云智聆口语评测TransInitUrl 接口说明-教育服务解决方案

接口描述

用于客户端SDK(Web SDK 和 微信 H5)在服务端调用评测服务。客户端 SDK 会获取评测参数调用该接口给服务端进行评测。

请求方式

POST

请求地址

https://127.0.0.1:8080/TransInitUrl (以实际提供接口地址为准)

请求头

属性名 类型 参数描述
Content-Type String application/json

请求参数

部分请求参数参考。具体可以参考 Web SDK 参数说明。

参数名称 类型 描述
RefText String 被评估文本。支持单词,组合词,缩写。
EvalMode Integer 评估模式。0:单词评测模式
ServerType Integer 评估语言。0:英文

请求示例

部分参数 SDK 内部处理。使用 Web SDK 填入对应参数,SDK 内部会自动获取参数,请求 TransInitUrl 接口。

{    "RefText": "Chinese",     "EvalMode": 0,     "ServerType":0,     "WorkMode":1,    "UserVoiceData":"UklGRka1CQBXQVZFZm10IBAAAA*********",    "SeqId":1,    "IsEnd":1,    "VoiceFileType":3,    "VoiceEncodeType":1,    "SessionId":"8fde-1668677271201-87656",    "ScoreCoeff":1.0}

响应参数

部分返回结果说明

参数名称 类型 描述
SuggestedScore Integer 建议评分
PronAccuracy Integer 整体精准度
PronFluency Integer 整体流利度
Words.PronAccuracy Integer 单词精准度
Words.PronFluency Integer 单词流利度
Words.PhoneInfos.PronAccuracy Integer 音素精准度
Words.PhoneInfos.Stress Boolean 当前评估文本对应音素是否为重音
Words.PhoneInfos.DetectedStress Boolean 当前音频数据对应音素是否为重音

返回示例

{    "Response":{        "SuggestedScore":96.90857,        "PronAccuracy":96.90857,        "PronFluency":0.8866854,        "PronCompletion":1,        "RequestId":"7f1b9ea1-afc2-43fe-8c8d-49******",        "Words":[            {                "MemBeginTime":880,                "MemEndTime":1660,                "PronAccuracy":96.90857,                "PronFluency":0.8866854,                "ReferenceWord":"chinese_0",                "Word":"chinese",                "MatchTag":0,                "KeywordTag":0,                "PhoneInfos":[                    {                        "MemBeginTime":880,                        "MemEndTime":1060,                        "PronAccuracy":97.13047,                        "DetectedStress":false,                        "Phone":"ch",                        "ReferencePhone":"",                        "ReferenceLetter":"",                        "Stress":false,                        "MatchTag":0                    },                    {                        "MemBeginTime":1060,                        "MemEndTime":1230,                        "PronAccuracy":97.7727,                        "DetectedStress":false,                        "Phone":"ay",                        "ReferencePhone":"",                        "ReferenceLetter":"",                        "Stress":false,                        "MatchTag":0                    },                    {                        "MemBeginTime":1230,                        "MemEndTime":1320,                        "PronAccuracy":98.01649,                        "DetectedStress":true,                        "Phone":"n",                        "ReferencePhone":"",                        "ReferenceLetter":"",                        "Stress":true,                        "MatchTag":0                    },                    {                        "MemBeginTime":1320,                        "MemEndTime":1460,                        "PronAccuracy":97.92693,                        "DetectedStress":false,                        "Phone":"iy",                        "ReferencePhone":"",                        "ReferenceLetter":"",                        "Stress":false,                        "MatchTag":0                    },                    {                        "MemBeginTime":1460,                        "MemEndTime":1660,                        "PronAccuracy":93.69628,                        "DetectedStress":false,                        "Phone":"z",                        "ReferencePhone":"",                        "ReferenceLetter":"",                        "Stress":false,                        "MatchTag":0                    }                ]            }        ],        "SessionId":"8fde-1668677*****",        "Status":"Finished"    }}

请求示例

请求流程

参考 SOE 控制台,提供 Web 服务,将项目部署上线即可。

Python 示例

使用 flask 框架,需要使用 pip 安装以下依赖:

tencentcloud-sdk-pythonflaskflask_corsgevent

示例代码:

import jsonfrom flask import Flask, request, render_templatefrom flask_cors import CORSfrom gevent import pywsgi
from tencentcloud.common import credentialfrom tencentcloud.common.profile.client_profile import ClientProfilefrom tencentcloud.common.profile.http_profile import HttpProfilefrom tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
app = Flask(__name__)
CORS(app) # 允许跨域
@app.route("/TransInitUrl", methods=["POST"]) #通过该地址请求接口,推荐使用post方法def TransInitUrl(): request_json = request.json #接收前端传出的json数据 try: # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey cred = credential.Credential("", "") # 实例化一个http选项,可选的,没有特殊需求可以跳过。 httpProfile = HttpProfile() httpProfile.reqMethod = "POST" # post请求(默认为post请求) httpProfile.reqTimeout = 30 # 请求超时时间,单位为秒(默认60秒) httpProfile.endpoint = "soe.tencentcloudapi.com" # 指定接入地域域名(默认就近接入) # 实例化一个client选项,可选的,没有特殊r需求可以跳过。 clientProfile = ClientProfile() clientProfile.signMethod = "TC3-HMAC-SHA256" # 指定签名算法(默认为HmacSHA256) clientProfile.unsignedPayload = True clientProfile.httpProfile = httpProfile
from tencentcloud.soe.v20180724 import soe_client, models client = soe_client.SoeClient(cred, "", clientProfile)
req = models.TransmitOralProcessWithInitRequest() # 从前端传入的json数据中获取请求参数 req.SeqId = request_json['SeqId'] req.IsEnd = request_json['IsEnd'] req.VoiceFileType = request_json['VoiceFileType'] req.VoiceEncodeType = request_json['VoiceEncodeType'] req.UserVoiceData = request_json['UserVoiceData'] req.RefText = request_json['RefText'] req.WorkMode = request_json['WorkMode'] req.EvalMode = request_json['EvalMode'] req.ScoreCoeff = request_json['ScoreCoeff'] req.SessionId = request_json['SessionId'] req.ServerType = request_json['ServerType'] req.TextMode = request_json['TextMode']
# 请求服务,获取结果 resp = client.TransmitOralProcessWithInit(req) json_resp = resp.to_json_string()
json_load = json.loads(json_resp) # SDK 封装了返回结果。此处需要加上Response new_dict = { "Response": json_load } json_dumps = json.dumps(new_dict) 
return json_dumps # 回调

except TencentCloudSDKException as err: return err
if __name__ == '__main__': server = pywsgi.WSGIServer(('0.0.0.0', 9000), app) server.serve_forever()



腾讯云官网1折活动,限时活动,即将结束,速速收藏
同尘科技为腾讯云授权服务中心。
购买腾讯云产品享受折上折,更有现金返利。同意关联立享优惠

发表评论