音频人工智能指南

音乐生成器

MusicGen 是 Meta 的开放式文本到音乐模型,于 2023 年 6 月发布,它使用单个转换器语言模型将音乐编写为一系列压缩音频标记。

听听这个指南AI叙述 · ~8 min

在本页阅读时间 9 分钟
  1. 概述
  2. 主要要点
  3. 深入探讨
  4. 生成并检查简短的 MusicGen 剪辑
  5. 现实世界的实施
  6. MusicGen 的未来
  7. 付诸实践
  8. 资料来源与延伸阅读
  9. 不断探索
  10. 常见问题

概述

它可以遵循文本描述,例如流派和情绪,或者哼唱或演奏的旋律,并输出 32 kHz 音频。它的代码获得了麻省理工学院的许可,而其权重则被许可用于非商业用途。

主要要点

  1. MusicGen 是一个单级转换器,可根据文本描述和(可选)旋律生成 EnCodec 音频标记。
  2. Meta 于 2023 年 8 月 2 日发布了 MusicGen 权重和代码,作为 AudioCraft 的一部分。
  3. MusicGen 经过约 20,000 小时的授权音乐训练,参数大小为 300M、1.5B 和 3.3B。
  4. 延迟交错模式将 30 秒的四码本音频转换为大约 1,500 个自回归步骤。
  5. MusicGen 无法产生真实的人声,因为人声已从其训练数据中删除。
  6. MusicGen代码已获得MIT许可,但其模型权重为CC-BY-NC 4.0,禁止商业使用。

深入探讨

MusicGen is a model that generates music from a text description, optionally guided by a melody. It was introduced by Jade Copet and colleagues at Meta AI in the paper "Simple and Controllable Music Generation", first posted to arXiv in June 2023. It works the way a text language model does, predicting the next token from the previous ones, except that its tokens represent short slices of compressed audio rather than words. A separate neural audio codec turns those tokens back into sound. The word simple in the title refers to the design: one transformer generates everything in a single stage, instead of the chain of models that earlier systems such as Google's MusicLM used to go from coarse to fine detail.

The first ingredient is EnCodec, a neural audio codec from the same Meta team, described in an October 2022 paper. A codec compresses audio into a compact form and reconstructs it. The MusicGen version takes 32 kHz mono audio, downsamples it by a stride of 640 samples to 50 frames per second, and represents each frame with residual vector quantization (RVQ): four codebooks of 2,048 entries each, where the first codebook captures the coarse content and each later codebook encodes what the previous ones missed. Thirty seconds of music therefore becomes 1,500 frames, each with four tokens.

The second ingredient is how those four parallel token streams are fed to one transformer. Predicting all 6,000 tokens of a 30-second clip one by one, called flattening, is accurate but slow. Predicting all four codebooks of a frame at once, called parallel, is fast but ignores dependencies between them. MusicGen's default "delay" pattern offsets each codebook by one step, so at each step the model predicts codebook 1 for the current frame, codebook 2 for the previous frame, and so on. The paper says this turns 30 seconds of audio into 1,500 autoregressive steps. In its ablation, flattening still scored best, delay came close, and parallel was worst.

Conditioning steers the generation. Text prompts are encoded by a frozen T5 text encoder, and the paper also tested FLAN-T5 and CLAP. For melody, the model reads a chromagram, a representation of how much energy falls in each of the 12 pitch classes over time. The authors found that the raw chromagram led the model to copy the original track, so they kept only the dominant pitch class at each step and used Demucs, a source-separation model, to remove drums and bass first, because those dominated the chromagram. Generation uses classifier-free guidance: during training the condition is dropped 20% of the time, and at inference the model blends conditioned and unconditioned predictions with a guidance scale of 3.0 to follow the prompt more closely.

Training used about 20,000 hours of licensed music: an internal set of 10,000 high-quality tracks plus 25,000 and 365,000 instrument-only tracks from the ShutterStock and Pond5 collections, all at 32 kHz with text descriptions and metadata. The team trained models of 300 million, 1.5 billion and 3.3 billion parameters for one million steps on 30-second crops, using 32, 64 and 96 GPUs respectively. Meta announced the model publicly on 2 August 2023 as part of AudioCraft, alongside AudioGen for sound effects and an improved EnCodec decoder. The Hugging Face model card says the version 1 models were trained between April and May 2023.

