扩写歌曲
在已有歌曲的基础上继续生成,调用 POST /api/v1/song/extend 提交扩写任务。该接口为异步模式:提交后返回 task_id,需轮询 GET /api/v1/task/query 获取结果。
请求参数说明
| 参数 | 必填 | 说明 |
|---|
| model | 是 | 模型版本,当前支持 v3.5 |
| origin_audio | 是 | 需要扩写的原始音频 |
| lyric | 否 | 扩写部分的歌词 |
| extend_at | 否 | 从哪个时间点(秒)开始扩写;不传则从音频结尾续写 |
| n | 否 | 生成歌曲数量,默认 2,最大 2 |
原始音频 origin_audio
| 字段 | 说明 |
|---|
| audio_type | upload_id、audio_id 或 audio_url |
| audio_content | 对应类型的 ID 或 URL |
本地文件需先通过 POST /api/v1/file/upload 上传,upload_type 设为 extend。
1. 上传原始音频(可选)
curl -X POST "https://open.yinchaoyongxian.com/api/v1/file/upload" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@origin.mp3" \
-F "upload_type=extend"
2. 提交扩写任务
curl -X POST "https://open.yinchaoyongxian.com/api/v1/song/extend" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "v3.5",
"origin_audio": {
"audio_type": "upload_id",
"audio_content": "UPLOAD_FILE_ID"
},
"lyric": "[CHORUS]\n继续唱下去\n让旋律不停歇",
"extend_at": 60.0,
"n": 2
}'
{
"id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
"task_type": "extend",
"choices": [],
"create_at": 1710000000
}
3. 轮询任务状态
import time
import requests
API_KEY = "YOUR_API_KEY"
BASE = "https://open.yinchaoyongxian.com"
headers = {"Authorization": f"Bearer {API_KEY}"}
task_id = "7c9e6679-7425-40de-944b-e07fc1f90ae7"
while True:
resp = requests.get(
f"{BASE}/api/v1/task/query",
params={"task_id": task_id},
headers=headers,
)
task = resp.json()
for song in task.get("choices", []):
if song["status"] == "done":
print(song["audio_url"])
elif song["status"] == "stream":
print("stream:", song["pipe_url"])
if all(s["status"] in ("done", "fail") for s in task.get("choices", [])):
break
time.sleep(3)
相关接口