体验中心
体验中国电信星辰大模型效果
协议类型:HTTP
| 环境 | 地址 |
|---|---|
| 公网 | https://api-maas.teleai.com.cn/aipaas/voice/v1/tts/offLineSynthesisAsync |
/aipaas/voice/v1/tts/offLineSynthesisAsyncPOSTapplication/json采用请求头携带鉴权信息:
Authorization: <鉴权信息>
| 请求头 | 必填 | 说明 |
|---|---|---|
Content-Type |
是 | 内容类型,固定 application/json |
X-APP-ID |
是 | 控制台 → 应用管理 → AppID |
Device-Uuid |
否 | 设备uuid |
Authorization |
是 | 鉴权信息 |
Authorization: Bearer <用户申请的API-KEY>
| 请求头 | 必填 | 说明 |
|---|---|---|
Content-Type |
是 | 内容类型,固定 application/json |
Device-Uuid |
否 | 设备uuid |
Authorization |
是 | Bearer |
离线语音合成模型是一种能够在没有互联网连接的情况下将文本转换为语音的技术,在智能家居、车载系统、移动应用和辅助技术等领域有着广泛的应用。
| 参数名 | 必填 | 类型 | 说明 |
|---|---|---|---|
timestamp |
是 | [int] | 当前时间的整形时间戳,精确到秒,10 分钟内有效 |
req_id |
是 | [string] | 请求全局唯一 ID,记录该值便于排查问题 |
text |
是 | [string] | 待合成的文本,需要为 UTF-8 编码 |
ret_mode |
否 | [int] | 合成音频的返回模式,默认值 1 |
format |
否 | [string] | 音频编码格式,支持 PCM、WAV、MP3 格式,默认值:PCM |
voice |
否 | [string] | 说话人,支持说话人:yixiaoling、yixiaotian、yixiaoluo、yixiaotong、yixiaohui、yixiaoxuan、yixiaochao、yixiaowei、yixiaoliang、yixiaoshen、yixiaojing、yixiaoke、yixiaorou、yixiaobei、yixiaoxin-female、yixiaoxin-male、yixiaobin、malili、tianxu、yixiaoqing、sarah |
sample_rate |
否 | [int] | 音频采样率,支持 16000 Hz,默认值:16000 |
volume |
否 | [int] | 音量,取值范围:[0, 100],默认值:50 |
speech_rate |
否 | [float] | 语速,取值范围:[0.5, 2.0],默认值:1.0 |
pitch |
否 | [float] | 语调,取值范围:[0.5, 2.0],默认值:1.0 |
voice可选值:yixiaoling:翼小玲、yixiaotian:翼小甜、yixiaoluo:翼小萝、yixiaotong:翼小童、yixiaohui:翼小慧、yixiaoxuan:翼小轩、yixiaochao:翼小超、yixiaowei:翼小威、yixiaoliang:翼小亮、yixiaoshen:翼小深、yixiaojing:翼小京、yixiaoke:翼小可、yixiaorou:翼小柔、yixiaobei:翼小贝、yixiaoxin-female:翼小馨、yixiaoxin-male:翼小鑫、yixiaobin:翼小彬、malili:马丽丽、tianxu:田旭、yixiaoqing:翼小青、sarah:sarah
| 参数名 | 必填 | 类型 | 说明 |
|---|---|---|---|
code |
是 | [string] | 状态码,10000 |
msg |
是 | [string] | 说明,调用成功 |
requestId |
是 | [string] | 请求 ID,用于查询模型结果,test001 |
{
"code": "10000",
"msg": "调用成功",
"requestId": "test001"
}
{
"code": "10093",
"msg": "调用失败",
"requestId": "test001"
}
通用状态码请参考【状态码】中的【网关认证】,其余状态码如下:
| 返回码 | 解释 | 说明 | 解决方法 |
|---|---|---|---|
10301 |
Required parameter miss | 必填参数缺失 | 检查请求体是否符合接口协议 |
10302 |
Too many requests | 并发请求过多 | 联系商务,增加并发 |
10304 |
Parse request body fail | 请求格式错误 | 查看请求的 URL body 格式是否正确,参考接口文档 |
10401 |
Authorize fail | 授权失败 | 联系技术人员 |
10503 |
Server connection time out | 服务连接超时 | 联系技术人员 |
10903 |
Recognize failed | 识别失败 | 联系技术人员 |
10000 |
Success | 成功 | 执行下一步操作 |
{
"timestamp": 1673493479,
"req_id": "test001",
"text": "今天是周一,天气挺好的。"
}
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("Content-Type", "application/json");
headers.put("X-APP-ID", "yourAppId");
headers.put("Authorization", "yourAuthorization");
// 创建请求对象
Map request = new HashMap();
request.put("timestamp", System.currentTimeMillis());
request.put("req_id", "test001");
request.put("text", "今天是周一,天气挺好的。");
// 将请求对象转换为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 = {
"timestamp": int(time.time()),
"req_id": "test001",
"text": "今天是周一,天气挺好的。"
}
# 构建请求头
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}")