TTS API 参考
Shisa TTS API 提供两个端点:一个用于生成语音,一个用于列出可用声音。两者均使用标准 Bearer 令牌进行身份验证。
Authorization: Bearer YOUR_API_KEY
端点
生成语音
POST https://api.shisa.ai/tts
将文本转换为语音音频。以请求的格式返回二进制音频数据。
列出声音
GET https://api.shisa.ai/tts/voices
返回所有可用声音的 JSON 数组,包括其元数据、支持的格式和流式传输功能。目录请参阅声音。
请求参数
POST /tts 端点的参数,以 JSON 主体形式发送:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
voice_id | string | 必填 | 要使用的声音 UUID。可从 GET /tts/voices 获取可用 ID。 |
text | string | 必填 | 要转换为语音的文本。 |
format | string | 必填 | 输出音频格式。必须是所选声音支持的格式。mp3、wav、ogg、pcm、flac 之一。 |
stream | boolean | 可选 | 为 true 时,以分块流形式返回音频用于实时播放。仅适用于 streaming: true 的声音。默认为 false。 |
响应
POST /tts — 二进制音频
成功时,API 返回带有适当 Content-Type 头(例如 audio/mp3)的原始二进制音频数据。将响应体直接保存到文件:
# The response is binary audio data — save directly to file
curl -s -X POST "https://api.shisa.ai/tts" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"voice_id": "61ba1141-60aa-4bc3-a3b3-be1ec20700b3", "format": "mp3", "text": "テスト"}' \
--output speech.mp3
GET /tts/voices — JSON
返回可用声音对象的 JSON 数组:
[
{
"id": "e3362c0a-7677-4cd8-b122-91fb093305c9",
"description": "Young male Japanese voice...",
"language": "Japanese & English",
"gender": "Male",
"formats": ["mp3", "ogg", "pcm"],
"sample_rates": [8000, 16000, 22050, 24000, 32000, 44100, 48000],
"streaming": true
}
]
声音对象字段:
| 字段 | 类型 | 描述 |
|---|---|---|
id | string (uuid) | 在请求中用作 voice_id 的 UUID。 |
description | string | 人类可读的声音描述。 |
language | string | 支持的语言。 |
gender | string | 声音性别(Male、Female、Neutral)。 |
formats | array | 支持的输出音频格式。 |
sample_rates | array | 支持的输出采样率(Hz)。 |
streaming | boolean | 声音是否支持实时流式传输。 |
错误处理
错误以下列格式的 JSON 返回:
{
"context": ["..."],
"code": 104,
"name": "ErrAuthenticationFailed",
"error": "Authentication error: Invalid token"
}
错误代码
| 状态 | 原因 | 解决方案 |
|---|---|---|
400 | 参数缺失或无效 | 检查 voice_id、text 和 format 字段。 |
400 | 声音不支持的格式 | 使用声音 formats 数组中列出的格式。 |
401 | API 密钥无效或缺失 | 检查您的 Authorization: Bearer 头。 |
429 | 超出速率限制 | 使用指数退避等待后重试。 |
500 | 内部服务器错误 | 重试请求或联系技术支持。 |
注意
当请求的 format 不在所选声音的 formats 数组中时,也会返回 400。生成语音前,请使用 GET /tts/voices 确认声音支持的格式。