Quick takeaways: MusicGen is a text-to-music model available through Meta/Facebook Research’s AudioCraft project. The safest first step is the official
facebook/MusicGenHugging Face Space or the documented Colab. For local usage, the AudioCraft README lists Python 3.9, PyTorch 2.1.0, FFmpeg, and GPU requirements; the MusicGen docs recommend at least 16GB GPU memory for medium-sized models. This guide does not generate or evaluate audio locally.
What is MusicGen?
The MusicGen documentation describes it as a simple and controllable music generation model. It is a single-stage autoregressive Transformer over a 32kHz EnCodec tokenizer.
MusicGen is part of AudioCraft, a PyTorch library for audio generation research that includes inference and training code for AudioGen and MusicGen.

Why it matters
Text-to-music can help creators prototype background tracks, developers test game audio ideas, and researchers understand generative audio workflows. But music also has licensing and rights concerns, so testing the model is not the same as clearing output for commercial use.
Try the official demo first
The public demo is available at:
https://huggingface.co/spaces/facebook/MusicGen
Start with short prompts and short durations. Use the demo to understand behavior before setting up a GPU environment.
Local installation from the AudioCraft README
The README lists Python 3.9 and PyTorch 2.1.0. It provides this installation path:
python -m pip install 'torch==2.1.0'
python -m pip install setuptools wheel
python -m pip install -U audiocraftFor the latest GitHub version:
python -m pip install -U git+https://[email protected]/facebookresearch/audiocraft#egg=audiocraftThe README also recommends FFmpeg:
sudo apt-get install ffmpegOr with Conda/Miniconda:
conda install "ffmpeg<5" -c conda-forgeLocal Gradio demo
The MusicGen docs list this command for the local Gradio demo:
python -m demos.musicgen_app --shareUse this only after the AudioCraft environment is correctly installed and your GPU is ready.
Basic Python API example
The MusicGen docs include this example:
import torchaudio
from audiocraft.models import MusicGen
from audiocraft.data.audio import audio_write
model = MusicGen.get_pretrained('facebook/musicgen-melody')
model.set_generation_params(duration=8)
wav = model.generate_unconditional(4)
descriptions = ['happy rock', 'energetic EDM', 'sad jazz']
wav = model.generate(descriptions)
melody, sr = torchaudio.load('./assets/bach.mp3')
wav = model.generate_with_chroma(descriptions, melody[None].expand(3, -1, -1), sr)
for idx, one_wav in enumerate(wav):
audio_write(f'{idx}', one_wav.cpu(), model.sample_rate, strategy="loudness", loudness_compressor=True)This is a documentation example, not a locally verified run from this cron job.
Model options
The docs list facebook/musicgen-small at 300M parameters, musicgen-medium and musicgen-melody at 1.5B, musicgen-large and musicgen-melody-large at 3.3B, plus stereo variants.
For first tests, start with the small model or the official demo.
Common issues
GPU memory is the main blocker. The docs recommend at least 16GB GPU memory for medium-sized models.
Missing FFmpeg or mismatched PyTorch versions can break local runs.
Licensing must be checked carefully. The Hugging Face Space lists cc-by-nc-4.0, while the AudioCraft repository is MIT-licensed. Code, model, demo, and output terms may differ.
Safety and licensing
The MusicGen docs state that the model was trained on 20K hours of licensed music, including 10K internal high-quality tracks plus ShutterStock and Pond5 music data. That does not automatically clear every use case.
For monetized videos, games, client work, or redistribution, review the model card, Space license, AudioCraft license, and platform policies first.
FAQ
Can MusicGen run on CPU?
The official docs emphasize GPU-based local inference and recommend 16GB GPU memory for medium models. This guide does not recommend CPU local usage.
Is there a no-install demo?
Yes. Use the facebook/MusicGen Hugging Face Space or the documented Colab.
Can I use generated music commercially?
Do not assume that. The Space lists cc-by-nc-4.0; verify all relevant terms before commercial use.







