Suno 歌曲生成 API

AceData:一站式AI创意工坊提供一站式的 AI 服务,包括问答、绘画、二维码、音乐等多种功能同时提供多样化API平台调用,满足你的多样化需求。新用户赠送免费使用积分,帮助您轻松创作!

随着 AI 的应用变广,各类 AI 程序已逐渐普及。AI 已逐渐深入到人们的工作生活方方面面。而 AI 涉及的行业也越来越多,从最初的写作,到医疗教育,再到现在的音乐。

Suno 是一个专业高质量的 AI 歌曲和音乐创作平台,用户只需输入简单的文本提示词,即可根据流派风格和歌词生成带有人声的歌曲。该 AI 音乐生成器由来自 Meta、TikTok、Kensho 等知名科技公司的团队成员开发,目标是不需要任何乐器工具,让所有人都可以创造美妙的音乐。

Suno 最新已将音乐生成模型升级到 V3 版本,可生成 2 分钟的歌曲。

然而 Suno 官方是并没有提供 API 的,AceDataCloud 提供了一套 Suno 的 API,模拟对接了 Suno 官方,可以方便快捷地生成想要的音乐。

申请和使用

要使用 Suno Audios API,首先可以到 Suno Audios Generation API 页面点击「Acquire」按钮,获取请求所需要的凭证:

如果你尚未登录或注册,会自动跳转到登录页面邀请您来注册和登录,登录注册之后会自动返回当前页面。

在首次申请时会有免费额度赠送,可以免费使用该 API。

基本使用

想些什么歌曲,可以任意输入一段文字,比如我想生成一个关于圣诞的歌曲,就可以输入 a song for Christmas,如图所示:

生成的代码如下:

可以点击「Try」按钮直接测试 API,稍等 1-2 分钟,结果如下:

{
  "success": true,
  "data": [
    {
      "state": "succeeded",
      "id": "2f16f7bc-4135-42c6-b3c5-6d6c49dc8cd5",
      "title": "Winter Wonderland",
      "image_url": "https://cdn1.suno.ai/image_2f16f7bc-4135-42c6-b3c5-6d6c49dc8cd5.png",
      "lyric": "[Verse]\nSnowflakes falling all around\nGlistening white\nCovering the ground\nChildren laughing\nFull of delight\nIn this winter wonderland tonight\nSanta's sleigh\nUp in the sky\nRudolph's nose shining bright\nOh my\nHear the jingle bells\nRinging so clear\nBringing joy and holiday cheer\n[Verse 2]\nRoasting chestnuts by the fire's glow\nChristmas lights\nThey twinkle and show\nFamilies gathering with love and cheer\nSpreading warmth to everyone near",
      "audio_url": "https://cdn1.suno.ai/2f16f7bc-4135-42c6-b3c5-6d6c49dc8cd5.mp3",
      "video_url": "https://cdn1.suno.ai/2f16f7bc-4135-42c6-b3c5-6d6c49dc8cd5.mp4",
      "created_at": "2024-05-10T16:21:37.624Z",
      "model": "chirp-v3",
      "prompt": "A song for Christmas",
      "style": "holiday"
    },
    {
      "state": "succeeded",
      "id": "5dca232b-17cc-4896-a2d1-4b59178bf410",
      "title": "Winter Wonderland",
      "image_url": "https://cdn1.suno.ai/image_5dca232b-17cc-4896-a2d1-4b59178bf410.png",
      "lyric": "[Verse]\nSnowflakes falling all around\nGlistening white\nCovering the ground\nChildren laughing\nFull of delight\nIn this winter wonderland tonight\nSanta's sleigh\nUp in the sky\nRudolph's nose shining bright\nOh my\nHear the jingle bells\nRinging so clear\nBringing joy and holiday cheer\n[Verse 2]\nRoasting chestnuts by the fire's glow\nChristmas lights\nThey twinkle and show\nFamilies gathering with love and cheer\nSpreading warmth to everyone near",
      "audio_url": "https://cdn1.suno.ai/5dca232b-17cc-4896-a2d1-4b59178bf410.mp3",
      "video_url": "https://cdn1.suno.ai/5dca232b-17cc-4896-a2d1-4b59178bf410.mp4",
      "created_at": "2024-05-10T16:21:37.624Z",
      "model": "chirp-v3",
      "prompt": "A song for Christmas",
      "style": "holiday"
    }
  ]
}

可以看到这时候我们就得到了两首歌的内容,包括标题、预览图、歌词、音频、视频等内容。

字段说明如下:

  • success:生成是否成功,如果成功则为 true,否则为 false
  • data:是一个列表,包含了生成的歌曲的详细信息。
    • state: 歌曲生成状态,主要包含四种,具体的如下:
      • succeeded:生成成功
      • pending:队列中
      • running:执行中
      • error:失败
    • id:歌曲 ID
    • title:歌曲的标题
    • image_url:歌曲的封面图片
    • lyric:歌曲的歌词
    • audio_url:歌曲的音频文件,打开就是一个 mp3 音频。
    • video_url:歌曲的视频文件,打开就是一个 mp4 视频。
    • created_at:创建的时间
    • model:使用的模型,一般是最新的 v3 模型
    • style:风格

