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:
- Genre - Electronic, orchestral, jazz, etc.
- Mood - Happy, melancholic, energetic, calm
- Instruments - Piano, guitar, drums, synth
- Tempo - Fast, slow, moderate
- 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 rocksforest birds chirping at dawnheavy rain on a metal roofwind howling through trees
Urban:
busy city trafficsubway train arrivingcoffee shop ambienceconstruction site
Sci-Fi:
laser blastspaceship engine hummingrobot walkingteleportation 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
- Be specific - Describe genre, mood, and instruments
- Match duration - Align with your video/project length
- Test variations - Generate multiple options
- Layer sounds - Combine music with effects
- Check licensing - AI-generated music is royalty-free
Next Steps
- Add voice narration
- Create video content
- Learn batch processing
#audio#music#sound-effects#generation