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 頻道,
如果您有任何問題、回饋,或只是想打個招呼,可以聯絡我:
? 用 ? 構建由單一開發者>