自定义生成

如果想自定义生成歌词,可以输入歌词:

这时候 lyric 字段可以传入类似如下内容:

[Verse]\nSnowflakes falling all around\nGlistening white\nCovering the ground\nChildren laughing\nFull of delight\nIn this winter wonderland tonight\nSanta's sleigh\nUp in the sky\nRudolph's nose shining bright\nOh my\nHear the jingle bells\nRinging so clear\nBringing joy and holiday cheer\n[Verse 2]\nRoasting chestnuts by the fire's glow\nChristmas lights\nThey twinkle and show\nFamilies gathering with love and cheer\nSpreading warmth to everyone near

注意,这里的歌词中 \n 是换行符,如果你不知道如何生成歌词,可以使用 AceDataCloud 提供的歌词生成 API 来通过 prompt 生成歌词,API 是 Suno Lyrics Generation API

接下来我们要根据歌词、标题、风格自定义生成歌曲,就可以指定如下内容:

  • lyric:歌词文本
  • custom:填写为 true,代表自定义生成,该参数默认为 false,代表使用 prompt 生成。
  • file:歌曲的标题。
  • style:歌曲的风格,选填。

填写样例如下:

填写完毕之后自动生成了代码如下:

对应的代码:

curl -X POST 'https://api.acedata.cloud/suno/audios' \
-H 'authorization: Bearer {token}' \
-H 'accept: application/json' \
-H 'content-type: application/json' \
-d '{
"lyric": "[Verse]\\nSnowflakes falling all around\\nGlistening white\\nCovering the ground\\nChildren laughing\\nFull of delight\\nIn this winter wonderland tonight\\nSanta's sleigh\\nUp in the sky\\nRudolph's nose shining bright\\nOh my\\nHear the jingle bells\\nRinging so clear\\nBringing joy and holiday cheer\\n[Verse 2]\\nRoasting chestnuts by the fire's glow\\nChristmas lights\\nThey twinkle and show\\nFamilies gathering with love and cheer\\nSpreading warmth to everyone near",
"custom": true
}'

测试允许,生成的效果是类似的。

自定义歌手风格生成功能

如果想使用歌手风格来生成歌曲的话,首先通过上文的基本使用生成一首歌曲,
具体的参数如下图所示:

填写完毕之后自动生成了代码如下:

对应的 Python 代码:

import requests

url = "https://api.acedata.cloud/suno/audios"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "action": "generate",
    "prompt": "A song for Christmas",
    "model": "chirp-v4"
}

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

点击运行,可以发现会得到一个结果,如下:

{
  "success": true,
  "task_id": "04067c0f-6655-44b6-8c4f-f443af573ebf",
  "trace_id": "c0a574b6-d5b1-4ddc-9529-b1a3d502a7e9",
  "data": [
    {
      "id": "8bc267d2-9794-412c-a504-974ce3cba254",
      "title": "Jingle All the Way",
      "image_url": "https://cdn2.suno.ai/image_8bc267d2-9794-412c-a504-974ce3cba254.jpeg",
      "lyric": "[Verse]\nSnowflakes dancing in the street\nWarm cocoa can't be beat\nNeighbours laugh as carolers sing\nJoyful bells begin to ring\n[Verse 2]\nCandy canes and mistletoe\nSparkling lights that gleam and glow\nWrinkled paper ribbons flying\nSmiling faces never lying\n[Chorus]\nJingle all the way tonight\nStars above are shining bright\nGifts of laughter love and cheer\nMaking memories so dear\n[Verse 3]\nStockings hanging by the fire\nEvery heart is full of desire\nSilent wishes whispered low\nUnderneath the mistletoe\n[Bridge]\nChildren dreaming of delight\nSanta's sleigh takes flight tonight\nMagic sparkles in the air\nChristmas wonder everywhere\n[Verse 4]\nWrapping presents with a bow\nFeeling love in every show\nFamily gathered round the tree\nHoliday spirit wild and free",
      "audio_url": "https://cdn1.suno.ai/8bc267d2-9794-412c-a504-974ce3cba254.mp3",
      "video_url": "https://cdn1.suno.ai/8bc267d2-9794-412c-a504-974ce3cba254.mp4",
      "created_at": "2025-01-04T03:26:59.710Z",
      "model": "chirp-v4",
      "state": "succeeded",
      "prompt": "A song for Christmas",
      "style": "pop",
      "duration": 181.56
    },
    {
      "id": "8ebdcf48-1d4d-4b8a-94bc-ec46a793f590",
      "title": "Jingle All the Way",
      "image_url": "https://cdn2.suno.ai/image_8ebdcf48-1d4d-4b8a-94bc-ec46a793f590.jpeg",
      "lyric": "[Verse]\nSnowflakes dancing in the street\nWarm cocoa can't be beat\nNeighbours laugh as carolers sing\nJoyful bells begin to ring\n[Verse 2]\nCandy canes and mistletoe\nSparkling lights that gleam and glow\nWrinkled paper ribbons flying\nSmiling faces never lying\n[Chorus]\nJingle all the way tonight\nStars above are shining bright\nGifts of laughter love and cheer\nMaking memories so dear\n[Verse 3]\nStockings hanging by the fire\nEvery heart is full of desire\nSilent wishes whispered low\nUnderneath the mistletoe\n[Bridge]\nChildren dreaming of delight\nSanta's sleigh takes flight tonight\nMagic sparkles in the air\nChristmas wonder everywhere\n[Verse 4]\nWrapping presents with a bow\nFeeling love in every show\nFamily gathered round the tree\nHoliday spirit wild and free",
      "audio_url": "https://cdn1.suno.ai/8ebdcf48-1d4d-4b8a-94bc-ec46a793f590.mp3",
      "video_url": "https://cdn1.suno.ai/8ebdcf48-1d4d-4b8a-94bc-ec46a793f590.mp4",
      "created_at": "2025-01-04T03:26:59.710Z",
      "model": "chirp-v4",
      "state": "succeeded",
      "prompt": "A song for Christmas",
      "style": "pop",
      "duration": 203.8
    }
  ]
}

