Registry / ai-ml / audiocraft

audiocraft

JSON →
library1.3.0pypypiunverified

Audiocraft is a research library from Facebook AI for state-of-the-art audio generation, including models like MusicGen and AudioGen. It is built on PyTorch, providing tools for both model inference and training. Currently at version 1.3.0, it sees active development with new releases roughly every 1-3 months, often coinciding with new model research.

pip install audiocraft
INSTALL
IMPORT
SIG · AUDIOCRAFT
A
audiocraft
ai-mlpythonv1.3.0
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MusicGen
from audiocraft.models import MusicGen
from audiocraft.models.musicgen import MusicGen
Models are directly accessible from `audiocraft.models`.
AudioGen
from audiocraft.models import AudioGen
from audiocraft.models.audiogen import AudioGen
Models are directly accessible from `audiocraft.models`.
audio_write
from audiocraft.data.audio import audio_write
from audiocraft.utils.audio import audio_write
The utility for writing audio files moved from `utils` to `data.audio`.

This quickstart demonstrates how to load a pretrained MusicGen model, generate an 8-second audio clip based on a text description, and save it to a WAV file. Ensure you have sufficient disk space and a stable internet connection for the initial model download. GPU is highly recommended for faster generation.

from audiocraft.models import MusicGen from audiocraft.data.audio import audio_write import torch # For moving to CPU if needed # Load a pretrained MusicGen model ('small' is generally recommended for quick tests) # This will download model weights (~2GB for 'small'). Ensure stable internet and disk space. # Specify device if needed: model = MusicGen.get_pretrained('small', device='cuda') # Ensure you have a compatible PyTorch/CUDA setup for GPU usage. model = MusicGen.get_pretrained('small') model.set_generation_params(duration=8) # Generate 8 seconds of audio # Define a description for the music description = "a retro synthwave track with a driving beat" print(f"Generating audio for: '{description}'...") # The generate method takes a list of descriptions. For unconditional generation, pass descriptions=None. samples = model.generate(descriptions=[description], progress=True) # Save the generated audio to a WAV file # `samples` is a torch.Tensor. It's good practice to move to CPU before saving if it's on GPU. audio_write( 'my_synthwave_track', samples[0].cpu(), # Take the first generated sample and move to CPU model.sample_rate, strategy="loudness", loudness_compressor=True # Recommended for better audio quality ) print("Audio saved as 'my_synthwave_track.wav'")
Debug
Known issues
gotchaGenerating audio, especially longer clips or with larger models ('medium', 'large'), is extremely GPU memory intensive. Running out of VRAM is the most common issue.
fix
Use a GPU with sufficient VRAM (e.g., 24GB+ for 'medium' models and longer generations). Reduce `duration` in `set_generation_params`. Try smaller models ('small'). Consider CPU inference as a last resort, but it will be very slow.
affects: All
breakingThe `model.generate_unconditional()` method has been removed/renamed.
fix
Use `model.generate(descriptions=None)` for unconditional generation. The `generate` method now handles both conditional and unconditional generation.
affects: >=1.0.0
gotchaInitial model loading requires downloading large weights (~2GB-3GB+). This can fail due to network issues or insufficient disk space.
fix
Ensure you have a stable internet connection and at least 5GB of free disk space. On unstable networks, consider pre-downloading models or increasing connection timeout settings if possible.
affects: All
gotchaOn Linux, you might encounter `FileNotFoundError: libFLAC.so.8` or similar errors if audio processing dependencies are missing.
fix
Install `libflac-dev` (Debian/Ubuntu) or `flac-libs` (Fedora/CentOS) or `libflac` (Arch Linux) using your system's package manager. For example: `sudo apt-get install libflac-dev`.
affects: All
Upgrade
Version history
1.3.0latest on PyPI · released Jun 3, 2024
Audit
Dependencies
torchrequiredCore deep learning framework (PyTorch)
torchaudiorequiredAudio I/O and processing for PyTorch
Agent activity
43 hits · last 30 days
node
38
Perplexity
1
OpenAI (training)
1
Resources
audiocraft — pip install audiocraft · libregistry