TutorialsAudioAI Music Generation
IntermediateUpdated Dec 16, 2025

AI Music Generation

Create original music, soundtracks, and sound effects using AI models for any creative project.

SC
Sarah Chen
Developer Advocate
10 min read

Introduction to AI Music

AI can now compose original music from text descriptions. Create background music, sound effects, and full compositions for your projects.

Basic Music Generation

python
from abstrakt import AbstraktClient

client = AbstraktClient()

result = client.run("fal-ai/music-generation", {
    "input": {
        "prompt": "Upbeat electronic music with synthesizers and a driving beat",
        "duration": 30  # seconds
    }
})

print(f"Music URL: {result.audio.url}")

Describing Music

Effective prompts include:

  1. Genre - Electronic, orchestral, jazz, etc.
  2. Mood - Happy, melancholic, energetic, calm
  3. Instruments - Piano, guitar, drums, synth
  4. Tempo - Fast, slow, moderate
  5. Style - Cinematic, lo-fi, ambient

Example Prompts

Background Music:

text
Calm ambient music with soft piano and gentle strings, 
perfect for meditation, slow tempo, peaceful atmosphere

Action Scene:

text
Intense orchestral music with dramatic drums and brass,
fast tempo, building tension, cinematic action score

Lo-fi:

text
Lo-fi hip hop beat with vinyl crackle, mellow piano chords,
relaxed drums, perfect for studying, chill vibes

Sound Effects Generation

python
result = client.run("fal-ai/sound-effects", {
    "input": {
        "prompt": "Thunder rumbling in the distance with light rain",
        "duration": 10
    }
})

Sound Effect Categories

Nature:

  • ocean waves crashing on rocks
  • forest birds chirping at dawn
  • heavy rain on a metal roof
  • wind howling through trees

Urban:

  • busy city traffic
  • subway train arriving
  • coffee shop ambience
  • construction site

Sci-Fi:

  • laser blast
  • spaceship engine humming
  • robot walking
  • teleportation whoosh

Controlling Duration

python
# Short clip (5 seconds)
{"duration": 5}

# Medium length (30 seconds)
{"duration": 30}

# Long form (2 minutes)
{"duration": 120}

Music for Videos

Create music that matches your video content:

python
async def create_video_with_music(video_prompt, music_prompt):
    # Generate video and music in parallel
    video_task = client.run_async("fal-ai/minimax/video-01", {
        "input": {"prompt": video_prompt}
    })
    
    music_task = client.run_async("fal-ai/music-generation", {
        "input": {
            "prompt": music_prompt,
            "duration": 10  # Match video duration
        }
    })
    
    video, music = await asyncio.gather(video_task, music_task)
    
    return {
        "video": video.video.url,
        "music": music.audio.url
    }

# Example
result = await create_video_with_music(
    video_prompt="A timelapse of clouds moving over mountains",
    music_prompt="Peaceful ambient music with soft synths, nature documentary style"
)

Looping Music

Create seamless loops for games and apps:

python
result = client.run("fal-ai/music-generation", {
    "input": {
        "prompt": "Ambient background music for a fantasy game",
        "duration": 30,
        "loop": True  # Ensures seamless loop
    }
})

Output Formats

python
# MP3 (default)
{"output_format": "mp3", "quality": "high"}

# WAV (lossless)
{"output_format": "wav"}

# OGG (games/web)
{"output_format": "ogg"}

Best Practices

  1. Be specific - Describe genre, mood, and instruments
  2. Match duration - Align with your video/project length
  3. Test variations - Generate multiple options
  4. Layer sounds - Combine music with effects
  5. Check licensing - AI-generated music is royalty-free

Next Steps

#audio#music#sound-effects#generation