最后得到了需要设置这个歌曲为歌手风格,然后需要进入Suno Persona API根据官方生成的音乐ID audio_id 来生成一个歌手风格的id参数 persona_id,具体的参数如下图所示:

填写完毕之后自动生成了代码如下:

对应的 Python 代码:

import requests

url = "https://api.acedata.cloud/suno/persona"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "name": "Christmas",
    "audio_id": "8bc267d2-9794-412c-a504-974ce3cba254"
}

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

点击运行,可以发现会得到一个结果,如下:

{
  "success": true,
  "task_id": "807dde07-ca91-4a51-ba45-d3b3f12f6a54",
  "data": {
    "persona_id": "194a0114-3705-4bd2-b975-abc20fec77f3"
  }
}

我们以上面的 audio_idpersona_id 分别为 8bc267d2-9794-412c-a504-974ce3cba254194a0114-3705-4bd2-b975-abc20fec77f3 为此次的示例数据。 然后可以将参数 action 设置为 artist_consistency ,并且输入需要继续生成歌曲的 ID 、 歌手风格ID,填写样例如下:

填写完毕之后自动生成了代码如下:

对应的 Python 代码:

import requests

url = "https://api.acedata.cloud/suno/audios"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "action": "artist_consistency",
    "prompt": "A song for Christmas",
    "model": "chirp-v4",
    "custom": True,
    "audio_id": "8bc267d2-9794-412c-a504-974ce3cba254",
    "persona_id": "194a0114-3705-4bd2-b975-abc20fec77f3",
    "lyric": "[Verse]\\nSnowflakes dancing in the street\\nWarm cocoa can't be beat\\nNeighbours laugh as carolers sing\\nJoyful bells begin to ring\\n[Verse 2]\\nCandy canes and mistletoe\\nSparkling lights that gleam and glow\\nWrinkled paper ribbons flying\\nSmiling faces never lying\\n[Chorus]\\nJingle all the way tonight\\nStars above are shining bright\\nGifts of laughter love and cheer\\nMaking memories so dear\\n[Verse 3]\\nStockings hanging by the fire\\nEvery heart is full of desire\\nSilent wishes whispered low\\nUnderneath the mistletoe\\n[Bridge]\\nChildren dreaming of delight\\nSanta's sleigh takes flight tonight\\nMagic sparkles in the air\\nChristmas wonder everywhere\\n[Verse 4]\\nWrapping presents with a bow\\nFeeling love in every show\\nFamily gathered round the tree\\nHoliday spirit wild and free"
}

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

点击运行,可以发现会得到一个结果,如下:

