API Path
/aipaas/voice/v1/tts/voiceSeperate
请求协议
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] | |||
| sample_rate | 音频采样率,默认值 16000 Hz | 否 | [int] | |||
| num_channels | 输入音频数据的通道数,默认值是 1 | 否 | [int] | |||
| enable_punc | 是否开启加标点,默认值是 true | 否 | [boolean] | |||
| enable_itn | 是否开启 ITN,默认值是 true | 否 | [boolean] | |||
| business_data | 客户端需要回传的业务数据 | 否 | [string] | |||
| callback_url | 接收回调结果的url地址,return_mode为0是必传 | 否 | [string] | |||
| return_mode | 结果返回模式,0:push,1:pull,默认为0。push模式即提供callback_url接收最终结果回调;pull模型即通过大模型异步调用结果回查接口查询最终调用结果,接口文档详见开发指南下的大模型异步调用结果回查。 | 否 | [int] |
REST参数 :
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| code | 是 | [string] |
响应内容 :
返回结果
> 成功 (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 | 服务连接超时 | 联系技术人员 |
| 10603 | Fetch audio failed | 获取音频文件失败 | 检查文件 URL 是否正确 |
| 10604 | Decode audio failed | 解析音频文件失败 | 检查源音频文件格式是否正确 |
| 10605 | Resample audio failed | 重采样音频失败 | 联系技术人员 |
| 10607 | Audio too large | 音频文件过大 | 切分音频再进行识别 |
| 10608 | Audio too long | 音频过长 | 切分音频再进行识别 |
| 10801 | Task processing | 任务处理中 | 等待重新查询 |
| 10903 | Recognize failed | 识别失败 | 联系技术人员 |
| 10904 | Query failed | 查询失败 | 联系技术人员 |
| 10905 | Unexpected error | 未知错误 | 联系技术人员 |
| 10000 | Success | 成功 | 执行下一步操作 |
{
"timestamp": 1673493479,
"file_link": "https://gw.alipayobjects.com/os/bmw-prod/0574ee2e-f494-45a5-820f-63aee583045a.wav",
"req_id": "3a87fe9793c9-4ebd-95d4-4ce2-a80c054b",
"enable_callback": true,
"callback_url": "http://{ip}/{port}/{uri}"
}
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import java.util.HashMap;
import java.util.Map;
public class OfflineAsr {
public static void main(String[] args) {
offlineAsr();
}
/**
* 方法中使用到的 JSONObject、HttpRequest、HttpResponse均来自Hutool工具类。
* 具体maven依赖为:
*
* cn.hutool
* hutool-all
* 5.8.29
*
*/
public static void offlineAsr() {
String url = "服务调用地址";
// 设置请求头
Map headers = new HashMap();
//公网调用鉴权
headers.put("X-APP-ID", "yourAppId");
headers.put("Authorization", "yourAuthorization");
headers.put("Content-Type", "application/json");
// 创建请求对象
JSONObject request = new JSONObject();
request.append("timestamp", System.currentTimeMillis() / 1000);
request.append("file_link", "http://yourAudioAddress.wav");
request.append("req_id", "yourRequestId");
request.append("enable_callback", true);
request.append("callback_url", "http://callback-address");
// 发起HTTP请求
HttpResponse response =
HttpRequest.post(url)
.headerMap(headers, false)
.body(JSONUtil.toJsonStr(request))
.execute();
// 打印返回结果
System.out.println(response.body());
}
}
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 = {
"timestamp": int(time.time()),
"file_link": "https://gw.alipayobjects.com/os/bmw-prod/0574ee2e-f494-45a5-820f-63aee583045a.wav",
"req_id": "yourRequestId",
"enable_callback": True,
"callback_url": "http://{ip}/{port}/{uri}"
}
# 构建请求头
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}")