{"id":9500,"library":"audiocraft","title":"audiocraft - Audio Generation","description":"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.","status":"active","version":"1.3.0","language":"en","source_language":"en","source_url":"https://github.com/facebookresearch/audiocraft","tags":["audio","generation","AI","PyTorch","ML","musicgen","audiogen"],"install":[{"cmd":"pip install audiocraft","lang":"bash","label":"Stable release"},{"cmd":"pip install -e '.[dev]' --no-deps","lang":"bash","label":"From source (development)"}],"dependencies":[{"reason":"Core deep learning framework (PyTorch)","package":"torch"},{"reason":"Audio I/O and processing for PyTorch","package":"torchaudio"}],"imports":[{"note":"Models are directly accessible from `audiocraft.models`.","wrong":"from audiocraft.models.musicgen import MusicGen","symbol":"MusicGen","correct":"from audiocraft.models import MusicGen"},{"note":"Models are directly accessible from `audiocraft.models`.","wrong":"from audiocraft.models.audiogen import AudioGen","symbol":"AudioGen","correct":"from audiocraft.models import AudioGen"},{"note":"The utility for writing audio files moved from `utils` to `data.audio`.","wrong":"from audiocraft.utils.audio import audio_write","symbol":"audio_write","correct":"from audiocraft.data.audio import audio_write"}],"quickstart":{"code":"from audiocraft.models import MusicGen\nfrom audiocraft.data.audio import audio_write\nimport torch # For moving to CPU if needed\n\n# Load a pretrained MusicGen model ('small' is generally recommended for quick tests)\n# This will download model weights (~2GB for 'small'). Ensure stable internet and disk space.\n# Specify device if needed: model = MusicGen.get_pretrained('small', device='cuda')\n# Ensure you have a compatible PyTorch/CUDA setup for GPU usage.\nmodel = MusicGen.get_pretrained('small')\nmodel.set_generation_params(duration=8) # Generate 8 seconds of audio\n\n# Define a description for the music\ndescription = \"a retro synthwave track with a driving beat\"\n\nprint(f\"Generating audio for: '{description}'...\")\n# The generate method takes a list of descriptions. For unconditional generation, pass descriptions=None.\nsamples = model.generate(descriptions=[description], progress=True)\n\n# Save the generated audio to a WAV file\n# `samples` is a torch.Tensor. It's good practice to move to CPU before saving if it's on GPU.\naudio_write(\n    'my_synthwave_track',\n    samples[0].cpu(), # Take the first generated sample and move to CPU\n    model.sample_rate,\n    strategy=\"loudness\",\n    loudness_compressor=True # Recommended for better audio quality\n)\n\nprint(\"Audio saved as 'my_synthwave_track.wav'\")","lang":"python","description":"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."},"warnings":[{"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.","message":"Generating audio, especially longer clips or with larger models ('medium', 'large'), is extremely GPU memory intensive. Running out of VRAM is the most common issue.","severity":"gotcha","affected_versions":"All"},{"fix":"Use `model.generate(descriptions=None)` for unconditional generation. The `generate` method now handles both conditional and unconditional generation.","message":"The `model.generate_unconditional()` method has been removed/renamed.","severity":"breaking","affected_versions":">=1.0.0"},{"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.","message":"Initial model loading requires downloading large weights (~2GB-3GB+). This can fail due to network issues or insufficient disk space.","severity":"gotcha","affected_versions":"All"},{"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`.","message":"On Linux, you might encounter `FileNotFoundError: libFLAC.so.8` or similar errors if audio processing dependencies are missing.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Reduce the `duration` parameter in `model.set_generation_params()`. Use a smaller model (e.g., 'small'). If possible, upgrade to a GPU with more VRAM. Ensure no other processes are consuming GPU memory.","cause":"Attempting to generate audio that exceeds the available VRAM on your GPU.","error":"torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate X GiB (GPU 0; Y GiB total capacity; Z GiB already allocated; W GiB free; P MiB reserved in total by PyTorch)"},{"fix":"Replace `model.generate_unconditional()` with `model.generate(descriptions=None)`. The `generate` method now handles both conditional and unconditional generation.","cause":"You are using an older API call (`generate_unconditional`) that has been deprecated/removed in favor of a unified `generate` method.","error":"AttributeError: 'MusicGen' object has no attribute 'generate_unconditional'"},{"fix":"Update your import statement from `from audiocraft.utils.audio import audio_write` to `from audiocraft.data.audio import audio_write`.","cause":"The `audio_write` utility function's import path changed in a recent version.","error":"ImportError: cannot import name 'audio_write' from 'audiocraft.utils.audio' (...)"},{"fix":"Ensure your PyTorch installation is compatible with your CUDA version. It's often best to install PyTorch directly from their website with the correct CUDA version. Reinstalling `audiocraft` or `torchaudio` after verifying PyTorch/CUDA can help. For `torch_audiomentations`, ensure it's properly installed and compatible with your Python/PyTorch versions.","cause":"This often indicates a mismatch between your PyTorch version and your CUDA toolkit, or an issue with custom C++ extensions failing to compile/load.","error":"RuntimeError: No module named '_C' or ImportError: cannot import name '_C' from 'torch_audiomentations.utils'"}]}