music-generator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Music Generator

音乐生成器

First time? If
setup_complete: false
above, run
./SETUP.md
first, then set
setup_complete: true
.
Generate custom AI music using ElevenLabs Music API with detailed composition control.
首次使用? 如果上方的
setup_complete: false
,请先运行
./SETUP.md
,然后将
setup_complete
设置为
true
使用ElevenLabs Music API生成自定义AI音乐,支持精细化的创作控制。

Features

功能特性

  • Simple Mode: Generate music from a text prompt
  • Detailed Mode: Create multi-section compositions with precise control over styles, moods, and transitions
  • Instrumental or Vocal: Support for both instrumental and vocal tracks
  • Custom Duration: Generate tracks from 15 seconds to 5 minutes
  • 简易模式:通过文本提示词生成音乐
  • 详细模式:创建多段落的音乐作品,可精准控制风格、情绪和过渡
  • 器乐或人声:同时支持器乐和人声曲目
  • 自定义时长:生成15秒到5分钟的曲目

Quick Start

快速开始

bash
cd ~/.claude/skills/music-generator/scripts
bash
cd ~/.claude/skills/music-generator/scripts

Simple prompt-based generation

Simple prompt-based generation

npx ts-node generate_music.ts
--prompt "Uplifting corporate music with electronic beats"
--duration 60
--output /path/to/music.mp3
npx ts-node generate_music.ts
--prompt "Uplifting corporate music with electronic beats"
--duration 60
--output /path/to/music.mp3

List available styles

List available styles

npx ts-node generate_music.ts --list-styles
undefined
npx ts-node generate_music.ts --list-styles
undefined

Composition Modes

创作模式

1. Simple Mode (--prompt)

1. 简易模式(--prompt)

Generate music from a single text prompt:
bash
npx ts-node generate_music.ts \
  --prompt "Energetic workout music with driving beats and motivational synths" \
  --duration 90 \
  --output workout.mp3
通过单个文本提示词生成音乐:
bash
npx ts-node generate_music.ts \
  --prompt "Energetic workout music with driving beats and motivational synths" \
  --duration 90 \
  --output workout.mp3

2. Detailed Mode (--composition)

2. 详细模式(--composition)

Create multi-section compositions with JSON config:
bash
npx ts-node generate_music.ts \
  --composition /path/to/composition.json \
  --output epic-track.mp3
Composition JSON Format:
json
{
  "duration_ms": 80000,
  "instrumental": true,
  "positive_global_styles": ["corporate", "motivational", "electronic"],
  "negative_global_styles": ["sad", "aggressive", "heavy metal"],
  "sections": [
    {
      "section_name": "Intro",
      "duration_ms": 20000,
      "positive_local_styles": ["building momentum", "soft start"],
      "negative_local_styles": ["loud", "intense"],
      "lines": []
    },
    {
      "section_name": "Main Theme",
      "duration_ms": 40000,
      "positive_local_styles": ["energetic", "uplifting", "driving rhythm"],
      "negative_local_styles": ["slow", "mellow"],
      "lines": []
    },
    {
      "section_name": "Outro",
      "duration_ms": 20000,
      "positive_local_styles": ["triumphant", "resolution"],
      "negative_local_styles": ["abrupt ending"],
      "lines": []
    }
  ]
}
通过JSON配置文件创建多段落音乐作品:
bash
npx ts-node generate_music.ts \
  --composition /path/to/composition.json \
  --output epic-track.mp3
创作JSON格式:
json
{
  "duration_ms": 80000,
  "instrumental": true,
  "positive_global_styles": ["corporate", "motivational", "electronic"],
  "negative_global_styles": ["sad", "aggressive", "heavy metal"],
  "sections": [
    {
      "section_name": "Intro",
      "duration_ms": 20000,
      "positive_local_styles": ["building momentum", "soft start"],
      "negative_local_styles": ["loud", "intense"],
      "lines": []
    },
    {
      "section_name": "Main Theme",
      "duration_ms": 40000,
      "positive_local_styles": ["energetic", "uplifting", "driving rhythm"],
      "negative_local_styles": ["slow", "mellow"],
      "lines": []
    },
    {
      "section_name": "Outro",
      "duration_ms": 20000,
      "positive_local_styles": ["triumphant", "resolution"],
      "negative_local_styles": ["abrupt ending"],
      "lines": []
    }
  ]
}