{
  "success": true,
  "task_id": "77fd7f95-9f75-4f5f-8c7a-4d78d284ef54",
  "trace_id": "f34b8b11-2839-48ea-b4e6-5525cb74d72f",
  "data": [
    {
      "id": "8b730866-dc0b-436e-aeee-d703a46c8187",
      "title": "",
      "image_url": "https://cdn2.suno.ai/image_8b730866-dc0b-436e-aeee-d703a46c8187.jpeg",
      "lyric": "[Verse]\\nSnowflakes dancing in the street\\nWarm cocoa can't be beat\\nNeighbours laugh as carolers sing\\nJoyful bells begin to ring\\n[Verse 2]\\nCandy canes and mistletoe\\nSparkling lights that gleam and glow\\nWrinkled paper ribbons flying\\nSmiling faces never lying\\n[Chorus]\\nJingle all the way tonight\\nStars above are shining bright\\nGifts of laughter love and cheer\\nMaking memories so dear\\n[Verse 3]\\nStockings hanging by the fire\\nEvery heart is full of desire\\nSilent wishes whispered low\\nUnderneath the mistletoe\\n[Bridge]\\nChildren dreaming of delight\\nSanta's sleigh takes flight tonight\\nMagic sparkles in the air\\nChristmas wonder everywhere\\n[Verse 4]\\nWrapping presents with a bow\\nFeeling love in every show\\nFamily gathered round the tree\\nHoliday spirit wild and free",
      "audio_url": "https://cdn1.suno.ai/8b730866-dc0b-436e-aeee-d703a46c8187.mp3",
      "video_url": "https://cdn1.suno.ai/8b730866-dc0b-436e-aeee-d703a46c8187.mp4",
      "created_at": "2025-01-04T03:54:22.060Z",
      "model": "chirp-v4",
      "state": "succeeded",
      "style": "",
      "duration": 120.28
    },
    {
      "id": "13cff259-a8f2-4729-ba1b-3dc48e92f18a",
      "title": "",
      "image_url": "https://cdn2.suno.ai/image_13cff259-a8f2-4729-ba1b-3dc48e92f18a.jpeg",
      "lyric": "[Verse]\\nSnowflakes dancing in the street\\nWarm cocoa can't be beat\\nNeighbours laugh as carolers sing\\nJoyful bells begin to ring\\n[Verse 2]\\nCandy canes and mistletoe\\nSparkling lights that gleam and glow\\nWrinkled paper ribbons flying\\nSmiling faces never lying\\n[Chorus]\\nJingle all the way tonight\\nStars above are shining bright\\nGifts of laughter love and cheer\\nMaking memories so dear\\n[Verse 3]\\nStockings hanging by the fire\\nEvery heart is full of desire\\nSilent wishes whispered low\\nUnderneath the mistletoe\\n[Bridge]\\nChildren dreaming of delight\\nSanta's sleigh takes flight tonight\\nMagic sparkles in the air\\nChristmas wonder everywhere\\n[Verse 4]\\nWrapping presents with a bow\\nFeeling love in every show\\nFamily gathered round the tree\\nHoliday spirit wild and free",
      "audio_url": "https://cdn1.suno.ai/13cff259-a8f2-4729-ba1b-3dc48e92f18a.mp3",
      "video_url": "https://cdn1.suno.ai/13cff259-a8f2-4729-ba1b-3dc48e92f18a.mp4",
      "created_at": "2025-01-04T03:54:22.060Z",
      "model": "chirp-v4",
      "state": "succeeded",
      "style": "",
      "duration": 120.44
    }
  ]
}

可以看出,结果内容与上文的是一致的,这也就实现使用歌手风格来生成歌曲的功能。

继续生成功能

如果想对已经生成的Suno歌曲进行继续生成的话,可以将参数 action 设置为 extend ,并且输入需要继续生成歌曲的 ID,歌曲 ID 的获取是根据基本使用来获取,如下图所示:

这时候可以看到歌曲的 ID 为:

"id": "b9e9fa11-0bf3-47cd-a3d7-85735aee3e07"

注意,这里的歌词中 id 是生成后歌曲的 ID,如果你不知道如何生成歌曲,可以参考上文的基本使用来生成歌曲。

如果想对自己上传的歌曲进行继续生成的话,可以将参数 action 设置为 upload_extend ,并且输入需要继续生成自定义上传的歌曲 ID,歌曲 ID 的获取是使用 Suno Upload Generation API来获取,如下图所示:

接下来我们要必须填歌词、风格自定义生成歌曲,就可以指定如下内容:

  • lyric:歌词文本
  • custom:填写为 true,代表自定义生成,该参数默认为 false,代表使用 prompt 生成。
  • style:歌曲的风格,选填。
  • continue_at:以秒为单位继续现有音频的时间。例如,213.5 表示继续到 3 分 33.5 秒。

填写样例如下:

填写完毕之后自动生成了代码如下:

对应的 Python 代码:

import requests

url = "https://api.acedata.cloud/suno/audios"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "action": "extend",
    "prompt": "A song for Christmas",
    "audio_id": "b9e9fa11-0bf3-47cd-a3d7-85735aee3e07",
    "continue_at": 10,
    "style": "cute",
    "lyric": "la la la"
}

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

点击运行,可以发现会得到一个结果,如下:

{
  "success": true,
  "task_id": "baf55c32-1207-4bdf-bd00-32a864f0474d",
  "data": [
    {
      "id": "5a3d0054-a6c5-43a9-a348-eae22d1f0efe",
      "title": "",
      "image_url": "https://cdn2.suno.ai/image_5a3d0054-a6c5-43a9-a348-eae22d1f0efe.jpeg",
      "lyric": "la la la",
      "audio_url": "https://cdn1.suno.ai/5a3d0054-a6c5-43a9-a348-eae22d1f0efe.mp3",
      "video_url": "https://cdn1.suno.ai/5a3d0054-a6c5-43a9-a348-eae22d1f0efe.mp4",
      "created_at": "2024-07-25T11:15:49.320Z",
      "model": "chirp-v3.5",
      "prompt": null,
      "style": "cute",
      "duration": 7.96
    },
    {
      "id": "9ae90c96-adcf-4aad-a591-361485168f13",
      "title": "",
      "image_url": "https://cdn2.suno.ai/image_9ae90c96-adcf-4aad-a591-361485168f13.jpeg",
      "lyric": "la la la",
      "audio_url": "https://cdn1.suno.ai/9ae90c96-adcf-4aad-a591-361485168f13.mp3",
      "video_url": "https://cdn1.suno.ai/9ae90c96-adcf-4aad-a591-361485168f13.mp4",
      "created_at": "2024-07-25T11:15:49.321Z",
      "model": "chirp-v3.5",
      "prompt": null,
      "style": "cute",
      "duration": 4.2
    }
  ]
}