On the MusicCaps benchmark of expert-written music descriptions, MusicGen compared well. Frechet Audio Distance (FAD), which measures how far generated audio statistics are from real audio, was 3.1 for the 300M model, against 4.0 reported for MusicLM, 7.5 for Mousai and 14.8 for Riffusion; Noise2Music reported the best FAD at 2.1. In human ratings on a 1 to 100 scale, the 3.3B model scored 84.81 for overall quality and the 1.5B model 83.70 for relevance to the text, against 80.51 and 82.35 for the public MusicLM demo. The authors note that larger models did not always improve automatic metrics even when listeners preferred them. With melody conditioning, the similarity between the reference and generated chromagrams rose from 0.10 to 0.66. A stereo variant, fine-tuned from the mono model with eight codebooks, was rated higher than mono.

Compared with alternatives, MusicGen's main trade is simplicity for some control. Hierarchical systems like MusicLM cascade several models, which the MusicGen authors avoided. Diffusion-based systems such as Riffusion and Mousai generate spectrograms or latents through iterative denoising rather than token by token. Within token-based models, MusicGen's interleaving patterns are its distinguishing choice. Its open release is also a difference: Meta published weights and code, while MusicLM's implementation was not public at the time of the paper.

The limitations are stated by Meta itself. The model card says MusicGen cannot generate realistic vocals, because vocals were removed from training data; works best with English descriptions; performs unevenly across musical styles and cultures; sometimes collapses to silence at the end of a song; and may need prompt engineering. The paper's authors note that their method offers no fine-grained control over how closely the output follows the conditioning beyond classifier-free guidance, and that the dataset contains a larger proportion of Western-style music. They also raise the concern that generative models could compete unfairly with artists. The weights are licensed CC-BY-NC 4.0, which rules out commercial use, even though the code is MIT-licensed. In practice, running MusicGen requires Python, PyTorch and ffmpeg per the AudioCraft README, and a GPU is advisable for the larger checkpoints; the model card's examples generate clips of a few seconds at a time.

04工作示例

生成并检查简短的 MusicGen 剪辑

  1. 安装Hugging Face Transformers 4.31.0或更高版本和scipy,并确认在CC-BY-NC 4.0重量许可证下使用为非商业用途。

  2. 通过文本到音频管道加载 facebook/musicgen-small,以在第一次测试中保持较低的内存使用量。

  3. 根据提示“带有柔和钢琴和黑胶爆裂声的低保真嘻哈节拍”生成剪辑,并将返回的 32 kHz 阵列保存为 WAV 文件。

  4. 根据同一提示生成第二个剪辑并收听两个剪辑;使用 top-k 进行采样使每次运行都不同。

  5. 更改提示的一项元素,例如将钢琴换成萨克斯管,然后检查乐器是否相应发生变化。

  6. 通过提供简短的参考旋律并聆听曲调是否延续来与旋律检查点进行比较。

它显示了什么

两个或多个 32 kHz 的短乐器剪辑,反映提示的流派和乐器。通过聆听是否及时坚持、是否有任何崩溃到接近尾声的沉默以及注意没有出现真实的声音来检查它们,这两者都符合 Meta 模型卡中的限制。

现实世界的实施

Meta 于 2023 年 8 月 2 日发布了包含 AudioGen 和 EnCodec 的 MusicGen 作为 AudioCraft 框架,发布了模型权重和训练代码,以便研究人员可以根据自己的数据训练模型。

旋律调节:MusicGen 旋律检查点在删除鼓和贝斯后从参考曲目中提取色谱图,然后生成遵循该曲调的新音乐,同时匹配文本提示。

研究人员通过 Hugging Face Transformers(版本 4.31.0 或更高版本)使用文本到音频管道加载小、中、大或旋律检查点,以生成单声道 32 kHz 剪辑。

在该论文对 MusicCaps 的听力测试中,3.3B 参数 MusicGen 的整体质量得分为 84.81(满分 100),高于公开 MusicLM 演示的 80.51 分。

