Suno Timing API 串接說明

SUNO 允許我們對生成的音樂進行二次創作,取得音樂的歌詞、音訊時間軸,本文說明相關 API 的串接方法。

data.aligned_words 回傳逐詞的對齊時間。以本頁實測回應中的前三個詞為例。

詞 開始(秒) 結束(秒)
Window 13.097 13.727
lights 13.91583 14.86
across 14.99667 15.7

該 API 只有一個輸入參數,就是 audio_id,它是官方生成的歌曲 ID。

這裡輸入的 audio_id 是 3f8c1800-7a96-4a2b-811f-5fee716a9e32。

import os

import requests

url = "https://api.acedata.cloud/suno/timing"
headers = {
    "accept": "application/json",
    "authorization": f"Bearer {os.environ['API_KEY']}",
    "content-type": "application/json",
}
payload = {
    "audio_id": "3f8c1800-7a96-4a2b-811f-5fee716a9e32",
}

response = requests.post(url, json=payload, headers=headers, timeout=180)
print(response.text)

結果節錄如下:

{
  "success": true,
  "task_id": "192b701b-8050-40f4-960c-29b54fd4822a",
  "trace_id": "b177ad51-617a-452a-a4ff-1115e8d2b347",
  "data": {
    "aligned_words": [
      {
        "word": "[Verse]\nWindow ",
        "success": true,
        "start_s": 13.097,
        "end_s": 13.727,
        "p_align": 0.99
      },
      {
        "word": "lights ",
        "success": true,
        "start_s": 13.91583,
        "end_s": 14.86,
        "p_align": 0.99
      },
      {
        "word": "across ",
        "success": true,
        "start_s": 14.99667,
        "end_s": 15.7,
        "p_align": 0.99
      },
      {
        "word": "the ",
        "success": true,
        "start_s": 15.78,
        "end_s": 15.948,
        "p_align": 0.99
      }
    ],
    "waveform_data": [
      0.14492,
      0.20651,
      0.1787
    ],
    "hoot_cer": 0.15671641791044777,
    "is_streamed": false,
    "aligned_lyrics": [
      {
        "text": "Window lights across the bay",
        "start_s": 13.097,
        "end_s": 16.188,
        "section": "Verse",
        "words": [
          {
            "text": "Window",
            "start_s": 13.097,
            "end_s": 13.727
          },
          {
            "text": " lights",
            "start_s": 13.727,
            "end_s": 14.86
          },
          {
            "text": " across",
            "start_s": 14.86,
            "end_s": 15.68
          },
          {
            "text": " the",
            "start_s": 15.7,
            "end_s": 15.94
          },
          {
            "text": " bay",
            "start_s": 15.948,
            "end_s": 16.188
          }
        ]
      },
      {
        "text": "Guide the boats that drift away",
        "start_s": 19.397,
        "end_s": 22.631,
        "section": "Verse",
        "words": [
          {
            "text": "Guide",
            "start_s": 19.397,
            "end_s": 19.789
          },
          {
            "text": " the",
            "start_s": 19.789,
            "end_s": 19.98
          },
          {
            "text": " bo",
            "start_s": 19.98,
            "end_s": 20.092
          },
          {
            "text": "ats",
            "start_s": 20.092,
            "end_s": 20.653
          },
          {
            "text": " that",
            "start_s": 20.689,
            "end_s": 21.063
          },
          {
            "text": " drift",
            "start_s": 21.22,
            "end_s": 22.07
          },
          {
            "text": " away",
            "start_s": 22.07,
            "end_s": 22.631
          }
        ]
      }
    ]
  }
}

aligned_words 欄位說明

可以看到,data.aligned_words 是物件陣列,每個物件代表一個帶有時間資訊的詞或片語。

  • word: 歌詞中的實際詞或片語
  • success: 布林值,表示此詞的對齊是否成功
  • start_s: 詞的開始時間
  • end_s: 詞的結束時間
  • p_align: 對齊的機率或信心分數,範圍為 0 到 1

data.aligned_lyrics 提供行與詞的時間,可用於捲動歌詞。waveform_data 為波形取樣。選取替換片段時,可以讀取對齊時間並試聽原曲核對。