可以看出,结果内容与上文的是一致的,这也就实现歌曲的继续生成功能。

获取完整歌曲

当基于原有的歌曲继续生成歌曲之后,返回的歌曲并不包含原来的歌曲内容。如果要获得完整的歌曲内容,需要使用拼接功能,就可以指定如下内容:

  • action:内容为 concat
  • audio_id:最后一个片段的 ID。

比如扩展后的歌曲 ID 是:0550d2ea-1e2e-4800-a163-60f172c0b51e,那么可以设置参数如下:

{
  "action": "concat",
  "audio_id": "0550d2ea-1e2e-4800-a163-60f172c0b51e"
}

其他参数不变,返回的就是一首完整的歌曲,就是所有歌曲片段的拼接结果,但结果只有一首歌,样例如下:

{
  "success": true,
  "data": [
    {
      "state": "succeeded",
      "id": "b7cc1054-4ecf-4fb3-a711-ec25f8878ac7",
      "title": "Piggy Dreams",
      "image_url": "https://cdn2.suno.ai/image_0550d2ea-1e2e-4800-a163-60f172c0b51e.jpeg",
      "lyric": "[Verse]\nSaw a pig with dreams today\nDancing in the mud and hay\nSnorting tunes in his own way\nLiving large in piggy sway\n\n[Verse 2]\nOinking songs from dawn to dusk\nRolling round in rustic musk\nDreaming big without no fuss\nPiggy life’s a simple trust\n\n[Chorus]\nPiggy dreams you can’t suppress\nDancing round in muddy dress\nLiving life without the stress\nIn their world they’re truly blessed\n\n[Verse 3]\nApple cores and pumpkin pie\nPigs don’t need a reason why\nEvery day just to defy\nAny doubt that they can\"t fly\n\n[Bridge]\nThrough the fields they trotter free\nUnderneath the apple tree\nDreamin\" of what they could be\nPiggy dreams wild and carefree\n\n[Chorus]\nPiggy dreams you can’t suppress\nDancing round in muddy dress\nLiving life without the stress\nIn their world they’re truly blessed\n\n[Verse]\nA big pig dancing[Verse 2]\nOinking songs from dawn to dusk\nRolling round in rustic musk\nDreaming big without no fuss\nPiggy life’s a simple trust\n\n[Chorus]\nPiggy dreams you can’t suppress\nDancing round in muddy dress\nLiving life without the stress\nIn their world they’re truly blessed",
      "audio_url": "https://cdn1.suno.ai/b7cc1054-4ecf-4fb3-a711-ec25f8878ac7.mp3",
      "video_url": "https://cdn1.suno.ai/b7cc1054-4ecf-4fb3-a711-ec25f8878ac7.mp4",
      "created_at": "2024-12-08T15:50:00.105Z",
      "model": null,
      "prompt": null,
      "style": null,
      "duration": 259
    }
  ],
  "task_id": "394f3ff7-d952-4dbc-901e-9248d4d5ecf5"
}

音乐翻版

当基于原有的歌曲继续生成歌曲之后,返回的歌曲的风格可能不太合适。如果要对原先生成的歌曲(若是自定义上传的音乐也支持)进行翻版,需要使用音乐翻版方法,就可以指定如下内容:

  • action:内容为 cover,当是对自定义上传的音乐进行翻版操作的时候必须指定内容为:upload_cover
  • audio_id:之前生成歌曲的 ID。

比如原先生成后的歌曲 ID 是:e0347cce-97f7-4a1c-84c4-d59246428241,那么可以设置参数如下:

{
  "action": "cover",
  "lyric":"girl girl girl",
  "style": "rock, punk",
  "model": "chirp-v4-tau",
  "audio_id": "e0347cce-97f7-4a1c-84c4-d59246428241"
}

其他参数不变,返回的就是一首翻版后的歌曲,就是对原先生成的歌曲进行翻版后的结果,样例如下:

