Skip to content

Suno 歌曲续写 ​

从已有曲目的某个时间点继续创作。需要开通 suno_extend;如果要把续写片段接回前半首,还需 suno_concat。

1. 准备原曲 ​

请在服务端用 Bash,准备 curl(7.76+)和 jq。在一个新的空目录内,依次运行本页命令;每个新任务单独用一个目录,以免混用任务 ID 或覆盖成品。在控制台创建有相应模型权限、分组和余额的 API Key,不要使用工作台登录令牌。

bash
export ABU_API_ORIGIN="https://api.abuai.chat"  # 自建部署改为根地址,不带 /v1 或末尾 /
read -rsp '输入 API Key:' ABU_API_KEY; printf '\n'

准备一个已成功的来源任务 ID(例如首次生成时 suno-id.txt 的内容),用原任务所属用户和组织的 API Key。下面会查询原任务,列出曲目供选择;有多首歌时不要仅凭标题手填 ID。也支持从 UPLOAD 的单个结果对象选取素材。

bash
choose_source() (
  set -e
  read -rp '来源任务 ID:' source_id
  path=$(jq -ner --arg id "$source_id" '$id | select(length > 0) | @uri')
  curl -sS --fail-with-body --max-time 30 "$ABU_API_ORIGIN/suno/fetch/$path" \
    -H "Authorization: Bearer ${ABU_API_KEY:?请先输入 API Key}" -o source.json || { cat source.json >&2; exit 1; }
  songs=$(jq -ce 'if .code == "success" and .data.status == "SUCCESS" then
    .data.data | if type == "array" then . else [.] end |
    map(select(.music_id | strings | length > 0)) | select(length > 0)
    else error(tostring) end' source.json)
  jq -r 'to_entries[] | [.key+1, (.value.title // "未命名"), .value.music_id] | @tsv' <<<"$songs" >&2
  read -rp '选择第几首(输入上面列出的序号):' n
  [[ "$n" =~ ^[1-9][0-9]*$ ]] || exit 1
  jq -en --arg task "$source_id" --argjson songs "$songs" --argjson n "$n" \
    '$songs[$n-1].music_id | strings | select(length > 0) | {task_id:$task, music_id:.}'
)
bash
source_ref=$(choose_source)

选中的 source_ref 只含 task_id 和对应的 music_id。如果没有列出曲目,先检查来源任务是否成功、是否属于当前身份,以及结果是否有 music_id。旧代理生成的作品如果没有平台渠道绑定,也不能用作这些动作的来源。

2. 设置歌曲续写参数 ​

字段怎么填
task_id、music_id使用第 1 步选出的原任务和曲目;不要传旧代理的 continue_clip_id
continue_at必填,JSON 数字,单位秒且大于 0。填原曲中的起点,不是要追加的时长;请先试听,选择原曲时长以内的位置
custom、提示词自写新段歌词用 custom:true 和 prompt;描述续写方向用 custom:false 和非空 gpt_description_prompt
title、tags、duration、audio_format可选标题、风格、目标时长(10~360 整数秒)、格式(mp3 / m4a / wav)。EXTEND 不转发 mv、model_id 或 instrumental

示例假定原曲长于 30 秒,在第 30 秒进入副歌。

bash
jq -en --argjson src "${source_ref:?请先选择来源曲目}" \
  '$src + {continue_at:30, custom:true, prompt:"[Chorus]\n海上的灯,陪我回航", tags:"acoustic folk", audio_format:"mp3"}' > request.json

3. 提交、查询并保存成品 ​

以下函数在当前 Bash 会话中使用。提交只运行一次;函数会把新任务 ID 存入 suno-id.txt。若提交超时且没有收到 ID,先核对平台调用记录,不要自动重发。

bash
submit_suno() (
  set -e
  if [[ -e suno-id.txt || -e submit.json ]]; then
    echo '本目录已有提交记录。请先查原任务;新任务另建目录。' >&2; exit 1
  fi
  jq -es 'length == 1 and (.[0] | type == "object" and length > 0)' request.json >/dev/null || exit 1
  curl -sS --fail-with-body --max-time 120 "$ABU_API_ORIGIN/suno/submit/$1" \
    -H "Authorization: Bearer ${ABU_API_KEY:?请先输入 API Key}" \
    -H 'Content-Type: application/json' --data-binary @request.json -o submit.json || { cat submit.json >&2; exit 1; }
  id=$(jq -er 'if .code == "success" then (.data | strings | select(length > 0)) else error(tostring) end' submit.json) || exit 1
  printf '%s\n' "$id" | tee suno-id.txt
)

wait_suno() (
  set -e
  id=$(jq -Rer 'select(length > 0) | @uri' suno-id.txt) || exit 1
  deadline=$((SECONDS + 1200))
  while (( SECONDS < deadline )); do
    curl -sS --fail-with-body --max-time 30 "$ABU_API_ORIGIN/suno/fetch/$id" \
      -H "Authorization: Bearer ${ABU_API_KEY:?请先输入 API Key}" -o status.json || { cat status.json >&2; exit 1; }
    state=$(jq -er 'if .code == "success" then .data.status else error(tostring) end' status.json)
    printf '状态:%s\n' "$state"
    case "$state" in
      SUCCESS) exit 0 ;;
      FAILURE) jq -r '.data.fail_reason // .data' status.json >&2; exit 1 ;;
      NOT_START|SUBMITTED|QUEUED|IN_PROGRESS) sleep 5 ;;
      *) cat status.json >&2; exit 1 ;;
    esac
  done
  echo '本地等待超时;保留任务 ID,稍后只运行 wait_suno。' >&2; exit 1
)