AudioCraft 存储库后来添加了相关研究模型,例如 MAGNeT(一种非自回归文本到音乐模型)和基于同一代码库构建的用于音频水印的 AudioSeal。

MusicGen 的未来

The MusicGen paper names its own open problems: finer control over how strictly output follows its conditioning, and better data augmentation and guidance for audio conditioning such as melodies. Meta's August 2023 announcement acknowledged that the training data skews toward Western-style music and English-only descriptions, which limits the model's range. Since 2023, the AudioCraft repository has grown to include MAGNeT, a non-autoregressive text-to-music and text-to-sound model, MusicGen Style, JASCO for conditioning on chords, melodies and drum tracks, and AudioSeal for watermarking generated audio, which shows the research direction toward faster generation, richer musical controls and provenance tools. Questions about training-data licensing, attribution and the economic effect on working musicians remain unresolved across the field, and the MusicGen authors flagged unfair competition for artists as an open issue. Evaluations using shared benchmarks such as MusicCaps, together with human listening tests, remain the main way to compare newer music models with MusicGen.

付诸实践

为什么这很重要

  • 交通与覆盖范围. 它通过转录、旁白和语音界面提高了可访问性。
  • 成本与预算. 媒体团队可以用更少的预算更快地交付精美的音频。
  • 速度与规模. 面向客户的系统可以处理更大规模的语音交互。

留意

  • 如果未征得同意,语音滥用和冒充风险就会增加。
  • 由于口音、方言或嘈杂的环境,准确性可能会下降。
  • 如果没有明确的标签,合成音频可能会被误认为是真实的语音。

后续步骤

  1. 获得语音捕获、克隆和重用的明确同意。
  2. 测试不同扬声器和背景条件下的质量。
  3. 定义人员必须审查或批准输出的时间。
  4. 标记合成音频并保留来源记录以供问责。

资料来源与延伸阅读

  1. arXiv (Meta AI)简单可控的音乐生成
  2. GitHub (facebookresearch)AudioCraft:音频生成的开源代码
  3. Hugging Facefacebook/musicgen-大模型卡
  4. Meta AIAudioCraft:简单的音频建模一站式商店
  5. arXiv (Meta AI)高保真神经音频压缩

不断探索

免费通讯

获取每日AI简报

每个工作日早晨提供三条经过验证的AI故事,使用简明英文撰写。永久免费,无广告。

每个工作日发送一封邮件。一键退订。我们永不出售或分享您的地址。

测试一下自己

参加 MusicGen 测验

每个答案即时反馈,课程通过后可获得可验证ID的可分享证书。

开始测验

支持免费AI教育。AI Understanding是一家501(c)(3)非营利组织——无广告,无付费墙,永不收费。 捐款

常见问题

MusicGen是什么?

MusicGen 是 Meta 的开放式文本到音乐模型,于 2023 年 6 月发布,它使用单个转换器语言模型将音乐编写为一系列压缩音频标记。它可以遵循文本描述,例如流派和情绪,或者哼唱或演奏的旋律,并输出 32 kHz 音频。它的代码获得了麻省理工学院的许可,而其权重则被许可用于非商业用途。

除了文本之外,旋律调节的 MusicGen 变体还可以接受哪些输入?

旋律条件变体可以使用文本描述和参考旋律;此输入并非在每个纯文本检查点中都可用。

哪个神经编解码器产生 MusicGen 预测的音频标记?

MusicGen 对 Meta 的 EnCodec 编解码器生成的离散令牌进行建模,该编解码器还将预测的令牌解码回音频。

MusicGen 如何对多个 EnCodec 码流进行建模?

该架构在单阶段自回归模型中使用延迟交错; “单级”并不意味着整首歌曲是在一次前向传递中生成的。

MusicGen 如何在不复制精确录音的情况下遵循提供的旋律?

色谱图捕捉随时间变化出现的音级,让 MusicGen 匹配曲调的和声和轮廓,而无需再现原始音色。

MusicGen 是哪个项目和公司发布的?

MusicGen 作为 Meta AI 的 AudioCraft 项目的一部分于 2023 年发布,具有开放代码和模型权重。