{
    "success": true,
    "task_id": "87d0de46-8976-4e26-a28d-4d83211f8e26",
    "trace_id": "b0375262-5c96-4b13-b80a-df5dc5f16ad2",
    "data": [
        {
            "id": "d1df73a1-38f3-4405-bbdc-f0a433c19dc7",
            "title": "",
            "image_url": "https://cdn2.suno.ai/image_d1df73a1-38f3-4405-bbdc-f0a433c19dc7.jpeg",
            "lyric": "girl girl girl",
            "audio_url": "https://cdn1.suno.ai/d1df73a1-38f3-4405-bbdc-f0a433c19dc7.mp3",
            "video_url": "https://cdn1.suno.ai/d1df73a1-38f3-4405-bbdc-f0a433c19dc7.mp4",
            "created_at": "2024-12-22T03:50:50.822Z",
            "model": "chirp-v4",
            "state": "succeeded",
            "style": "rock, punk",
            "duration": 161.68
        },
        {
            "id": "2c45f5ba-6af7-40a6-b62f-9ced54548b12",
            "title": "",
            "image_url": "https://cdn2.suno.ai/image_2c45f5ba-6af7-40a6-b62f-9ced54548b12.jpeg",
            "lyric": "girl girl girl",
            "audio_url": "https://cdn1.suno.ai/2c45f5ba-6af7-40a6-b62f-9ced54548b12.mp3",
            "video_url": "https://cdn1.suno.ai/2c45f5ba-6af7-40a6-b62f-9ced54548b12.mp4",
            "created_at": "2024-12-22T03:50:50.822Z",
            "model": "chirp-v4",
            "state": "succeeded",
            "style": "rock, punk",
            "duration": 170.28
        }
    ]
}

生成的结果与上文类似,这就完成了对原先生成的歌曲进行翻版生成的过程。

替换片段

当生成歌曲之后需要进行替换歌曲片段单独操作的二次创作时,可以对歌曲的某个片段进行替换操作。就可以指定如下内容:

  • action:内容为 replace_section
  • audio_id:之前生成歌曲的 ID。
  • model: 歌曲生成模型,
  • lyric: 替换后的完整歌词(只需要与prompt有重复就行,不需要完全的歌词),
  • prompt:需要替换的歌词部分。
  • style:歌曲的风格,选填。
  • replace_section_start:lyric对应的歌词时间轴的起始时间。
  • replace_section_end:lyric对应的歌词时间轴的终点时间。

比如原先生成后的歌曲 ID 是:ade7241b-0357-4a5e-9b3d-4ec4f4b3a0c0,那么可以设置参数如下:

{
  "action": "replace_section",
  "lyric": "[Chorus]\n新年快乐 人人欢快歌\n祝福洒满每一片角落\n新年快乐 心中花火多\n愿望成真生活似金色波\n[Verse 2]\n梅花绽放春意洋溢满地\n梅花绽放春意洋溢满地",
  "prompt": "梅花绽放春意洋溢满地\n梅花绽放春意洋溢满地",
  "replace_section_start": 28.94100580270793,
  "replace_section_end": 85.39410058027079,
  "model": "chirp-v4",
  "audio_id": "ade7241b-0357-4a5e-9b3d-4ec4f4b3a0c0",
  "custom": false,
  "instrumental": false
}

其他参数不变,返回的就是一首替换后的歌曲,就是对原先生成的歌曲进行替换片段后的结果,样例如下:

{
    "success": true,
    "task_id": "7a37c35d-7081-413d-908d-ab2d3f8139bf",
    "trace_id": "1ed92d6e-9a19-48f7-ab34-68c82c792303",
    "data": [
        {
            "id": "2a1467dc-51a4-4872-9ccc-ccd96e4fbbb6",
            "title": "新年快乐",
            "image_url": "https://cdn2.suno.ai/image_dc1b5edc-fbae-44a3-8962-d596dbd2b0d7.jpeg",
            "lyric": "[Chorus]\n新年快乐 人人欢快歌\n祝福洒满每一片角落\n新年快乐 心中花火多\n愿望成真生活似金色波\n[Verse 2]\n梅花绽放春意洋溢满地\n梅花绽放春意洋溢满地",
            "audio_url": "https://cdn1.suno.ai/2a1467dc-51a4-4872-9ccc-ccd96e4fbbb6.mp3",
            "video_url": "",
            "created_at": "2025-04-18T01:55:02.930Z",
            "model": "chirp-v4",
            "state": "succeeded",
            "style": "traditional influences, female vocals",
            "duration": 202.52,
            "concat_history": [
                {
                    "id": "ade7241b-0357-4a5e-9b3d-4ec4f4b3a0c0",
                    "type": "gen",
                    "source": "ios",
                    "infill_start_s": 28.94100580270793,
                    "infill_end_s": 85.39410058027079,
                    "infill_dur_s": 56.45309477756285,
                    "infill_context_start_s": 0,
                    "infill_context_end_s": 115.39410058027079,
                    "include_future_s": 2,
                    "include_history_s": 2,
                    "infill": true,
                    "infill_lyrics": "梅花绽放春意洋溢满地\n梅花绽放春意洋溢满地"
                },
                {
                    "id": "dc1b5edc-fbae-44a3-8962-d596dbd2b0d7"
                }
            ]
        }
    ]
}

生成的结果与上文类似,这就完成了对原先生成的歌曲进行替换片段的过程。

声曲分离

当生成歌曲之后需要进行伴奏和人声单独操作的二次创作时,可以分离纯音乐伴奏和清唱人声。就可以指定如下内容:

  • action:内容为 stems
  • audio_id:之前生成歌曲的 ID。

比如原先生成后的歌曲 ID 是:ec13e502-d043-4eb2-92ee-e900c6da69d1,那么可以设置参数如下:

{
  "audio_id": "ec13e502-d043-4eb2-92ee-e900c6da69d1"
}

