API Path
/aipaas/voice/v1/tts/largeFileTrans
请求协议
HTTP
请求方法
POST
请求头部 :
| 头部标签 | 必填 | 说明 | 类型 | 数据字典 | 限制 | 头部内容 | 示例 |
|---|---|---|---|---|---|---|---|
| Content-Type | 是 | application/json | [string] | application/json | application/json | ||
| X-APP-ID | 是 | 控制台-应用管理-创建应用-AppID,公网鉴权,公网调用时必传 | [string] | ||||
| Authorization | 是 | 公网鉴权,公网调用时必传 | [string] | ||||
| Device-Uuid | 否 | 设备管理-设备uuid | [string] |
请求参数 Json:
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| timestamp | 当前时间的整形时间戳,精确到秒,10 分钟内有效 | 是 | [int] | |||
| file_link | 存放录音文件的地址链接,支持 HTTP | 是 | [string] | |||
| req_id | 请求全局唯一 ID,记录该值便于排查问题 | 是 | [string] | |||
| enable_callback | 是否启用回调功能,当前版本仅支持true | 是 | [boolean] | |||
| business_data | 客户端需要回传的业务数据 | 否 | [string] | |||
| callback_url | 接收回调结果的url地址,return_mode为0是必传 | 否 | [string] | |||
| return_mode | 结果返回模式,0:push,1:pull,默认为0。push模式即提供callback_url接收最终结果回调;pull模型即通过大模型异步调用结果回查接口查询最终调用结果,接口文档详见开发指南下的大模型异步调用结果回查。 | 否 | [int] |
响应内容 :
返回结果
> 成功 (200)
> Json
> Object
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| code | 状态响应码。参考错误编码规范 | 是 | [string] | |||
| msg | 调用结果描述。参考错误编码规范 | 是 | [string] | |||
| requestId | 请求ID,用于调用查询大模型生成结果信息接口 | 是 | [string] |
成功示例[Mock API] :
{
"code": "10000",
"msg": "调用成功",
"requestId": "test001"
}
失败示例[Mock API] :
{
"code": "10903",
"msg": "服务执行失败",
"requestId": "test001"
}
音频文件转写是一种将语音信号转换为文本的机器学习模型。这种模型在语音识别、自动字幕生成、语音助手等领域有广泛的应用,支持PCM、WAV、MP3格式多通道多采样率音频识别。
服务接口调用时需要严格遵循服务鉴权规则
公网服务调用鉴权规则请参见:开发指南 - 签名认证方式。
| 返回码 | 解释 | 说明 | 解决方法 |
|---|---|---|---|
| 10301 | Required parameter miss | 必填参数缺失 | 检查请求体是否符合接口协议 |
| 10302 | Too many requests | 并发请求过多 | 联系商务,增加并发 |
| 10304 | Parse request body fail | 请求格式错误 | 查看请求的 URL body 格式是否正确,参考接口文档 |
| 10503 | Server connection time out | 服务连接超时 | 联系技术人员 |
| 10903 | Recognize failed | 识别失败 | 联系技术人员 |
| 10000 | Success | 成功 | 执行下一步操作 |
通用状态码请参考【状态码】中的【网关认证】
{
"req_id": "test001",
"timestamp": 1673493479,
"file_link": "https://gw.alipayobjects.com/os/bmw-prod/0574ee2e-f494-45a5-820f-63aee583045a.wav",
"enable_callback": true,
"callback_url": "http://{ip}/{port}"
}
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import java.util.HashMap;
import java.util.Map;
/** 主类,用于发起HTTP请求并处理响应 */
public class Example {
public static void main(String[] args) {
example();
}
/**
* 方法中使用到的 JSONUtil、HttpRequest、HttpResponse均来自Hutool工具类。
* 具体maven依赖为:
*
* cn.hutool
* hutool-all
* 5.8.29
*
*/
public static void example() {
try {
String url = "算法调用地址";
// 设置请求头
Map headers = new HashMap();
//公网调用鉴权
headers.put("X-APP-ID", "yourAppId");
headers.put("Authorization", "yourAuthorization");
headers.put("Content-Type", "application/json");
// 创建请求对象
Map request = new HashMap();
request.put("req_id", "test001");
request.put("timestamp", System.currentTimeMillis());
request.put("file_link", "https://gw.alipayobjects.com/os/bmw-prod/0574ee2e-f494-45a5-820f-63aee583045a.wav");
request.put("enable_callback", true);
request.put("callback_url", "http://{ip}/{port}");
// 将请求对象转换为JsonNode
String requestString = JSONUtil.toJsonStr(request);
// 发起HTTP请求
HttpResponse response =
HttpRequest.post(url)
.headerMap(headers, true)
.body(requestString)
.execute();
// 输出响应结果
System.out.println(response.body());
} catch (Exception e) {
e.printStackTrace();
}
}
}
import json
import hashlib
import hmac
import time
import re
import urllib.parse
import requests
import warnings
from datetime import datetime
import logging
# 配置日志,设置日志级别为INFO,并指定日志格式
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# 配置环境变量
# 公网调用鉴权,与内网鉴权必传其一
X_APP_ID = "yourAppId"
AUTHORIZATION = "yourAuthorization"
# URL 和请求数据
url = "算法调用地址" # 请求的URL
request_data = {
"req_id": "test001",
"timestamp": int(time.time()),
"file_link": "https://gw.alipayobjects.com/os/bmw-prod/0574ee2e-f494-45a5-820f-63aee583045a.wav",
"enable_callback": True,
"callback_url": "http://{ip}/{port}"
}
# 构建请求头
headers = {
"Content-Type": "application/json",
# 公网调用鉴权
"X-APP-ID": X_APP_ID,
"Authorization": AUTHORIZATION
}
def timeSimple(timestamp):
# 将时间戳转换为HH:MM:SS格式的时间字符串
dt_object = datetime.fromtimestamp(timestamp)
formatted_time = dt_object.strftime("%H:%M:%S")
return formatted_time
def send_request(url):
try:
start_time = time.time()
logging.info(f"请求路径: {url}")
logging.info(f"开始发送: {timeSimple(start_time)}")
with requests.post(
url, json=request_data, headers=headers, stream=True, verify=False
) as response:
first_packet_time = None
if response.status_code == 200:
logging.info(f"接受到返回: {timeSimple(time.time())}")
for chunk in response.iter_content(chunk_size=1024):
if chunk:
if first_packet_time is None:
first_packet_time = time.time()
logging.info(
f"Received chunk: {timeSimple(time.time())} {chunk.decode('utf-8')}"
)
end_time = time.time()
logging.info(f"Time to first byte (TTFB): {first_packet_time - start_time:.3f} seconds")
logging.info(f"Request completed in {end_time - start_time:.3f} seconds")
else:
logging.error(f"Request failed with status code {response.status_code}")
except Exception as e:
logging.error(f"An error occurred: {e}")
# 发送请求
send_request(url)
logging.info(f"headers = {headers}")