# Getting Started with XCodec2 on Hugging Face To use `xcodec2`, ensure you have it installed. You can install it using the following command: ```bash conda create -n xcodec2 python=3.9 conda activate xcodec2 pip install xcodec2 ``` Then, ```python import torch import soundfile as sf from transformers import AutoConfig from xcodec2.modeling_xcodec2 import XCodec2Model model_path = "HKUST-Audio/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) with torch.no_grad(): vq_code = model.encode_code(input_waveform=wav_tensor) print("Code:", vq_code ) recon_wav = model.decode_code(vq_code).cpu() sf.write("reconstructed.wav", recon_wav[0, 0, :].numpy(), sr) print("Done! Check reconstructed.wav") ```