Skip to content

Suno 母带处理、变速与文件导出 ​

以下动作都从一首已完成的作品开始,可以单独运行。按需开通 suno_remaster、suno_adjust_speed、suno_download 或 suno_gen_midi。只想保存生成时已有的音频,用原结果的 audio_url 即可,不必额外提交导出。

开始前 ​

请在服务端用 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'

先展开下面的代码,在同一个 Bash 会话中运行一次。每个示例都会新建独立任务目录,不会覆盖已有任务。等待中断时进入该任务目录运行 wait_suno,成功后只重跑保存结果的命令,不要重新提交。

提交、轮询和下载函数(先运行)

以下函数在当前 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。

需要选择已有曲目时,下面的函数按任务 ID 查回成功结果,再让你按序号选作品。请使用原用户和组织的 Key;返回的是匹配的 task_id 和 music_id。在当前会话中先运行函数定义。

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:.}'
)

重制母带或调整速度 ​

REMASTER 可选 variation_category:subtle、normal 或 high。ADJUST_SPEED 必填新 title;speed_multiplier 为 0.25~4 的数字,keep_pitch 为布尔值。变速动作不接收 audio_format。

bash
(
  set -e
  mkdir processed
  cd processed
  action=REMASTER
  ref=$(choose_source)
  case "$action" in
    REMASTER) options='{"variation_category":"subtle","audio_format":"mp3"}' ;;
    ADJUST_SPEED) options='{"title":"夜航 · 加速版","speed_multiplier":1.15,"keep_pitch":true}' ;;
    *) exit 1 ;;
  esac
  jq -en --argjson ref "$ref" --argjson opts "$options" '$ref + $opts' > request.json
  submit_suno "$action"
  wait_suno
  save_audio
)

导出所选格式 ​

DOWNLOAD 接受 formats 数组,选 1~3 种:mp3、m4a、wav。成功返回 data.data.files[],每项有 format 和 file_url。下面保存每个返回的文件,不用普通歌曲的 audio_url。

bash
(
  set -e
  mkdir export
  cd export
  ref=$(choose_source)
  jq -en --argjson ref "$ref" '$ref + {"formats":["mp3","wav"]}' > request.json
  submit_suno DOWNLOAD
  wait_suno
  count=$(jq -er '.data.data.files | arrays | length | select(.>0)' status.json)
  for ((i=0; i<count; i++)); do
    ext=$(jq -er --argjson i "$i" '.data.data.files[$i].format | select(.=="mp3" or .=="wav" or .=="m4a")' status.json)
    url=$(jq -er --argjson i "$i" '.data.data.files[$i].file_url | strings | select(startswith("https://"))' status.json)
    file="song-$((i+1)).$ext"
    curl -fsSL --proto '=https' --max-time 300 "$url" -o "$file.part"
    test -s "$file.part"
    mv "$file.part" "$file"
  done
)

保存 MIDI 乐器文件 ​

GEN_MIDI 只需原曲引用,没有 formats 参数。它返回 data.data.instruments[],每件乐器的文件地址是 midi_url。不要把 JSON 或 MP3 改扩展名当作 MIDI。

bash
(
  set -e
  mkdir midi
  cd midi
  choose_source > request.json
  submit_suno GEN_MIDI
  wait_suno
  count=$(jq -er '.data.data.instruments | arrays | length | select(.>0)' status.json)
  for ((i=0; i<count; i++)); do
    url=$(jq -er --argjson i "$i" '.data.data.instruments[$i].midi_url | strings | select(startswith("https://"))' status.json)
    file="instrument-$((i+1)).mid"
    curl -fsSL --proto '=https' --max-time 300 "$url" -o "$file.part"
    test -s "$file.part"
    mv "$file.part" "$file"
  done
)

成品分别保存在 processed/、export/ 或 midi/。两个导出示例只向媒体链接发送下载请求,不带平台密钥;下载中断时在原目录用 status.json 重跑下载部分即可。

AbuAI - 让 AI 触手可及