在这篇文章中,我们将介绍如何集成 Riffusion 音频生成 API。该 API 能够通过输入自定义参数生成官方的 Riffusion 音乐,适合开发者在各种应用场景中使用,比如音乐创作、游戏背景音乐生成等。
申请使用 API
要使用 Riffusion 音频生成 API,首先需要在 Riffusion Audios Generation API 页面申请相应的服务。进入页面后,点击“获取”按钮,如下图所示:

如果您尚未登录或注册,将自动重定向到登录页面,邀请您进行注册和登录。登录或注册后,将自动返回当前页面。
首次申请时,您将获得免费的配额,允许您免费使用 API。
基本用法
您可以输入任何文本来生成歌曲。例如,如果我想生成一首关于圣诞节的歌曲,可以输入 a song for Christmas,如下图所示:

在这里,我们设置了请求头,包括:
accept: 您希望接收的响应格式,这里填为application/json,表示 JSON 格式。authorization: 调用 API 的密钥,可以在申请后直接选择。
另外,请求体中的参数包括:
action: 音乐生成任务的操作,这里设置为generate,表示生成一首歌曲。model: 用于创建歌曲的模型,目前主要包括:FUZZ-1.0, FUZZ-1.1, FUZZ-1.0 Pro, FUZZ-1.1 Pro。lyric: 歌词内容。custom: 是否以自定义方式生成歌曲。prompt: 灵感模式下的提示词。style: 歌曲风格参数。title: 歌曲标题信息。audio_id: 参考歌曲 ID,用于续写/再现操作。continue_at: 从指定秒数继续写歌。replace_section_start/replace_section_end: 替换段落的起始和结束时间,以秒为单位。vocal_variation: 声音变异程度,数值越大表示与原声差异越大。callback_url: 结果需要发送回的 URL。instrumental: 是否为无歌词模式。
上述参数与 Riffusion 官方自定义生成之间的映射关系如下:
model: 对应 Riffusion 账号设置页面的模型选择,如下图所示。lyric: 对应 Riffusion 自定义生成页面的“歌词”部分,如下图所示。style: 对应 Riffusion 自定义生成页面的“声音”部分,实际上指定了一些风格,如下图所示。title: 对应 Riffusion 自定义生成页面的“详细信息”部分,用于指定歌曲标题,如下图所示。instrumental: 对应 Riffusion 自定义生成页面的“无歌词”开关,用于设置无歌词模式,如下图所示。


在选择后,您可以在右侧看到相应的代码生成,如下图所示:

点击“尝试”按钮进行测试,如上图所示,我们得到了以下结果:
{
"success": true,
"task_id": "f45388a9-4169-41d4-aec8-fb8259c48d36",
"trace_id": "1df9f664-fd74-476b-8038-b0b5f62ddf87",
"data": [
{
"id": "02702b40-272d-4838-8644-675105930658",
"title": "Vibe",
"image_url": "https://storage.googleapis.com/corpusant-app-public/riffs/e850008a-d9a1-4c8f-acbd-a37f228946bc/image/02702b40-272d-4838-8644-675105930658.jpg",
"lyric": "[Intro]\nYeah, yeah\nKeep talking, keep talking\nI love the way you sound\n[Verse 1]\nYour voice is like a drug I can't put down\nEvery word you say just pulls me in\nI'm addicted to the way you laugh out loud\nAnd how you whisper when the room goes dim\nTell me 'bout your day, tell me 'bout your fears\nI could listen to you talk for years\n[Pre-Chorus]\nDon't stop now, don't you dare\nI need your voice filling up the air\n[Chorus]\nKeep talking, keep talking to me\nYour words are all I fucking need\nKeep talking, keep talking, I'm high\nOff every sound you make tonight\nKeep talking\n[Verse 2]\nYou could read the phone book, I don't care\nJust the rhythm of your breathing's enough\nWhen you say my name, it's like a prayer\nAnd your silence hits me twice as rough\nEvery conversation feels like home\nNever want to hear this dial tone\n[Pre-Chorus]\nDon't stop now, don't you dare\nI need your voice filling up the air\n[Chorus]\nKeep talking, keep talking to me\nYour words are all I fucking need\nKeep talking, keep talking, I'm high\nOff every sound you make tonight\nKeep talking\n[Bridge]\nWhen the world gets loud and crazy\nYour voice cuts through the noise\nYou're my favorite conversation\nYou're my drug of choice\nKeep talking, keep talking\nKeep talking, keep talking\nKeep talking, keep talking\nKeep talking, keep talking\n[Chorus]\nKeep talking, keep talking to me\nYour words are all I fucking need\nKeep talking, keep talking, I'm high\nOff every sound you make tonight\nKeep talking\n[Outro]\nYeah, yeah\nKeep talking, keep talking\nNever stop that sound",
"audio_url": "https://storage.googleapis.com/corpusant-app-public/riffs/e850008a-d9a1-4c8f-acbd-a37f228946bc/audio/02702b40-272d-4838-8644-675105930658.m4a",
"video_url": null,
"created_at": "2025-06-18T15:47:54.705246Z",
"model": "FUZZ-1.0",
"lyrics_timestamped": {
"words": [
{
"text": "[Intro]",
"start": 0.64,
"end": 0.64,
"line_index": 0,
"index_range": null,
"wav2vec2_format": null
},
...
{
"text": "sound",
"start": 179.84,
"end": 180.48,
"line_index": 63,
"index_range": null,
"wav2vec2_format": null
}
]
},
"state": "succeeded",
"style": "Pop, upbeat tempo, modern production",
"duration": 181.12
},
...
]
}
返回结果包含多个字段,具体描述如下:
success: 音乐生成任务的状态。data: 此音乐任务的结果 -id: 此时音乐生成任务的 ID。prompt: 此时音乐生成任务的提示。audio_url: 此时音乐生成任务的音频链接。image_url: 此时音乐生成任务的封面链接。state: 此时音乐生成任务的状态。duration: 此时音乐的时长信息。style: 此时音乐的风格信息。model: 此时用于音乐生成任务的模型信息。lyric: 此时音乐生成任务的歌词信息。
可以看到,我们已经获得了生成的音乐信息,只需根据 data 中的音乐链接地址获取生成的 Riffusion 音乐。
另外,如果您想生成相应的集成代码,可以直接复制生成的代码,例如,CURL 代码如下:
curl -X POST 'https://api.acedata.cloud/riffusion/audios' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
"model": "FUZZ-1.0",
"action": "generate",
"prompt": "A song for Christmas"
}'
自定义生成
如果