其他参数不变,返回的就是一首翻版后的歌曲,就是对原先生成的歌曲进行翻版后的结果,样例如下:

{
  "success": true,
  "task_id": "4050affc-f8a6-4cba-a86c-bf201eed053d",
  "trace_id": "5107ee58-687d-422f-9195-fa0e82e1fcc8",
  "data": [
    {
      "id": "e3de0928-085a-42c4-b982-3b24738d1989",
      "title": "Deck the Sky - Vocals",
      "image_url": "https://cdn2.suno.ai/image_e3de0928-085a-42c4-b982-3b24738d1989.jpeg",
      "lyric": "[Verse]\nSnowflakes dance on rooftops high\nChildren's laughter fills the sky\nCarols ring from church bells loud\nHolidays a joyful crowd\n[Verse 2]\nCandy canes and cocoa warm\nWrapped up tight in our own storm\nStockings hung with dreams and cheer\nMagic growing every year\n[Chorus]\nDeck the sky with twinkling stars\nHoliday joy feels ours and ours\nSing the songs of love and light\nChristmas glows so pure and bright\n[Verse 3]\nFireside tales of long ago\nReindeer prance in icy glow\nEvergreen and tinsel’s gleam\nChristmas time a lovely dream\n[Bridge]\nHearts are full with friends and kin\nMistletoe for love to win\nGifts of love and hope we share\nChristmas spirit everywhere\n[Chorus]\nDeck the sky with twinkling stars\nHoliday joy feels ours and ours\nSing the songs of love and light\nChristmas glows so pure and bright",
      "audio_url": "https://cdn1.suno.ai/e3de0928-085a-42c4-b982-3b24738d1989.mp3",
      "video_url": "https://cdn1.suno.ai/e3de0928-085a-42c4-b982-3b24738d1989.mp4",
      "created_at": "2025-01-05T07:49:16.881Z",
      "model": "",
      "state": "succeeded",
      "style": "holiday, jolly",
      "duration": 174.16
    },
    {
      "id": "ad5d7c89-709c-4eb4-a5a6-72f9f5e57fdb",
      "title": "Deck the Sky - Instrumental",
      "image_url": "https://cdn2.suno.ai/image_ad5d7c89-709c-4eb4-a5a6-72f9f5e57fdb.jpeg",
      "lyric": "",
      "audio_url": "https://cdn1.suno.ai/ad5d7c89-709c-4eb4-a5a6-72f9f5e57fdb.mp3",
      "video_url": "https://cdn1.suno.ai/ad5d7c89-709c-4eb4-a5a6-72f9f5e57fdb.mp4",
      "created_at": "2025-01-05T07:49:16.892Z",
      "model": "",
      "state": "succeeded",
      "style": "holiday, jolly",
      "duration": 174.16
    }
  ]
}

生成的结果与上文类似,这就完成了对原先生成的歌曲进行声曲分离的过程。

异步回调

由于 Suno 生成音乐的时间相对较长,大约需要 1-2 分钟,如果 API 长时间无响应,HTTP 请求会一直保持连接,导致额外的系统资源消耗,所以本 API 也提供了异步回调的支持。

整体流程是:客户端发起请求的时候,额外指定一个 callback_url 字段,客户端发起 API 请求之后,API 会立马返回一个结果,包含一个 task_id 的字段信息,代表当前的任务 ID。当任务完成之后,生成音乐的结果会通过 POST JSON 的形式发送到客户端指定的 callback_url,其中也包括了 task_id 字段,这样任务结果就可以通过 ID 关联起来了。

下面我们通过示例来了解下具体怎样操作。

首先,Webhook 回调是一个可以接收 HTTP 请求的服务,开发者应该替换为自己搭建的 HTTP 服务器的 URL。此处为了方便演示,使用一个公开的 Webhook 样例网站 https://webhook.site/,打开该网站即可得到一个 Webhook URL,如图所示:

将此 URL 复制下来,就可以作为 Webhook 来使用,此处的样例为 https://webhook.site/03e60575-3d96-4132-b681-b713d78116e2。

接下来,我们可以设置字段 callback_url 为上述 Webhook URL,同时填入 prompt,如图所示:

点击运行,可以发现会立即得到一个结果,如下:

{
  "task_id": "44472ab8-783b-4054-b861-5bf14e462f60"
}

稍等片刻,我们可以在 https://webhook.site/03e60575-3d96-4132-b681-b713d78116e2 上观察到生成歌曲的结果,如图所示:

内容如下:

