SunoAI API Library是一个非官方的Python客户端,用于与Suno AI的音乐生成器交互。该库有助于使用 Suno 的 Chirp v3 模型生成音乐,并包含 Suno AI 的主要功能和内置音乐下载器。它可以使用 FastAPI、Local、Docker 作为REST API部署在 Heroku 等 PaaS 提供商上。
?在使用库或 REST API 之前,您必须在 suno.ai 网站上注册并获取您的 cookie,如此屏幕截图所示。
您可以从 Web 浏览器的开发者工具 -> 网络选项卡中找到 cookie
只需右键单击并打开检查。过滤器: _clerk_js_version
将此 cookie 设置为SUNO_COOKIE
环境变量或初始化库,如下所示。
from suno import Suno , ModelVersions
client = Suno (
cookie = 'YOUR_COOKIE_HERE' ,
model_version = ModelVersions . CHIRP_V3_5 )
使用 pip 安装库:
pip install SunoAI
在部署之前将SUNO_COOKIE
设置为环境变量。 - 指示
export SUNO_COOKIE= " YOUR_COOKIE_HERE "
git clone [email protected]:Malith-Rukshan/Suno-API.git
pip3 install -r requirements.txt
cd Suno-API
fastapi run api.py --port 8080
?网址:http://127.0.0.1:8080
⚡️快速入门:
from suno import Suno , ModelVersions
client = Suno (
cookie = 'YOUR_COOKIE_HERE' ,
model_version = ModelVersions . CHIRP_V3_5 )
# Generate a song
songs = client . generate ( prompt = "A serene landscape" , is_custom = False , wait_audio = True )
# Download generated songs
for song in songs :
file_path = client . download ( song = song )
print ( f"Song downloaded to: { file_path } " )
Suno()
<- 初始化
chirp-v3-5
、 chirp-v3-0
、 chirp-v2-0
默认为chirp-v3-5
。 |详细视图generate()
Clip
对象列表。 clips = client . generate (
prompt = "A peaceful melody reflecting a serene landscape" ,
is_custom = False ,
wait_audio = True
)
print ( clips )
clips = client . generate (
prompt = "I found a love, for me n Darling, just dive right in and follow my lead n Well, I found a girl, beautiful and sweet n Oh, I never knew you were the someone waiting for me..." ,
tags = "English men voice" ,
title = "Perfect by Malith-Rukshan/Suno-API" ,
make_instrumental = False ,
is_custom = True ,
wait_audio = True
)
print ( clips )
✍️使用注意事项:
is_custom
设置为True
时,请确保提示参数包含您要生成的歌曲的歌词。相反,如果is_custom
设置为False
,请提供描述性提示,详细说明您想要的歌曲的本质。wait_audio
设置为True时,请求将花费更长的时间来等待音频 URL 准备好。如果未设置,则返回的响应将不带audio_url
,但带有音频ID。在这种情况下,生成过程完成后,您需要在短时间间隔后调用get_songs或get_song方法来检索包含audio_url
的响应。 get_songs()
Clip
对象列表。 songs = client . get_songs ( song_ids = "123,456" )
print ( songs )
set_visibility()
response = client . set_visibility ( song_id = "uuid-type-songid-1234" , is_public = False )
print ( response )
get_credits()
CreditsInfo
对象的当前账单和积分信息。 credits_info = client . get_credits ()
print ( credits_info )
download()
# Using a song ID
file_path = client . download ( song = "uuid-type-songid-1234" )
print ( f"Song downloaded to: { file_path } " )
# Using a Clip object
clip = client . get_song ( "uuid-type-songid-1234" )
file_path = client . download ( song = clip )
print ( f"Song downloaded to: { file_path } " )
Suno AI 提供的用于生成音乐的模型。
chirp-v3-5
:最新模型,更好的歌曲结构,最长 4 分钟。chirp-v3-0
:广泛、通用,最长 2 分钟。chirp-v2-0
:复古 Suno 模型,最长 1.3 分钟。示例如何使用:
from suno import Suno , ModelVersions
client = Suno ( model_version = ModelVersions . CHIRP_V3_5 )
或者
from suno import Suno
client = Suno ( model_version = 'chirp-v3-5' )
夹子型号:
Clip类封装了 Suno AI 生成的音乐曲目的详细信息。此类的每个属性都提供有关轨道的特定信息:
CreditsInfo 模型:
CreditsInfo类提供有关 Suno AI 系统中用户的信用余额和使用情况的信息。
1. 生成音乐
POST /generate
请求正文:
{
"prompt" : " A serene melody about the ocean " ,
"is_custom" : false ,
"tags" : " relaxing, instrumental " ,
"title" : " Ocean Waves " ,
"make_instrumental" : true ,
"model_version" : " chirp-v3-5 " ,
"wait_audio" : true
}
回复:
[
{
"id" : " 124b735f-7fb0-42b9-8b35-761aed65a7f6 " ,
"video_url" : " " ,
"audio_url" : " https://audiopipe.suno.ai/item_id=124b735f-7fb0-42b9-8b35-761aed65a7f6 " ,
"image_url" : " https://cdn1.suno.aiimage_124b735f-7fb0-42b9-8b35-761aed65a7f6.png " ,
"image_large_url" : " https://cdn1.suno.aiimage_large_124b735f-7fb0-42b9-8b35-761aed65a7f.png " ,
"is_video_pending" : False,
"major_model_version" : " v3 " ,
"model_name" : " chirp-v3 " ,
"metadata" : {
"tags" : " English men voice " ,
"prompt" : " I found a love, for me n Darling,just dive right in and follow mylead n Well, I found a girl, beautiful andsweet n Oh, I never knew you were thesomeone waiting for me nn ′Cause we werejust kids when we fell in love n Not knowingwhat it was n I will not give you up thistime n But darling, just kiss me slow n Yourheart is all I own n And in your eyes,you're holding mine nn Baby, I′m dancing inthe dark n With you between myarms n Barefoot on the grass n Listening toour favourite song n When you said youlooked a mess n I whispered underneath mybreath n But you heard it n Darling, you lookperfect tonight " ,
"gpt_description_prompt" : None,
"audio_prompt_id" : None,
"history" : None,
"concat_history" : None,
"type" : " gen " ,
"duration" : None,
"refund_credits" : None,
"stream" : True,
"error_type" : None,
"error_message" : None
},
"is_liked" : False,
"user_id" : " 2340653f-32cb-4343-artb-09203ty749e9 " ,
"display_name" : " Snonymous " ,
"handle" : " anonymous " ,
"is_handle_updated" : False,
"is_trashed" : False,
"reaction" : None,
"created_at" : " 2024-05-05T11:54:09.356Z " ,
"status" : " streaming " ,
"title" : " Perfect by Malith-Rukshan/Suno-API " ,
"play_count" : 0 ,
"upvote_count" : 0 ,
"is_public" : False
}
]
2. 检索歌曲
POST /songs
{
"song_ids" : " uuid-format-1234,4567-abcd "
}
/generate
响应相同3. 获取一首特定的歌曲
POST /get_song
{
"song_id" : " uuid-song-id "
}
/generate
响应相同,但仅剪辑POST /set_visibility
{
"song_id" : " uuid-song-id " ,
"is_public" : true
}
{
"is_public" : true
}
4. 检索信用信息
GET /credits
{
"credits_left" : 50 ,
"period" : " 2024-05 " ,
"monthly_limit" : 100 ,
"monthly_usage" : 25
}
根据 Suno.ai 的说法,每生成一首歌曲需要消耗 5 个积分,因此每次成功调用总共需要 10 个积分。
贡献使开源社区成为学习、启发和创造的绝佳场所。我们非常感谢您所做的任何贡献。
通过该库生成的所有内容和音乐均归功于 Suno AI。这个非官方的 API 提供了一种与 Suno AI 服务交互的便捷方式,但不声明对所生成的音乐的任何所有权或权利。使用Suno AI平台时请遵守Suno AI的服务条款❤️。
该库主要用于教育和开发目的。它旨在增强和简化对 Suno AI 音乐生成功能的访问。如果您喜欢生成的音乐,请考虑直接支持Suno AI。徽标信用:@rejaul43
该项目是根据 MIT 许可证分发的。该许可证允许每个人使用、修改和重新分发代码。但是,它不对其功能提供任何保证。有关更多详细信息,请参阅存储库中的 LICENSE 文件。
如果您发现这个项目有帮助,请不要忘记在 GitHub 上给它一个。这也可以帮助其他人找到并使用该项目! ?
加入我们的 Telegram 频道,
如果您有任何问题、反馈,或者只是想打个招呼,可以联系我:
? 用 ? 构建由单一开发者>