前言说明

本接口基于 Fish Speech 开源语音合成项目,由 Fish Audio 团队开发维护。Fish Audio S2 Pro 是当前最先进的多语言 TTS 系统之一,基于超过 1000 万小时音频数据训练,覆盖 80+ 语言,采用 Dual-Autoregressive(Dual-AR)架构与强化学习对齐,生成语音自然、真实、富有情感。

API接口插图

其他说明


1. 语音合成

POST https://www.yuntts.com/api/v1/fish-audio/tts

将文本转换为语音,支持三种模式:基础音色合成、多人对话、零样本克隆。

请求头

参数 类型 必填 说明
model string TTS 模型,可选 s1 / s2-pro(默认),s2-pro 支持多人对话
Authorization string 用户认证 Token

请求体(application/json)

参数 类型 必填 默认值 说明
text string 要合成的文本
reference_id string / string[] 条件必填 音色模型ID。基础合成传字符串,多人对话传字符串数组。与 references 二选一
references object[] 条件必填 零样本克隆参考音频数组,与 reference_id 二选一
references[].audio string 参考音频,Base64 编码字符串(需使用 MessagePack 序列化请求体)
references[].text string 参考音频对应的文本,有助于提升克隆质量
temperature number 0.7 控制表达性,越高越多样,越低越稳定。范围:0 ~ 1
top_p number 0.7 Nucleus 采样多样性控制。范围:0 ~ 1
chunk_length integer 300 文本分段长度。范围:100 ~ 300
normalize boolean true 标准化文本(数字转文字、日期格式化等),提升中英文稳定性
format string mp3 输出音频格式:wav / pcm / mp3 / opus
sample_rate integer 格式默认值 音频采样率(Hz)。WAV/PCM/MP3 默认 44100,Opus 默认 48000
mp3_bitrate integer 128 MP3 比特率(kbps),仅 format 为 mp3 时生效。可选:64 / 128 / 192
opus_bitrate integer -1000 Opus 比特率(bps),-1000 为自动,仅 format 为 opus 时生效。可选:-1000 / 24000 / 32000 / 48000 / 64000
latency string normal 延迟模式:normal(最佳质量)/ balanced(降低延迟)/ low(最低延迟)
prosody object 韵律控制
prosody.speed number 语速控制,1.0 为正常语速
prosody.volume number 音量控制,0 为正常音量
prosody.normalize_loudness boolean 响度归一化
max_new_tokens integer 1024 每个文本段生成的最大音频 token 数
repetition_penalty number 1.2 重复模式惩罚,高于 1.0 减少重复
min_chunk_length integer 50 新分段前最小字符数。范围:0 ~ 100
condition_on_previous_chunks boolean true 使用前一段音频作为上下文以保持语音一致性
early_stop_threshold number 1 批量处理提前停止阈值。范围:0 ~ 1
stream boolean true 是否启用流式合成。true 直接返回音频流,false 下载后返回 JSON

三种模式说明

模式一:基础音色合成

{
    "text": "你好,欢迎使用语音合成",
    "reference_id": "7f92f8afb8ec43bf81429cc1c9199cb1"
}

模式二:多人对话(仅 s2-pro 模型)

{
    "text": "<|speaker:0|>你好!<|speaker:1|>你好啊!<|speaker:0|>今天天气不错",
    "reference_id": ["model-id-alice", "model-id-bob"]
}

使用 <|speaker:N|> 标签切换说话者,reference_id 为模型ID数组,按索引对应。

模式三:零样本克隆

{
    "text": "你好,这是克隆语音",
    "references": [
        {
            "audio": "Base64编码的音频数据",
            "text": "参考音频对应的文本"
        }
    ]
}

零样本克隆需使用 application/msgpack(MessagePack)序列化请求体以传输二进制音频数据,或使用 application/json 配合 Base64 编码。

stream 参数响应说明

stream: true(默认)

直接返回音频二进制流,响应头包含:

响应头 说明 示例
Content-Type 音频 MIME 类型 audio/mpeg(mp3)、audio/wav(wav)、audio/pcm(pcm)、audio/opus(opus)
Content-Length 音频文件大小(字节) 65536
X-Characters 合成字符数 150
X-Cost 扣费金额(元) 0.021
X-Task-Id 任务唯一ID fishaudio_664f8a1b2c3d4

stream: false

返回 JSON:

{
    "url": "https://www.yuntts.com/wp-content/uploads/audio/processed/202605/fishaudio_xxx.mp3",
    "chars": 150,
    "cost": 0.021,
    "task_id": "fishaudio_664f8a1b2c3d4"
}

2. 创建音色模型

POST https://www.yuntts.com/api/v1/fish-audio/model

上传音频文件创建音色模型,使用 multipart/form-data 格式。

请求参数