Style Guide

风格指南

Positive Global Styles (Overall Track Feel)

全局正向风格(整体曲目基调)

Moods:
  • uplifting, inspiring, motivational, peaceful, energetic
  • dramatic, epic, emotional, nostalgic, mysterious
  • playful, cheerful, romantic, melancholic
Genres:
  • corporate, cinematic, electronic, ambient, orchestral
  • pop, rock, jazz, classical, world music
  • lo-fi, hip-hop, EDM, acoustic, folk
Instruments:
  • piano, guitar, strings, synths, drums
  • brass, woodwinds, percussion, bass
情绪类:
  • uplifting, inspiring, motivational, peaceful, energetic
  • dramatic, epic, emotional, nostalgic, mysterious
  • playful, cheerful, romantic, melancholic
流派类:
  • corporate, cinematic, electronic, ambient, orchestral
  • pop, rock, jazz, classical, world music
  • lo-fi, hip-hop, EDM, acoustic, folk
乐器类:
  • piano, guitar, strings, synths, drums
  • brass, woodwinds, percussion, bass

Negative Global Styles (What to Avoid)

全局负向风格(需要避免的元素)

  • aggressive, dark, scary, chaotic
  • heavy metal, death metal, harsh noise
  • explicit, profane
  • aggressive, dark, scary, chaotic
  • heavy metal, death metal, harsh noise
  • explicit, profane

Section-Specific Styles

段落专属风格

Use
positive_local_styles
and
negative_local_styles
to control individual sections:
Intro Styles:
  • soft opening, building momentum, atmospheric
  • gentle start, mysterious intro
Peak/Chorus Styles:
  • energetic peak, driving rhythm, powerful
  • emotional climax, triumphant
Outro Styles:
  • gentle fade, triumphant ending, resolution
  • nostalgic close, hopeful conclusion
使用
positive_local_styles
negative_local_styles
来控制单个段落的风格:
开场段落风格:
  • soft opening, building momentum, atmospheric
  • gentle start, mysterious intro
高潮/副歌段落风格:
  • energetic peak, driving rhythm, powerful
  • emotional climax, triumphant
结尾段落风格:
  • gentle fade, triumphant ending, resolution
  • nostalgic close, hopeful conclusion

Command Options

命令选项

OptionShortDescription
--prompt
-p
Text prompt for simple mode
--composition
-c
JSON file for detailed mode
--duration
-d
Duration in seconds (simple mode)
--output
-o
Output file path (required)
--instrumental
-i
Generate instrumental track
--format
-f
Output format (mp3_44100_192, mp3_44100_128)
--list-styles
Show available styles
--help
-h
Show help
选项缩写描述
--prompt
-p
简易模式下的文本提示词
--composition
-c
详细模式使用的JSON配置文件
--duration
-d
曲目时长(秒,仅简易模式)
--output
-o
输出文件路径(必填)
--instrumental
-i
生成纯器乐曲目
--format
-f
输出格式(可选值:mp3_44100_192, mp3_44100_128)
--list-styles
显示所有可用风格
--help
-h
显示帮助信息

Examples

示例

Corporate Background Music

企业背景音乐

bash
npx ts-node generate_music.ts \
  -p "Professional corporate background music, uplifting and modern, suitable for presentations" \
  -d 120 \
  -i \
  -o corporate-bg.mp3
bash
npx ts-node generate_music.ts \
  -p "Professional corporate background music, uplifting and modern, suitable for presentations" \
  -d 120 \
  -i \
  -o corporate-bg.mp3

Podcast Intro

播客开场音乐

bash
npx ts-node generate_music.ts \
  -p "Catchy podcast intro music, energetic and memorable, with electronic elements" \
  -d 15 \
  -o podcast-intro.mp3
