📚 API 接口文档

通过 HTTP 请求调用语音合成服务,支持多种编程语言

🚀 快速开始

  1. 官网注册 账号
  2. 登录后进入 API Key 管理 获取你的 API Key(格式:tts-xxxxxxxx
  3. 联系管理员充值余额(充值记录
  4. 按本文档调用 API,费用按字符数自动扣除

🔐 认证方式

所有 API 请求需要在 HTTP Header 中携带 API Key:

X-API-Key: tts-your-api-key-here

认证错误码

HTTP 状态码code说明
401401API Key 缺失或无效
403403账号已被禁用

🎙️ 语音合成

POST /api/v1/tts

提交文本和参考音频 URL,生成语音。

请求参数(JSON Body)

参数名类型必填默认值说明
textstring✅ 是-要合成的文本,最大 5000 字符
prompt_audio_urlstring✅ 是-音色参考音频的 URL 地址(需公网可访问)
emo_control_methodstringsame情感控制方式:same / ref_audio / vector
emo_ref_urlstring-情感参考音频 URL(ref_audio 方式时需要)
emo_weightfloat0.65情感权重,范围 0~1
emo_vectorfloat[8]全0情感向量 [喜,怒,哀,惧,厌恶,低落,惊喜,平静],各维度 0~1
temperaturefloat0.8采样温度 0.1~2.0,越高越随机
top_pfloat0.8Nucleus 采样概率阈值 0~1
top_kint30Top-K 采样,0=不限制
output_formatstringurl输出格式: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
  }
}

错误码

codeHTTP说明
200200✅ 成功
400400请求参数错误(缺少必填参数或格式错误)
401401API Key 无效或未提供
402402余额不足,请充值
403403账号已被禁用
500500服务器内部错误或 TTS 服务异常

cURL 示例

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"
  }'

Python 示例

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']}")

JavaScript / Node.js 示例

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);

PHP 示例

📊 查询账户信息

GET /api/v1/account

查询当前 API Key 对应的账户余额和用量统计。

请求示例

curl -H "X-API-Key: tts-your-api-key" \
  https://tts.juchuang.cloud/api/v1/account

Python 示例

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

🧪 在线测试

你也可以在 🎙️ 语音合成 页面直接试用,无需编写代码。