参数 类型 必填 默认值 说明
title string 音色模型名称
voices file[] 训练音频文件,支持 mp3/wav/m4a/opus,单个最大 20MB,最多 10 个
visibility string private 可见性:public(公开,展示在发现页)/ unlist(不公开,链接可访问)/ private(仅自己可见)
description string 模型描述说明
cover_image file 模型封面图片,仅允许 jpg/jpeg/png,最大 5MB。公开模型(public)时必填
train_mode string fast 训练模式,目前仅支持 fast(快速创建,立即可用)
texts string 音频对应的文本,不传则自动进行语音识别(ASR)
tags string 模型标签,多个标签用逗号分隔
enhance_audio_quality boolean false 是否增强音频质量(训练耗时略长)

响应示例

{
    "model_id": "7f92f8afb8ec43bf81429cc1c9199cb1",
    "title": "我的音色",
    "description": "音色描述",
    "state": "created",
    "visibility": "private",
    "train_mode": "fast",
    "cover_image": "",
    "samples": [],
    "reference_id": "7f92f8afb8ec43bf81429cc1c9199cb1",
    "message": "音色模型创建成功,训练中请稍候"
}

模型数量限制

用户类型 最大模型数
普通用户 2 个
VIP 10 个
BOOS VIP 无限制

3. 获取音色列表

GET https://www.yuntts.com/api/v1/fish-audio/model/list

查询音色模型列表,支持分页和筛选。

Query 参数

参数 类型 必填 默认值 说明
page integer 1 当前页码
page_size integer 20 每页数量,范围 1 ~ 100
search string 按音色名称模糊搜索
visibility string 筛选可见性:public / private
source string 筛选来源:official(官方)/ community(社区)/ upload(用户上传),不传则不筛选

响应示例

{
    "total": 56,
    "items": [
        {
            "_id": "7f92f8afb8ec43bf81429cc1c9199cb1",
            "title": "音色名称",
            "description": "音色描述",
            "cover_image": "https://www.yuntts.com/.../cover.jpg",
            "state": "trained",
            "tags": [],
            "created_at": "2026-05-20 10:30:00",
            "updated_at": "2026-05-20 10:30:00",
            "visibility": "public",
            "like_count": 0,
            "mark_count": 0,
            "shared_count": 0,
            "task_count": 0,
            "train_mode": "fast",
            "samples": ["https://www.yuntts.com/.../sample.mp3"],
            "languages": ["zh-CN"],
            "voice_source": "official",
            "author": {
                "_id": "1",
                "nickname": "用户昵称",
                "avatar": ""
            },
            "is_own": true
        }
    ],
    "has_more": true
}

4. 更新音色模型

PATCH / POST https://www.yuntts.com/api/v1/fish-audio/model/update

更新音色模型信息,只能更新自己创建的模型。

Query 参数

参数 类型 必填 说明
model_id string 要更新的音色模型ID

请求参数(Body)

至少需要提供一个更新字段。无文件上传时使用 application/json,有文件上传时使用 multipart/form-data

参数 类型 必填 说明
title string 条件必填 音色模型名称
description string 条件必填 模型描述说明
visibility string 条件必填 可见性:public / unlist / private
tags string 条件必填 模型标签,多个用逗号分隔
cover_image file 条件必填 模型封面图片,仅允许 jpg/jpeg/png,最大 5MB

响应示例

{
    "model_id": "7f92f8afb8ec43bf81429cc1c9199cb1",
    "title": "更新后的名称",
    "description": "更新后的描述",
    "visibility": "public",
    "cover_image": "https://www.yuntts.com/.../cover.jpg",
    "message": "音色模型更新成功"
}

5. 删除音色模型

DELETE https://www.yuntts.com/api/v1/fish-audio/model/delete

删除音色模型,只能删除自己创建的模型。

Query 参数

参数 类型 必填 说明
model_id string 要删除的音色模型ID

响应示例

{
    "model_id": "7f92f8afb8ec43bf81429cc1c9199cb1",
    "message": "音色模型删除成功"
}

通用错误码

HTTP 状态码 错误码 说明
400 missing_text 未提供合成文本
400 missing_reference 未提供 reference_id 或 references
400 invalid_model model 可选值:s1 / s2-pro
400 invalid_format format 可选值:wav / pcm / mp3 / opus
400 invalid_visibility visibility 可选值:public / unlist / private
400 missing_title 未提供音色名称
400 missing_audio 未上传音频文件
400 invalid_audio_type 音频文件格式不支持
400 audio_too_large 音频文件超过 20MB
400 too_many_files 音频文件数量超过 10 个
400 missing_cover_image 公开模型必须上传封面图片
400 model_limit_exceeded 音色模型数量已达上限
400 missing_params 至少需要提供一个更新参数
401 unauthorized 未登录或认证失败
402 insufficient_balance 余额不足
403 permission_denied 无权操作此模型
404 model_not_found 模型不存在或已被删除
405 method_not_allowed 请求方法不允许
500 internal_error 服务器内部错误
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。