音效与音乐
POST /v1/sound-generation · POST /v1/music
用一句文字描述生成音效(脚步声、爆炸、环境声等)或整首音乐。参数、请求体、响应格式均与 ElevenLabs 官方 API 一致,使用官方 SDK 时只需把 base URL 换成本站域名、key 换成本站 API Key。
鉴权:请求头 xi-api-key: YOUR_API_KEY(官方 SDK 的默认方式);也可以用 Authorization: Bearer YOUR_API_KEY。
| 能力 | 端点 | 模型 | 计费 |
|---|---|---|---|
| 音效 | POST /v1/sound-generation |
eleven_text_to_sound_v2 |
按秒(指定的时长) |
| 音乐 | POST /v1/music、POST /v1/music/stream |
music_v1 |
按秒(指定的时长) |
1. 音效:POST /v1/sound-generation
1.1 请求参数
| 参数 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
text |
body | string | 是 | 音效描述,如 "Heavy rain on a tin roof, distant thunder" |
duration_seconds |
body | number | 否 | 音效时长,0.5–30 秒。不传或传 null 时由模型自动决定长度,按 5 秒计费(见 1.4 计费) |
loop |
body | boolean | 否 | 是否生成可无缝循环的音效,默认 false |
prompt_influence |
body | number | 否 | 0–1,默认 0.3。越高越贴近描述、变化越少 |
model_id |
body | string | 否 | 默认 eleven_text_to_sound_v2。目前支持的模型只有这一个 |
output_format |
query | string | 否 | 输出格式,默认 mp3_44100_128。可用值与语音合成相同,见 语音合成 · 输出格式 |
1.2 请求示例
cURL
curl "https://api.modeltap.net/v1/sound-generation?output_format=mp3_44100_128" \
-H "Content-Type: application/json" \
-H "xi-api-key: YOUR_API_KEY" \
-d '{
"text": "Heavy rain on a tin roof, distant thunder",
"duration_seconds": 3
}' \
--output rain.mp3Python(ElevenLabs 官方 SDK)
from elevenlabs.client import ElevenLabs
client = ElevenLabs(
api_key="YOUR_API_KEY",
base_url="https://api.modeltap.net",
)
audio = client.text_to_sound_effects.convert(
text="Heavy rain on a tin roof, distant thunder",
duration_seconds=3,
output_format="mp3_44100_128",
)
with open("rain.mp3", "wb") as f:
for chunk in audio:
f.write(chunk)1.3 响应
响应体直接是音频字节,格式由 output_format 决定。音效没有 /stream 流式版本(单条最长 30 秒,几秒内即可生成)。
1.4 计费
按秒计费,数量在请求时确定,与实际生成的音频长度无关:
| 请求 | 计费秒数 |
|---|---|
传了 duration_seconds |
该值(如 3 → 3 秒,2.5 → 2.5 秒) |
未传或为 null |
固定 5 秒(自动时长的实际产物可能更短,仍按 5 秒计) |
费用 = 计费秒数 × 模型目录中 eleven_text_to_sound_v2 的每秒单价 × 你的折扣。需要可预期的成本时,请显式传 duration_seconds。
2. 音乐:POST /v1/music
| 端点 | 说明 |
|---|---|
POST /v1/music |
生成完成后一次性返回音频 |
POST /v1/music/stream |
边生成边流式返回音频,长音乐推荐 |
2.1 请求参数
prompt 与 composition_plan 二选一,且必须能确定时长:用 prompt 时必须传 music_length_ms;用 composition_plan 时以各段 duration_ms 之和为时长。无法确定时长的请求返回 400。
| 参数 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
prompt |
body | string | 二选一 | 文字描述,如风格、情绪、乐器、是否有人声 |
music_length_ms |
body | integer | 用 prompt 时必填 |
时长(毫秒),3000–600000(3 秒–10 分钟) |
composition_plan |
body | object | 二选一 | 分段作曲计划,结构见下。各段不能引用已有歌曲(sections[].source_from),否则返回 400 |
model_id |
body | string | 否 | 默认 music_v1。目前支持的模型只有这一个 |
force_instrumental |
body | boolean | 否 | true 时保证纯音乐(无人声),仅与 prompt 一起使用 |
seed |
body | integer | 否 | 随机种子,尽力复现;仅与 composition_plan 一起使用 |
respect_sections_durations |
body | boolean | 否 | 只支持 true(默认,严格遵守 composition_plan 中各段时长);传 false 返回 400,因为计费时长以计划为准 |
output_format |
query | string | 否 | 默认 mp3_44100_128,可用值见 语音合成 · 输出格式 |
不支持的参数(返回 400):finetune_id(非 null 时)、store_for_inpainting: true、respect_sections_durations: false、作曲计划中引用已有歌曲(source_from / song_id)。
composition_plan 结构:
{
"positive_global_styles": ["lo-fi hip hop", "warm", "relaxed"],
"negative_global_styles": ["distorted guitar"],
"sections": [
{
"section_name": "Intro",
"positive_local_styles": ["soft piano"],
"negative_local_styles": [],
"duration_ms": 10000,
"lines": []
},
{
"section_name": "Verse",
"positive_local_styles": ["female vocal"],
"negative_local_styles": [],
"duration_ms": 20000,
"lines": ["城市的灯光慢慢亮起", "我走在回家的路上"]
}
]
}上例计费时长 = 10000 + 20000 = 30000 毫秒 = 30 秒。
2.2 请求示例
cURL
curl "https://api.modeltap.net/v1/music" \
-H "Content-Type: application/json" \
-H "xi-api-key: YOUR_API_KEY" \
-d '{
"prompt": "Upbeat electronic track with a catchy synth melody, no vocals",
"music_length_ms": 30000,
"model_id": "music_v1"
}' \
--output music.mp3Python(ElevenLabs 官方 SDK)
from elevenlabs.client import ElevenLabs
client = ElevenLabs(
api_key="YOUR_API_KEY",
base_url="https://api.modeltap.net",
)
audio = client.music.compose(
prompt="Upbeat electronic track with a catchy synth melody, no vocals",
music_length_ms=30000,
model_id="music_v1",
)
with open("music.mp3", "wb") as f:
for chunk in audio:
f.write(chunk)流式版本用 client.music.stream(...),参数相同。生成较长音乐耗时较长(10 秒的音乐约 5 秒,长曲需数分钟),请把客户端读超时设得足够长。长音乐建议使用 /v1/music/stream:同步接口要等整首生成完才一次性返回,输出超过 64 MB 时会失败(502)。
2.3 响应
响应体直接是音频字节,格式由 output_format 决定。
2.4 计费
按秒计费,数量 = 请求中指定的时长,与实际生成的音频长度无关:
| 请求 | 计费秒数 |
|---|---|
prompt + music_length_ms |
music_length_ms ÷ 1000 |
composition_plan |
各段 duration_ms 之和 ÷ 1000(sections[];chunks[] 结构同理) |
费用 = 计费秒数 × 模型目录中 music_v1 的每秒单价 × 你的折扣。
3. 暂不提供
/v1/music/detailed、/v1/music/plan(作曲计划生成)、音乐微调(finetune)、音乐编辑(inpainting)、视频配乐、分轨等音乐相关端点暂不提供。
4. 用量记录与错误
用量记录:音效与音乐在用量明细和账单中按「按秒」计费方式记录,prompt_tokens / completion_tokens 均为 0,计费秒数与每秒单价见导出明细的 flat_quantity / flat_unit_price_usd 列,详见 账单对账与用量自动同步。
| 状态码 | 含义与处理 |
|---|---|
| 400 | 参数不支持或取值非法(如音乐未指定时长、prompt 与 composition_plan 同时传、使用了不支持的参数),message 中说明具体字段 |
| 403 | output_format_not_allowed:所选输出格式当前不可用 |
| 422 | 参数校验失败(如 duration_seconds 越界),原样返回模型厂商的错误体 |
| 429 | 服务繁忙,请指数退避后重试 |
| 502 | 同步音乐接口的输出过大(超过 64 MB)无法返回,请改用 /v1/music/stream |
| 503 | 请求了目前不支持的模型(如其他 music_*、eleven_text_to_sound_v3),请改用上文列出的模型 |
每个响应都带 X-Request-ID(本站请求 ID)。反馈问题时请提供这个值。