SuperAPI AI 工具集

music

智能体与模型

查看项目

更新于 10-14 05:32

技能介绍

用途

该技能用于通过 ElevenLabs Music API 生成音乐。根据文本提示即可生成器乐轨道、带歌词的歌曲、背景音乐、广告短曲,或任何 AI 生成的音乐。

主要能力

支持从文本提示生成音频,也支持带歌词的歌曲;可通过作曲计划(composition plan)实现细粒度控制。

提供以下方法:

  • music.compose:从提示或作曲计划生成音频
  • music.composition_plan.create:生成结构化计划以实现细粒度控制
  • music.compose_detailed:生成音频 + 作曲计划 + 元数据
  • music.upload:上传音频文件,用于后续 inpainting 工作流,并可选提取其作曲计划

完整参数详见 API Reference。music.upload 仅面向可访问 inpainting 功能的企业客户。

使用方式

Python 示例:

from elevenlabs import ElevenLabs

client = ElevenLabs()

audio = client.music.compose(
    prompt="A chill lo-fi hip hop beat with jazzy piano chords",
    music_length_ms=30000
)

with open("output.mp3", "wb") as f:
    for chunk in audio:
        f.write(chunk)

JavaScript 示例(仅使用 @elevenlabs/* 包):

import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
import { createWriteStream } from "fs";

const client = new ElevenLabsClient();
const audio = await client.music.compose({
  prompt: "A chill lo-fi hip hop beat with jazzy piano chords",
  musicLengthMs: 30000,
});
audio.pipe(createWriteStream("output.mp3"));

cURL 示例:

curl -X POST "https://api.elevenlabs.io/v1/music" \
  -H "xi-api-key: $ELEVENLABS_API_KEY" -H "Content-Type: application/json" \
  -d '{"prompt": "A chill lo-fi beat", "music_length_ms": 30000}' --output output.mp3

作曲计划用于更精细的控制:先生成计划、修改后,再作曲。

plan = client.music.composition_plan.create(
    prompt="An epic orchestral piece building to a climax",
    music_length_ms=60000
)

# Inspect/modify styles and sections
print(plan.positiveGlobalStyles)  # e.g. ["orchestral", "epic", "cinematic"]

audio = client.music.compose(
    composition_plan=plan,
    music_length_ms=60000
)

适用场景

适用于创建器乐轨道、带歌词的歌曲、背景音乐、广告短曲等 AI 生成音乐的场景,尤其适合需要通过作曲计划对风格与段落进行细粒度控制的需求。

限制

不可引用具体艺人、乐队或受版权保护的歌词。bad_prompt 错误会附带 prompt_suggestion 提供替代措辞;bad_composition_plan 错误会附带 composition_plan_suggestion。

错误处理示例:

try:
    audio = client.music.compose(prompt="...", music_length_ms=30000)
except Exception as e:
    print(f"API error: {e}")

常见错误:401(无效密钥)、422(无效参数)、429(触发速率限制)。