bash
npx ts-node generate_music.ts \
  -p "Catchy podcast intro music, energetic and memorable, with electronic elements" \
  -d 15 \
  -o podcast-intro.mp3

Video Game Theme

电子游戏主题音乐

bash
npx ts-node generate_music.ts \
  -p "Epic fantasy adventure theme with orchestral instruments and heroic melodies" \
  -d 180 \
  -i \
  -o game-theme.mp3
bash
npx ts-node generate_music.ts \
  -p "Epic fantasy adventure theme with orchestral instruments and heroic melodies" \
  -d 180 \
  -i \
  -o game-theme.mp3

Multi-Section Composition

多段落音乐作品

Create a file
my-composition.json
:
json
{
  "duration_ms": 120000,
  "instrumental": true,
  "positive_global_styles": ["cinematic", "epic", "orchestral"],
  "negative_global_styles": ["electronic", "modern"],
  "sections": [
    {
      "section_name": "Dawn",
      "duration_ms": 30000,
      "positive_local_styles": ["soft", "mysterious", "building anticipation"],
      "negative_local_styles": ["loud", "fast"],
      "lines": []
    },
    {
      "section_name": "Battle",
      "duration_ms": 50000,
      "positive_local_styles": ["intense", "driving", "heroic"],
      "negative_local_styles": ["peaceful", "slow"],
      "lines": []
    },
    {
      "section_name": "Victory",
      "duration_ms": 40000,
      "positive_local_styles": ["triumphant", "emotional", "uplifting"],
      "negative_local_styles": ["sad", "mellow"],
      "lines": []
    }
  ]
}
Then generate:
bash
npx ts-node generate_music.ts \
  -c my-composition.json \
  -o epic-journey.mp3
创建配置文件
my-composition.json
json
{
  "duration_ms": 120000,
  "instrumental": true,
  "positive_global_styles": ["cinematic", "epic", "orchestral"],
  "negative_global_styles": ["electronic", "modern"],
  "sections": [
    {
      "section_name": "Dawn",
      "duration_ms": 30000,
      "positive_local_styles": ["soft", "mysterious", "building anticipation"],
      "negative_local_styles": ["loud", "fast"],
      "lines": []
    },
    {
      "section_name": "Battle",
      "duration_ms": 50000,
      "positive_local_styles": ["intense", "driving", "heroic"],
      "negative_local_styles": ["peaceful", "slow"],
      "lines": []
    },
    {
      "section_name": "Victory",
      "duration_ms": 40000,
      "positive_local_styles": ["triumphant", "emotional", "uplifting"],
      "negative_local_styles": ["sad", "mellow"],
      "lines": []
    }
  ]
}
然后执行生成命令:
bash
npx ts-node generate_music.ts \
  -c my-composition.json \
  -o epic-journey.mp3

API Limits

API限制

  • Maximum duration: 330 seconds (5.5 minutes)
  • Minimum duration: 15 seconds
  • Generation time: ~30-60 seconds per track
  • Cost: ~$0.05-0.15 per generation (varies by duration)
  • 最长时长:330秒(5.5分钟)
  • 最短时长:15秒
  • 生成时间:每首曲目约30-60秒
  • 成本:每次生成约0.05-0.15美元(根据时长有所不同)

Troubleshooting

故障排除

"Invalid API key": Check
.env
file has valid
ELEVENLABS_API_KEY
"Duration too long": Maximum is 330 seconds (5.5 minutes)
"Validation error": Ensure composition JSON has all required fields:
  • positive_global_styles
    (array)
  • negative_global_styles
    (array)
  • sections
    with
    section_name
    ,
    duration_ms
    ,
    positive_local_styles
    ,
    negative_local_styles
    ,
    lines
"Invalid API key":检查
.env
文件中是否包含有效的
ELEVENLABS_API_KEY
"Duration too long":最长时长限制为330秒(5.5分钟)
"Validation error":确保创作JSON文件包含所有必填字段:
  • positive_global_styles
    (数组类型)
  • negative_global_styles
    (数组类型)
  • sections
    数组中的每个元素需包含
    section_name
    duration_ms
    positive_local_styles
    negative_local_styles
    lines
    字段