本文档由 云音工坊 自动生成,如有疑问,请联系客服微信:yuntts !
| 项目 | 值 |
|---|---|
| 合成接口 | POST /api/v1/microsoft-tts |
| 异步状态查询 | POST /api/v1/microsoft-tts-status |
| 请求格式 | application/json(也兼容 application/x-www-form-urlencoded) |
| 认证方式 | Authorization: Bearer <API_KEY> |
text 与 ssml 时以 ssml 为准):text 必填,其余可选。| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
text | string | ✅ | - | 要合成的文本内容(服务端未强制长度;同步建议 ≤ 5000,异步建议 ≤ 100000) |
voice | string | ❌ | zh-CN-XiaoxiaoNeural | 音色名称 |
language | string | ❌ | zh-CN | 语言代码,写入 SSML 的 xml:lang |
rate | string | ❌ | 0 | 语速(相对百分比,10 = +10%,-10 = -10%;0 不写入) |
volume | string | ❌ | 100 | 音量(绝对 0-100,0 为静音;非空即写入) |
pitch | string | ❌ | 0 | 音调(相对百分比,2 = +2%;0 不写入) |
style | string | ❌ | general | 说话风格;空或 general = 不指定 |
role | string | ❌ | general | 角色风格;仅 style 生效时才写入 |
styledegree | string | ❌ | 1 | 风格强度 0.01-2.0;1 不写入 |
kbitrate | string | ❌ | audio-48khz-96kbitrate-mono-mp3 | 音频编码与质量 |
backgroundaudio | string | ❌ | - | 背景音直链(http/https) |
backgroundvolume | string | ❌ | - | 背景音音量 0-100 |
stream | boolean | ❌ | true | true=流式返回音频二进制;false=保存音频并返回 audio_url |
async | boolean | ❌ | false | true=提交长文本批量任务并返回 task_id |
{
"text": "您好,这是一个 Microsoft TTS 语音合成示例。",
"voice": "zh-CN-XiaoxiaoNeural",
"style": "friendly",
"rate": "10",
"stream": true
}ssml 必填。| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
ssml | string | ✅ | - | 完整 SSML 文档:必须含 <speak>、至少一个 <voice>,且含命名空间 xmlns="http://www.w3.org/2001/10/synthesis";必须是良构 XML |
kbitrate | string | ❌ | audio-48khz-96kbitrate-mono-mp3 | 音频编码与质量 |
stream | boolean | ❌ | true | 同模式一 |
async | boolean | ❌ | false | 同模式一 |
{
"ssml": "<speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\" xmlns:mstts=\"http://www.w3.org/2001/mstts\" xml:lang=\"zh-CN\"><voice name=\"zh-CN-XiaoxiaoNeural\"><mstts:express-as style=\"friendly\">您好,这是 SSML 示例。</mstts:express-as></voice></speak>"
}| 方式 | 参数 | 成功响应 | 计费时机 |
|---|---|---|---|
| 流式 | async=false, stream=true(默认) | audio/mpeg 二进制(chunked + X-Characters/X-Cost) | 收到首个音频字节时扣费 |
| 关闭流式 | async=false, stream=false | JSON,音频地址在 data.audio_url | 音频落盘后扣费 |
| 异步(长文本) | async=true | JSON,返回 task_id,再用 -status 轮询 | 提交时扣费,失败自动退款 |
stream=true)audio/mpeg 二进制(不是 JSON)Content-Type: audio/mpeg
Transfer-Encoding: chunked
X-Accel-Buffering: no
X-Characters: 42
X-Cost: 0.01
Access-Control-Expose-Headers: X-Characters, X-Coststream=false){
"code": 200,
"message": "合成成功",
"data": {
"audio_url": "http://your-site/wp-content/uploads/my-document/audio/processed/1791448781_21220898.mp3",
"format": "mp3",
"char_count": 17,
"cost": 0.001,
"balance": 2.265
}
}async=true){
"code": 200,
"message": "任务已提交,正在处理中",
"data": { "task_id": "808_1852492485_1791445288", "char_count": 21, "cost": 0.001, "balance": 2.266 }
}POST /api/v1/microsoft-tts-status,body { "task_id": "..." };三种状态都是 HTTP 200,靠 data.status 区分:{ "code": 200, "message": "ok", "data": { "task_id": "808_…", "status": "processing", "progress": 50 } }{ "code": 200, "message": "ok", "data": { "task_id": "808_…", "status": "completed", "progress": 100, "zip_url": "http://your-site/wp-content/uploads/…/tts_808_….zip" } }{ "code": 200, "message": "ok", "data": { "task_id": "808_…", "status": "failed", "progress": 0, "msg": "合成失败,费用已退回" } }completed的zip_url是已转存到本站的压缩包(内含0001.mp3),不会给几天后就失效的临时链接。
{ "code": <HTTP 状态码>, "error": "<错误码>", "message": "<描述>" }{ "code": 400, "error": "invalid_ssml", "message": "SSML格式不正确,必须包含<voice>标签" }{ "code": "rest_invalid_api_key", "message": "API密钥无效", "data": { "status": 401 } }| 错误码 | HTTP | 说明 |
|---|---|---|
method_not_allowed | 405 | 非 POST 请求 |
rest_forbidden / rest_invalid_auth / rest_missing_api_key / rest_invalid_api_key | 401 | 鉴权失败(WP REST 形态) |
empty_text | 400 | text 与 ssml 均为空 |
invalid_ssml | 400 | SSML 校验失败(缺 <speak> / <voice> / 命名空间,或非良构 XML) |
missing_task_id | 400 | 状态查询未传 task_id |
insufficient_balance | 403 | 余额不足 |
task_not_found | 404 | 状态查询:任务不存在或非本人 |
missing_config | 500 | 语音合成账户未配置 |
save_failed | 500 | 关闭流式时音频保存失败(此时不会扣费) |
task_create_failed | 500 | 异步建任务落库失败(已自动退款) |
api_error | 服务端状态码 / 500 / 502 | 合成请求失败或业务错误 |
parse_error | 500 | 响应无法解析 |
Script=Han):计 2 个字符扣费点数 = 超出免费额度的字符数 × 单价 × 折扣api_free、永久会员走 perm_free)。| 方式 | 时机 |
|---|---|
流式(stream=true) | 首个音频字节到达时扣费;中途 curl 中断自动退款 |
关闭流式(stream=false) | 先落盘再扣费:落盘失败就一分钱不扣 |
异步(async=true) | 提交时即扣费并建订单;任务失败按提交时的额度分解精确回滚 + 原路退款 |
<speak version="1.0"
xmlns="http://www.w3.org/2001/10/synthesis"
xmlns:mstts="http://www.w3.org/2001/mstts"
xml:lang="{language}">| 参数 | 规则 |
|---|---|
rate | 纯数字自动补 %(10 → rate="10%");0 / 0% / 空 → 不输出 |
pitch | 同 rate |
volume | 空 → 不输出;其他值原样输出(100 也会写入,等价默认音量) |
style | 空或 general → 整个 <mstts:express-as> 不输出(role、styledegree 随之失效) |
role | 空 / general / null → 不输出;仅当 style 生效时才会写入 |
styledegree | 空或 1 → 不输出;服务端不钳制范围 |
backgroundaudio | 非空 → 输出 <mstts:backgroundaudio src="…" [volume="…"] fadein="3000" fadeout="4000"/>,且必须是 <speak> 的第一个子元素 |
<mstts:express-as> 内为 role → style → styledegree;<prosody> 内为 volume → rate → pitch。zh-CN-XiaoxiaoDialectsNeural 会自动用 <lang xml:lang="…"> 包裹文本。<break time="0.5s"/>、<phoneme>、<say-as>)会被原样保留并生效。& 与 < 会让 SSML 非良构而被拒绝(400 invalid_ssml),需要写成 & 与 <。<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xml:lang="zh-CN">
<mstts:backgroundaudio src="https://example.com/bgm.mp3" volume="50" fadein="3000" fadeout="4000"/>
<voice name="zh-CN-XiaoxiaoNeural">
<mstts:express-as role="YoungAdultFemale" style="friendly" styledegree="1.5">
<prosody volume="90" rate="10%" pitch="2%">
您好,这是一个示例。
</prosody>
</mstts:express-as>
</voice>
</speak>| 音色名称 | 语言 | 性别 |
|---|---|---|
zh-CN-XiaoxiaoNeural | 中文(简体) | 女 |
zh-CN-YunxiNeural | 中文(简体) | 男 |
zh-CN-XiaoyiNeural | 中文(简体) | 女 |
zh-CN-YunyangNeural | 中文(简体) | 男 |
en-US-JennyNeural | 英语(美国) | 女 |
en-US-GuyNeural | 英语(美国) | 男 |
ja-JP-NanamiNeural | 日语 | 女 |
friendly、excited、sad、angry、calm、cheerful、fearful、whispering、newscast、customerservice、assistant 等(general 为「不指定」,不是有效风格值)。Girl、Boy、YoungAdultFemale、YoungAdultMale、OlderAdultFemale、OlderAdultMale、SeniorFemale、SeniorMale| 值 | 说明 |
|---|---|
audio-48khz-96kbitrate-mono-mp3 | 48kHz 96kbps 单声道 MP3(默认) |
audio-24khz-48kbitrate-mono-mp3 | 24kHz 48kbps 单声道 MP3 |
audio-16khz-32kbitrate-mono-mp3 | 16kHz 32kbps 单声道 MP3 |