音潮开放平台
使用指南仿写歌曲

仿写歌曲

仿写模式与提示词生成共用 POST /api/v1/song/generate 接口,将 task_type 设为 reference 并传入参考音频即可。该接口为异步模式,提交后返回 task_id,需轮询 GET /api/v1/task/query 获取结果。

请求参数说明

参数必填说明
model模型版本,当前支持 v3.5
task_type固定为 reference(仿写模式)
reference_audio参考音频,见下方说明
prompt提示词 prompt:补充风格描述
lyric自定义歌词
similarity与参考音频的相似度,取值为[0.2, 0.8, 1.3, 1.5]
n生成歌曲数量,默认 2,最大 2

参考音频 reference_audio

字段说明
audio_typeupload_id(上传文件 ID)、audio_id(平台歌曲 ID)或 audio_url(公网 URL)
audio_content对应类型的 ID 或 URL

若使用本地音频文件,需先调用 POST /api/v1/file/upload 上传,将返回的 id 作为 upload_id 使用。

1. 上传参考音频(可选)

curl -X POST "https://open.yinchaoyongxian.com/api/v1/file/upload" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@reference.mp3" \
-F "upload_type=reference"

2. 提交仿写任务

curl -X POST "https://open.yinchaoyongxian.com/api/v1/song/generate" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
  "model": "v3.5",
  "task_type": "reference",
  "prompt": "保持参考曲的律动感,换成爵士风格",
  "reference_audio": {
    "audio_type": "upload_id",
    "audio_content": "UPLOAD_FILE_ID"
  },
  "similarity": 0.8,
  "n": 2
}'

3. 轮询任务状态

仿写任务与提示词生成使用相同的轮询方式,调用 query 接口直到歌曲 statusdone

import time
import requests

API_KEY = "YOUR_API_KEY"
BASE = "https://open.yinchaoyongxian.com"
headers = {"Authorization": f"Bearer {API_KEY}"}

task_id = "3fa85f64-5717-4562-b3fc-2c963f66afa6"

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["title"], song["audio_url"])
      elif song["status"] == "fail":
          print(song["error"])

  if all(s["status"] in ("done", "fail") for s in task.get("choices", [])):
      break

  time.sleep(3)

相关接口