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.1.tar.gz (32.1 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.1-py3-none-any.whl (28.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for musicgen_unified-2.0.1.tar.gz
Algorithm Hash digest
SHA256 e520d838a519031689f2d68a53899b5dd009ac32a7bf3cf29902c85da74dd90c
MD5 d7283997bc2c5c6d0efeb5bed8248d13
BLAKE2b-256 f4be9198dc4b7f15eb65c1eb7a6b7bee46ee17c4a2d4c1649e3f5061b1fbe7d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for musicgen_unified-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7d8617d406e7dc22265e8acb46dffbef619160a8afe481acfb82d13a7658cd36
MD5 750298bb68f86a9c0a3d68a5f80f50d5
BLAKE2b-256 842aa5d13416d5fc86ca4ccf1ed2dc6c2824f6ed557efa0d3a12101a870b3198

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