Skip to main content

Simple, clean instrumental music generation with MusicGen

Project description

MusicGen Unified - v2.0

PyPI version Python License CI Downloads Code style: black

A clean, focused implementation of Facebook's MusicGen for instrumental music generation.

What This Is

  • Simple: Just music generation, no unnecessary complexity
  • Fast: GPU-optimized for 10x realtime generation
  • Practical: CLI, API, and web interface included
  • Deployable: One-click AWS deployment

What This Isn't

  • Not for vocal/singing generation (MusicGen doesn't support it)
  • Not a microservices architecture (it's a simple tool)
  • Not a research framework (it's for practical use)

Quick Start

# Install
pip install musicgen-unified

# Generate music
musicgen generate "upbeat jazz piano" --duration 30

# Start web interface
musicgen serve

# Start API
musicgen api

Features

  • ✅ Text-to-music generation
  • ✅ Extended generation (>30 seconds)
  • ✅ Batch processing from CSV
  • ✅ GPU acceleration
  • ✅ Web interface
  • ✅ REST API
  • ✅ AWS deployment ready

Installation

# Basic installation
pip install musicgen-unified

# With GPU support
pip install musicgen-unified[gpu]

# Development
git clone https://github.com/yourusername/musicgen-unified
cd musicgen-unified
pip install -e ".[dev]"

Usage

Command Line

# Basic generation
musicgen generate "smooth jazz saxophone" -o jazz.mp3

# Extended generation
musicgen generate "epic orchestral" --duration 120 -o epic.mp3

# Batch processing
musicgen batch playlist.csv --output-dir music/

Python API

from musicgen import MusicGenerator

# Initialize
generator = MusicGenerator(device="cuda")

# Generate music
audio, sample_rate = generator.generate(
    "ambient electronic",
    duration=30.0
)

# Save
generator.save_audio(audio, sample_rate, "output.mp3")

Web Interface

musicgen serve --port 8080
# Open http://localhost:8080

REST API

musicgen api --port 8000

# Generate music
curl -X POST http://localhost:8000/generate \
  -H "Content-Type: application/json" \
  -d '{"prompt": "classical piano", "duration": 30}'

Deployment

Docker

docker build -t musicgen .
docker run -p 8080:8080 --gpus all musicgen

AWS

# Configure AWS credentials
aws configure

# Deploy
./deployment/deploy_aws.sh

Architecture

musicgen-unified/
├── musicgen/
│   ├── generator.py    # Core generation with GPU optimization
│   ├── batch.py        # Batch processing
│   ├── prompt.py       # Prompt engineering
│   ├── api.py          # FastAPI server
│   ├── cli.py          # CLI interface
│   └── utils.py        # Utilities
├── static/             # Web UI files
├── tests/              # Test suite
└── deployment/         # Deployment scripts

Performance

  • GPU: 10x faster than realtime
  • CPU: 1x realtime (approximate)
  • Memory: <1GB base, ~4GB with large model
  • Startup: <10 seconds

Models

  • small: Fast, lower quality (300M parameters)
  • medium: Balanced (1.5B parameters)
  • large: Best quality (3.3B parameters)

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

License

MIT License - see LICENSE file for details.

Acknowledgments

  • Facebook Research for MusicGen
  • The open source community

Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

musicgen_unified-2.0.0.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

musicgen_unified-2.0.0-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file musicgen_unified-2.0.0.tar.gz.

File metadata

  • Download URL: musicgen_unified-2.0.0.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for musicgen_unified-2.0.0.tar.gz
Algorithm Hash digest
SHA256 6ce71f9581d34ef5df55b4ef68434075d74a81c120d792fd408149c85bef624e
MD5 f6c8ae37aff8010f6f1df09ecd956a49
BLAKE2b-256 8ca336da10359fa3ca0b2728981b87f14e8b48ef9011021a735e9131baf3d9bd

See more details on using hashes here.

File details

Details for the file musicgen_unified-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for musicgen_unified-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa64c7b0f2c65100785f5fcb2a5d4b151525e898f390bbdac09359ef9825fa1a
MD5 086753055670488d04610ee62cc384dc
BLAKE2b-256 0ab3950f42a7e1b229973ff4e09100b46fcb268655085d09876edbc9f850591b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page