AgentSkillsCN

Music Generation

利用Google的音乐生成API生成原创背景音乐。根据场景情绪与时间点,量身定制契合氛围的配乐。

SKILL.md
--- frontmatter
name: Music Generation
description: Generates original background music using Google's Music Generation API. Creates soundtracks matched to scene mood and timing.
triggers:
  - Video has been generated and needs soundtrack
  - User wants background music for their creation
keywords:
  - music
  - soundtrack
  - BGM
  - audio

Music Generation Skill

Creates original background music that matches the mood and pacing of video scenes.

When to Use

  • After video generation → Add matching soundtrack
  • User wants custom music for their scene
  • Need to set emotional tone with audio

Inputs

InputTypeRequiredDefaultDescription
scene_descriptionstrYesWhat's happening in the scene
moodstrYesEmotional tone (see options)
durationintNo30Duration in seconds
stylestrNo"anime_orchestral"Music style

Mood Options

MoodDescription
adventurousUpbeat, exciting, forward momentum
melancholicSad, reflective, bittersweet
mysteriousIntriguing, suspenseful, curious
joyfulHappy, celebratory, light
epicGrand, powerful, dramatic
peacefulCalm, serene, gentle

Style Options

StyleDescription
anime_orchestralClassic anime soundtrack feel
lofi_chillRelaxed, lo-fi hip hop vibe
cinematic_epicBig movie trailer sound
cute_playfulLight, bouncy, kawaii
electronic_ambientAtmospheric synths

Outputs

OutputTypeDescription
audio_pathPathPath to generated audio file
durationfloatActual audio duration
metadatadictGeneration metadata

Implementation Contract

python
class MusicGenerator:
    async def execute(
        self,
        scene_description: str,
        mood: str,
        duration: int = 30,
        style: str = "anime_orchestral"
    ) -> tuple[Path, dict]:
        """
        Generate background music for a scene.

        Raises:
            ValueError: If mood or style is invalid
            APIError: If Music API call fails
        """
        ...

Example Usage

python
from skills.generate_music import MusicGenerator

skill = MusicGenerator()

# Basic usage
audio_path, metadata = await skill.execute(
    scene_description="Two characters explore a neon-lit city",
    mood="adventurous"
)

# Full control
audio_path, metadata = await skill.execute(
    scene_description="Peaceful morning in a meadow",
    mood="peaceful",
    duration=45,
    style="anime_orchestral"
)

Integration with Video

python
# Generate music to match video
video_path, video_meta = await video_skill.execute(...)

music_path, music_meta = await music_skill.execute(
    scene_description=scene_concept["scene_description"],
    mood=scene_concept["mood_for_music"],
    duration=video_meta["duration"]
)

# Compose together
final = await compose_skill.execute(
    video=video_path,
    audio=music_path
)

Dependencies

  • Google Music Generation API
  • Scene concept (for mood extraction)

API Reference

See: https://ai.google.dev/gemini-api/docs/music-generation

Error Handling

ErrorCauseRecovery
ValueErrorInvalid mood/styleUse supported option
APIErrorMusic API failureRetry with backoff
DurationErrorDuration out of rangeUse 5-120 seconds