save_audio() (
  set -e
  ext=$(jq -er '.audio_format // "mp3" | select(. == "mp3" or . == "wav" or . == "m4a")' request.json) || exit 1
  count=$(jq -er 'select(.code == "success" and .data.status == "SUCCESS") | .data.data | arrays | length | select(. > 0)' status.json) || { echo '成功结果没有音频数组,请检查 status.json。' >&2; exit 1; }
  for ((i=0; i<count; i++)); do
    url=$(jq -er --argjson i "$i" '.data.data[$i].audio_url | strings | select(startswith("https://"))' status.json) || exit 1
    label=$(jq -r --argjson i "$i" '.data.data[$i] | .stem_type // .title // .music_id // "音频"' status.json)
    file="audio-$((i+1)).$ext"
    curl -fsSL --proto '=https' --max-time 300 "$url" -o "$file.part" || exit 1
    test -s "$file.part" && mv "$file.part" "$file" || exit 1
    printf '%s → %s\n' "$file" "$label"
  done
)

查询成功看 data.status == "SUCCESS",外层 code == "success" 仅表示查询成功。歌曲或分轨的链接在 data.data[].audio_url;下载媒体时不发送 API Key。下载中断只重跑 save_audio,原始结果和每首歌的 ID 保留在 status.json。

运行本场景的动作:

bash
submit_suno EXTEND && wait_suno && save_audio

本目录的 audio-1.mp3 等是本次返回的续写音频。需要完整歌曲时,另建任务引用刚才的续写任务及其中一个片段,不是最初的原曲。下例选第一个片段,成功后完整歌曲在 full-song/audio-1.mp3 等文件中。

bash
(
  set -e
  mkdir full-song
  cd full-song
  jq -e 'select(.code == "success" and .data.status == "SUCCESS") | .data |
    {task_id, music_id:.data[0].music_id, audio_format:"mp3"} |
    select([.task_id,.music_id] | all(type == "string" and length > 0))' ../status.json > request.json
  submit_suno CONCAT
  wait_suno
  save_audio
)

拼接已提交但等待中断时,进入已有的 full-song 目录,只运行 wait_suno && save_audio。

AbuAI - 让 AI 触手可及