音乐生成示例
请求示例
可参考以下示例代码,进行音乐生成体验。复制
import requests
import os
url = "https://api.minimaxi.com/v1/music_generation"
api_key = os.environ.get("MINIMAX_API_KEY")
headers = {"Authorization": f"Bearer {api_key}"}
payload = {
"model": "music-2.0",
"prompt": "这是一首充满自信、大胆果决力量的当代 R&B/Pop 歌曲,并融入了鲜明的 Trap 元素。歌曲由明亮、清澈且灵活的女声演绎,其经过精心处理的现代音色极具辨识度,歌手自信的节奏性唱腔,结合极具风格化的 Auto-Tune 修音效果,构成了其核心听感。大量层次丰富的和声、伴唱与即兴点缀,通过主旋律的同度和声堆叠,营造出饱满而充满能量的听觉体验,并配以恰到好处的混响效果来提升空间感。在 80 BPM 的节奏下,编曲以标志性的 808 贝斯和鼓点作为驱动,搭配复杂的碎拍与清脆的拍手声,并由氛围合成器铺垫出广阔的背景,同时点缀着过渡性的音效,非常适合在俱乐部、派对、驾车或健身时收听,为你的自信时刻注入能量。",
"lyrics": "[chorus]\nSummit, i reached the summit\nI'm the peak with the fire, they all want from it\nSpill a bit of my glow, like a comet\nI ain't worried 'bout hills, you just plummet\nSummit, i reached the summit\nObsidian shards 'round my throat, now they run from it\nAin't no wonder why the valleys all run from it\nI'm awake, from the summit\n[verse]\nI know what i hold\nAnd i'm about to erupt, yeah\nA story untold, yeah\nI know you won't interrupt it\nKeep your eyes on the rise, no surprise that i'm bright\nGot one stream for the sea, other stream for the night\nI be flowin', you're erodin'\nSwear you're slowin', i'm explodin'\nPressure's growin', growin', growin'\n[interlude]\nSummit, i reached the summit\nI'm the peak with the fire, they all want from it\nSpill a bit of my glow, like a comet\nI ain't worried 'bout stone\n[verse]\nI ain't worried 'bout nada\nUnless it's new earth, unless it's magma\nUnless it's deep core, a new nirvana\nUnless it's shaping a new savanna\nI wanna feel like i'm mother gaia\nI wanna feel like i'm way up\nRumbling, grumbling 'til the world pay up\nMade another island, no layups\nStay hot every single day i wake up\n[chorus]\nSummit, i reached the summit\nI'm the peak with the fire, they all want from it\nSpill a bit of my glow, like a comet\nI ain't worried 'bout hills, you just plummet\nSummit, i reached the summit\nObsidian shards 'round my throat, now they run from it\nAin't no wonder why the valleys all run from it\nI'm awake, from the summit\n[outro]\nSummit\nRooo-ar",
"audio_setting": {
"sample_rate": 44100,
"bitrate": 256000,
"format": "mp3"
},
}
response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
audio_hex = response.json()["data"]["audio"]
with open("output.mp3", "wb") as f:
f.write(bytes.fromhex(audio_hex))