通过 HTTP 请求调用语音合成服务,支持多种编程语言
tts-xxxxxxxx)所有 API 请求需要在 HTTP Header 中携带 API Key:
X-API-Key: tts-your-api-key-here
| HTTP 状态码 | code | 说明 |
|---|---|---|
| 401 | 401 | API Key 缺失或无效 |
| 403 | 403 | 账号已被禁用 |
提交文本和参考音频 URL,生成语音。
| 参数名 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
text | string | ✅ 是 | - | 要合成的文本,最大 5000 字符 |
prompt_audio_url | string | ✅ 是 | - | 音色参考音频的 URL 地址(需公网可访问) |
emo_control_method | string | 否 | same | 情感控制方式:same / ref_audio / vector |
emo_ref_url | string | 否 | - | 情感参考音频 URL(ref_audio 方式时需要) |
emo_weight | float | 否 | 0.65 | 情感权重,范围 0~1 |
emo_vector | float[8] | 否 | 全0 | 情感向量 [喜,怒,哀,惧,厌恶,低落,惊喜,平静],各维度 0~1 |
temperature | float | 否 | 0.8 | 采样温度 0.1~2.0,越高越随机 |
top_p | float | 否 | 0.8 | Nucleus 采样概率阈值 0~1 |
top_k | int | 否 | 30 | Top-K 采样,0=不限制 |
output_format | string | 否 | url | 输出格式:url(返回音频 URL)/ base64 |
{
"code": 200,
"message": "success",
"data": {
"audio_url": "https://tts.juchuang.cloud/outputs/tts_xxx.wav",
"text": "你好,欢迎使用语音合成。",
"text_length": 13,
"cost": 0.0013,
"balance": 9.9987
}
}
| code | HTTP | 说明 |
|---|---|---|
| 200 | 200 | ✅ 成功 |
| 400 | 400 | 请求参数错误(缺少必填参数或格式错误) |
| 401 | 401 | API Key 无效或未提供 |
| 402 | 402 | 余额不足,请充值 |
| 403 | 403 | 账号已被禁用 |
| 500 | 500 | 服务器内部错误或 TTS 服务异常 |
curl -X POST https://tts.juchuang.cloud/api/v1/tts \
-H "X-API-Key: tts-a1b2c3d4e5f6789012345678" \
-H "Content-Type: application/json" \
-d '{
"text": "你好,欢迎使用语音合成服务。",
"prompt_audio_url": "https://example.com/reference.wav"
}'
import requests
API_KEY = "tts-your-api-key"
API_URL = "https://tts.juchuang.cloud/api/v1/tts"
response = requests.post(API_URL,
headers={
"X-API-Key": API_KEY,
"Content-Type": "application/json"
},
json={
"text": "你好,欢迎使用语音合成服务。",
"prompt_audio_url": "https://example.com/reference.wav"
},
timeout=120
)
result = response.json()
if result["code"] == 200:
audio_url = result["data"]["audio_url"]
print(f"生成成功!\n音频地址:{audio_url}\n消耗:¥{result['data']['cost']}")
# 下载音频
r = requests.get(audio_url)
with open("output.wav", "wb") as f:
f.write(r.content)
else:
print(f"错误 [{result['code']}]: {result['message']}")
const API_KEY = "tts-your-api-key";
const API_URL = "https://tts.juchuang.cloud/api/v1/tts";
async function tts(text, promptAudioUrl) {
const response = await fetch(API_URL, {
method: "POST",
headers: {
"X-API-Key": API_KEY,
"Content-Type": "application/json"
},
body: JSON.stringify({ text, prompt_audio_url: promptAudioUrl })
});
return await response.json();
}
// 使用示例
tts("你好世界", "https://example.com/voice.wav").then(console.log);
查询当前 API Key 对应的账户余额和用量统计。
curl -H "X-API-Key: tts-your-api-key" \
https://tts.juchuang.cloud/api/v1/account
import requests
r = requests.get("https://tts.juchuang.cloud/api/v1/account",
headers={"X-API-Key": "tts-your-api-key"}
)
print(r.json())
# { "code": 200, "data": { "username": "demo", "balance": 50.0, ... } }
{
"code": 200,
"data": {
"username": "demo",
"balance": 50.00,
"total_calls": 1234,
"total_chars": 567890,
"role": "user"
}
}
| 项目 | 说明 |
|---|---|
| 计费方式 | 按字符数计费(¥0.0001 / 字符),含标点,不含空格,不足100字符按100字符计 |
| 超时时间 | 建议客户端设置 120 秒超时,长文本合成需要较长时间 |
| 并发限制 | 同一 API Key 建议串行调用,高并发请联系管理员 |
| 音频有效期 | 生成的音频文件保留 24 小时,请及时下载 |
| 参考音频要求 | 建议 3~10 秒 WAV/MP3,采样率不限,需公网直链 URL |
| 音色文件 | 上传的音色文件保留 7 天,过期自动清理 |
| 文本长度 | 单次最大 5000 字符 |
| 最低充值 | 最低充值金额 ¥10 |
你也可以在 🎙️ 语音合成 页面直接试用,无需编写代码。