Model reference · open weights
xcodec2 is an open-weight audio or speech model from HKUSTAudio. AxForge deploys and operates it for you on dedicated EU-owned hardware — with the licence handled where one is required.
Available as managed deployment — configured and operated for you on dedicated EU hardware, quoted per deployment.
What it is
| Released by | HKUSTAudio |
|---|---|
| Type | Audio & music |
| Task | Audio→audio |
| Parameters (lead) | 823M |
| Released | 2025-01-07 |
| Popularity | 1k downloads / month |
| Licence | Commercial licence needed |
About
Update (2026-06-25): A Transformers-native version of Xcodec2 has been released here!
Update (2025-02-13): Add Llasa finetune instruction.
Update (2025-02-07): Our paper has been released!
LLaSA: Scaling Train Time and Inference Time Compute for LLaMA based Speech Synthesis
Codec Does Matter: Exploring the Semantic Shortcoming of Codec for Audio Language Model (AAAI 2025, xcodec 1.0)
XCodec2 is a speech tokenizer that offers the following key features:
To use xcodec2, ensure you have it installed. You can install it using the following command:
conda create -n xcodec2 python=3.9
conda activate xcodec2
pip install xcodec2 (Use `xcodec2==0.1.5` for codec inference and llasa fine-tuning. I’ve removed unnecessary dependencies, and it works fine in my testing. However, I’m not sure if other problems may arise. If you prefer more stability, I recommend using `xcodec2==0.1.3` which accurately aligns during my codec training.)
Then,
import torch
import soundfile as sf
from transformers import AutoConfig
from xcodec2.modeling_xcodec2 import XCodec2Model
model_path = "HKUSTAudio/xcodec2"
model = XCodec2Model.from_pretrained(model_path)
model.eval().cuda()
wav, sr = sf.read("test.wav")
wav_tensor = torch.from_numpy(wav).float().unsqueeze(0) # Shape: (1, T)
with torch.no_grad():
# Only 16khz speech
# Only supports single input. For batch inference, please refer to the link below.
vq_code = model.encode_code(input_waveform=wav_tensor)
print("Code:", vq_code )
recon_wav = model.decode_code(vq_code).cpu() # Shape: (1, 1, T')
sf.write("reconstructed.wav", recon_wav[0, 0, :].numpy(), sr)
print("Done! Check reconstructed.wav")
From the published model card. Full card on the HuggingFace links in the sidebar.
Using it via the API
Once AxForge deploys hkustaudio-xcodec2 for you, it answers on the OpenAI-compatible API — the same base URL and keys as every other model. (hkustaudio-xcodec2 below is illustrative; you get the exact model name on deployment.)
$ curl -sS https://api.axforge.ai/v1/audio/transcriptions \ -H "Authorization: Bearer $AXFORGE_API_KEY" \ -F model="hkustaudio-xcodec2" -F file=@audio.mp3
Create an account — your API key is available in the console. 3M free tokens every 30 days with every new account.