zhenye234/xcodec

AAAI 2025: Codec Does Matter: Exploring the Semantic Shortcoming of Codec for Audio Language Model

What is X-Codec?

X-Codec is a codec — a system that compresses audio into a compact representation and then reconstructs it. But unlike traditional codecs that only preserve acoustic details (like pitch and timbre), X-Codec also captures semantic meaning (what is being said or what sound represents). It's designed specifically for audio language models (AI systems that generate or understand audio, like speech or music).

Why does it matter?

The project's paper argues that existing codecs often lose semantic information when compressing audio, which hurts the performance of audio language models. X-Codec fixes this by unifying semantic and acoustic features into a single codec, so the compressed representation retains both the meaning and the acoustic quality.

How does it work?

X-Codec builds on top of any existing acoustic codec (like those from UniAudio or DAC) and adds two extra components:

  1. A semantic model (e.g., HuBERT or WavLM) that extracts high-level meaning from audio.
  2. Projector layers that combine the acoustic and semantic features before quantization, and then separate them after quantization.

The code example in the README shows how to modify a standard codec class: you add a semantic model, two linear projectors (fc_prior to merge features, fc_post1/fc_post2 to split them back), and a loss function to ensure the quantized representation matches the semantic features.

In short: the encoder extracts both acoustic and semantic features, they are merged, quantized together, then split — the acoustic part goes to the decoder, and the semantic part is used for training.

How to use it?

Inference

  1. Download a model checkpoint and its config from Hugging Face (links in the README).
  2. Run python inference.py (the script is in the repo).

Training

  1. Prepare a text file listing paths to your audio files (one per line) for training and validation.
  2. Update the config file with these file paths.
  3. Run:
    torchrun --nnodes=1 --nproc-per-node=8 main_launch_vqdp.py
    

Available models

The README lists several pre-trained checkpoints on Hugging Face, each with a different semantic model and training data:

  • Speech models: trained on Librispeech or MLS English, using HuBERT or WavLM as the semantic extractor.
  • General audio models: trained on 200k hours of internal data, using a HuBERT variant for general audio.

Some models are marked "not mentioned in paper" — these are extra variants.

Acknowledgements

The codebase is largely borrowed from UniAudio and DAC.

Citation

If you find the project useful, cite the paper:

@article{ye2024codecdoesmatterexploring,
  title={Codec Does Matter: Exploring the Semantic Shortcoming of Codec for Audio Language Model},
  author={Zhen Ye and Peiwen Sun and Jiahe Lei and Hongzhan Lin and Xu Tan and Zheqi Dai and Qiuqiang Kong and Jianyi Chen and Jiahao Pan and Qifeng Liu and Yike Guo and Wei Xue},
  journal={arXiv preprint arXiv:2408.17175},
  year={2024}
}

All information above is taken directly from the project's README.

Related

  • Project
  • Project
  • Project
  • Project