{
  "success": true,
  "task_id": "44472ab8-783b-4054-b861-5bf14e462f60",
  "data": [
    {
      "id": "da4324e5-84b2-484b-b0e9-dd261381c594",
      "title": "Winter Whispers",
      "image_url": "https://cdn1.suno.ai/image_da4324e5-84b2-484b-b0e9-dd261381c594.png",
      "lyric": "[Verse]\nSnow falling gently from the sky\nChildren giggling as they pass by\nFire crackling\nCozy and warm\nChristmas spirit begins to swarm\n[Verse 2]\nTwinkling lights\nA sight to behold\nStockings hung\nWaiting to be filled with gold\nGifts wrapped with love\nPiled high\nExcitement in the air\nYou can't deny\n[Chorus]\nWinter whispers in the wind\nJoy and love it brings\nLet's celebrate this season\nWith the ones we're missing",
      "audio_url": "https://cdn1.suno.ai/da4324e5-84b2-484b-b0e9-dd261381c594.mp3",
      "video_url": "https://cdn1.suno.ai/da4324e5-84b2-484b-b0e9-dd261381c594.mp4",
      "created_at": "2024-05-11T07:33:05.430Z",
      "model": "chirp-v3",
      "prompt": "A song for Christmas",
      "style": "pop"
    },
    {
      "id": "b878a87b-a0db-4046-8ccd-ecd2fb3d4372",
      "title": "Winter Whispers",
      "image_url": "https://cdn1.suno.ai/image_b878a87b-a0db-4046-8ccd-ecd2fb3d4372.png",
      "lyric": "[Verse]\nSnow falling gently from the sky\nChildren giggling as they pass by\nFire crackling\nCozy and warm\nChristmas spirit begins to swarm\n[Verse 2]\nTwinkling lights\nA sight to behold\nStockings hung\nWaiting to be filled with gold\nGifts wrapped with love\nPiled high\nExcitement in the air\nYou can't deny\n[Chorus]\nWinter whispers in the wind\nJoy and love it brings\nLet's celebrate this season\nWith the ones we're missing",
      "audio_url": "https://cdn1.suno.ai/b878a87b-a0db-4046-8ccd-ecd2fb3d4372.mp3",
      "video_url": "https://cdn1.suno.ai/b878a87b-a0db-4046-8ccd-ecd2fb3d4372.mp4",
      "created_at": "2024-05-11T07:33:05.430Z",
      "model": "chirp-v3",
      "prompt": "A song for Christmas",
      "style": "pop"
    }
  ]
}

可以看到结果中有一个 task_id 字段,其他的字段都和上文类似,通过该字段即可实现任务的关联。

错误处理

如果发生错误,您将得到类似如下的错误信息:

{
  "success": false,
  "error": {
    "code": "forbidden",
    "message": "Song Description contained artist name: eminem"
  },
  "trace_id": "9bb7c2f4-3b7b-4965-b50a-f663874b1b6f",
  "task_id": "9bb3a2a6-c438-436d-a9f3-fa466abc077c"
}

下面是 HTTP Status Code, error.code, error.message 的列表:

Status Codeerror.codeerror.message
400bad_requestinstrumental must be a boolean
400bad_requeststyle must be less than or equal 120
400bad_requestcustom must be a boolean
400bad_requestaudio_id is required when extend audio
400bad_requestcontinue_at is required when extend audio
400bad_requestcontinue_at must be a number greater than 0
400bad_requestlyric is required when extend audio and instrumental is false
400bad_requestprompt is required when generate audio
400bad_requestlyric is required when generate custom audio
403forbiddenPrompt likely malformed
403forbiddenPrompt likely copyrighted
403forbiddenPrompt contained inappropriate material
403forbiddenSong Description flagged for moderation
403forbiddenSong Description contained artist name
403forbiddenSong Description contained producer tag
500api_errorUnable to generate lyrics from song description
500api_errorjob failed with unknown error
500api_errorno available worker in system
500api_errorservice under maintenance, generation paused
504timeouttimeout while waiting for audio generation
PyCharm是一个集成开发环境(IDE),主要用于Python语言开发。如果你想利用它创建一个程序来通过Suno API生成音乐并将其下载,你可以按照以下步骤操作: 1. **安装所需库**: 首先,你需要安装`requests`库来发送HTTP请求以及处理API响应,如果尚未安装,可以在命令行中输入 `pip install requests`. 2. **设置Suno API**: 确保你有Suno API的访问权限,并获取到必要的访问密钥或令牌。通常,这涉及到注册一个开发者账号并在文档中找到对应的API端点和下载音乐的URL。 3. **编写代码**: 使用PyCharm编写一个脚本,示例如下: ```python import requests import os def download_sunny_music(api_key, song_id): # 创建请求头 headers = { 'Authorization': f'Token {api_key}', 'Content-Type': 'application/json' } # 构造下载URL base_url = "https://api.suno.com/music/download" url = f"{base_url}/{song_id}" # 发送GET请求 response = requests.get(url, headers=headers) # 检查请求状态码 if response.status_code == 200: # 下载文件 file_path = f'music/{song_id}.mp3' # 根据需求定制保存路径 with open(file_path, 'wb') as file: file.write(response.content) print(f"Music downloaded: {file_path}") else: print(f"Error downloading music: {response.text}") # 使用API密钥和歌单ID替换这里的变量 api_key = "your_api_key" song_id = "your_song_id" download_sunny_music(api_key, song_id) ``` 4. **运行和调试**: 在PyCharm中设置好项目结构,将上述代码放在适当的位置,然后运行这段代码。记得将`api_key`和`song_id`替换为你实际的API密钥和要下载的歌曲ID。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值