Skip to content

Guide · Open source

How to use Audiocraft: install, generate music and sound

Updated · written with AI from the project's own documentation and checked against our catalogue data

Audiocraft is an open-source PyTorch library from Meta's research team for generating audio with deep learning. It includes inference and training code for models such as MusicGen (text-to-music) and AudioGen (text-to-sound), plus the EnCodec audio codec. This guide walks through installing it, what the library contains, where models are stored, and what the licence allows, so you can decide whether it fits your project.

AudioCraftfacebookresearch/audiocraft · ★ 23.8k · MIT

Quick start

  1. 1Check Python and PyTorch. Confirm you have Python 3.9 and install PyTorch 2.1.0 before anything else.
  2. 2Install setuptools and wheel. Run the pip command for setuptools and wheel if installation later asks for them.
  3. 3Install Audiocraft. Run python -m pip install -U audiocraft to get the stable release.
  4. 4Install ffmpeg. Install ffmpeg through your system package manager or conda, as recommended in the README.
  5. 5Set a cache directory if needed. Set AUDIOCRAFT_CACHE_DIR if you want model downloads stored somewhere other than the default.
  6. 6Read the model documentation. Open the MusicGen or AudioGen page linked from the README for usage details before generating audio.

Check the requirements before you install

Audiocraft requires Python 3.9 and PyTorch 2.1.0. You should be comfortable working in a Python environment and running commands in a terminal. The library is built around PyTorch, so it is not a plug-in for a consumer audio app.

The README recommends installing ffmpeg as well. It is listed as recommended, not strictly required.

  • Python 3.9
  • PyTorch 2.1.0
  • ffmpeg (recommended)

Install Audiocraft with pip

Install PyTorch first, before installing xformers or Audiocraft. The README says to skip the PyTorch step if you already have it installed. Then install setuptools and wheel, and finally install the stable Audiocraft release.

If you cloned the repository locally, the README says a local editable install is mandatory if you want to train models.

python -m pip install 'torch==2.1.0' python -m pip install setuptools wheel python -m pip install -U audiocraft

Install ffmpeg

The README recommends ffmpeg. On Debian or Ubuntu you can install it through apt. If you use Anaconda or Miniconda, the README gives a conda command that pins a version below 5.

sudo apt-get install ffmpeg # Or if you are using Anaconda or Miniconda conda install "ffmpeg<5" -c conda-forge

Know which models the library contains

Audiocraft bundles several models. The most relevant for beginners are MusicGen, which generates music from text, and AudioGen, which generates sound from text. EnCodec is a neural audio compressor and tokenizer. Each model has its own documentation page in the repository, linked from the README.

The README also lists Multi Band Diffusion, MAGNeT, AudioSeal watermarking, MusicGen Style and JASCO. Check each model's documentation for its specific usage.

  • MusicGen: text-to-music model
  • AudioGen: text-to-sound model
  • EnCodec: neural audio codec
  • Multi Band Diffusion, MAGNeT, AudioSeal, MusicGen Style, JASCO: additional models described in the README

Control where models are stored

Audiocraft models are downloaded from Hugging Face. You can change the storage location by setting the AUDIOCRAFT_CACHE_DIR environment variable. Other Hugging Face models use the Hugging Face Transformers cache setup, and Demucs-based models such as musicgen-melody use the Torch Hub download location.

  • AUDIOCRAFT_CACHE_DIR sets the cache for Audiocraft models
  • Hugging Face Transformers cache setup applies to other Hugging Face models
  • Torch Hub settings control Demucs downloads

Understand the licence before using the weights

The code in the repository is released under the MIT licence. The model weights are released under CC-BY-NC 4.0, which restricts non-commercial use. If you plan a commercial product, the MIT licence on the code does not extend that permission to the pretrained weights.

  • Code: MIT licence (LICENSE file)
  • Model weights: CC-BY-NC 4.0 (LICENSE_weights file)

What people use it for

  • Researchers testing text-to-music generation with the MusicGen model
  • Developers adding text-to-sound generation to a Python project
  • Students studying how neural audio codecs like EnCodec compress and tokenize audio
  • Training your own audio model with the training code, using a local editable install

Frequently asked questions

Is Audiocraft free to use?

The code is released under the MIT licence, which is permissive. The pretrained model weights are released under CC-BY-NC 4.0, which restricts non-commercial use. Read both licence files before using the models in a product.

What are the requirements for Audiocraft?

The README says Audiocraft requires Python 3.9 and PyTorch 2.1.0. ffmpeg is recommended. You also need a working Python environment, since installation is done with pip.

How do I install Audiocraft?

Install PyTorch 2.1.0 with pip, install setuptools and wheel, then run python -m pip install -U audiocraft. The README also covers installing from GitHub or from a local clone.

Where does Audiocraft store downloaded models?

Audiocraft models are stored in a Hugging Face location by default. Set the AUDIOCRAFT_CACHE_DIR environment variable to change it. Demucs-based models use the Torch Hub download location.

What is the difference between MusicGen and AudioGen?

According to the README, MusicGen is a text-to-music model and AudioGen is a text-to-sound model. Both are included in the Audiocraft library and each has its own documentation page.

What are alternatives to Audiocraft?

Comparable projects mentioned for this category include Stable Audio Tools, Bark and AudioLDM. Compare them on licence, model type and ease of setup before choosing one.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Audiocraft suits researchers, Python developers and students who want working code for text-to-music or text-to-sound models and are comfortable with PyTorch. It is not a finished music app, and commercial projects should check the CC-BY-NC 4.0 limits on the pretrained weights before relying on them.

Install options & downloads