Views
No views yet

pip install dualcodec| Model_ID | Frame Rate | RVQ Quantizers | Semantic Codebook Size (RVQ-1 Size) | Acoustic Codebook Size (RVQ-rest Size) | Training Data |
|---|---|---|---|---|---|
| 12hz_v1 | 12.5Hz | Any from 1-8 (maximum 8) | 16384 | 4096 | 100K hours Emilia |
| 25hz_v1 | 25Hz | Any from 1-12 (maximum 12) | 16384 | 1024 | 100K hours Emilia |
1import dualcodec
2
3model_id = "12hz_v1" # select from available Model_IDs, "12hz_v1" or "25hz_v1"
4
5dualcodec_model = dualcodec.get_model(model_id)
6dualcodec_inference = dualcodec.Inference(dualcodec_model=dualcodec_model, device="cuda")
7
8# do inference for your wav
9import torchaudio
10audio, sr = torchaudio.load("YOUR_WAV.wav")
11# resample to 24kHz
12audio = torchaudio.functional.resample(audio, sr, 24000)
13audio = audio.reshape(1,1,-1)
14audio = audio.to("cuda")
15# extract codes, for example, using 8 quantizers here:
16semantic_codes, acoustic_codes = dualcodec_inference.encode(audio, n_quantizers=8)
17# semantic_codes shape: torch.Size([B, 1, T])
18# acoustic_codes shape: torch.Size([B, n_quantizers-1, T])
19
20# produce output audio
21out_audio = dualcodec_inference.decode(semantic_codes, acoustic_codes)
22
23# save output audio
24torchaudio.save("out.wav", out_audio.cpu().squeeze(0), 24000)# export HF_ENDPOINT=https://hf-mirror.com # uncomment this to use huggingface mirror if you're in China
huggingface-cli download facebook/w2v-bert-2.0 --local-dir w2v-bert-2.0
huggingface-cli download amphion/dualcodec dualcodec_12hz_16384_4096.safetensors dualcodec_25hz_16384_1024.safetensors w2vbert2_mean_var_stats_emilia.pt --local-dir dualcodec_ckptsdualcodec_ckpts.1import dualcodec
2
3w2v_path = "./w2v-bert-2.0" # your downloaded path
4dualcodec_model_path = "./dualcodec_ckpts" # your downloaded path
5model_id = "12hz_v1" # select from available Model_IDs, "12hz_v1" or "25hz_v1"
6
7dualcodec_model = dualcodec.get_model(model_id, dualcodec_model_path)
8dualcodec_inference = dualcodec.Inference(dualcodec_model=dualcodec_model, dualcodec_path=dualcodec_model_path, w2v_path=w2v_path, device="cuda")
9
10# do inference for your wav
11import torchaudio
12audio, sr = torchaudio.load("YOUR_WAV.wav")
13# resample to 24kHz
14audio = torchaudio.functional.resample(audio, sr, 24000)
15audio = audio.reshape(1,1,-1)
16audio = audio.to("cuda")
17# extract codes, for example, using 8 quantizers here:
18semantic_codes, acoustic_codes = dualcodec_inference.encode(audio, n_quantizers=8)
19# semantic_codes shape: torch.Size([1, 1, T])
20# acoustic_codes shape: torch.Size([1, n_quantizers-1, T])
21
22# produce output audio. If `acoustic_codes=None` is passed, will decode only semantic codes (RVQ-1)
23out_audio = dualcodec_inference.decode(semantic_codes, acoustic_codes)
24
25# save output audio
26torchaudio.save("out.wav", out_audio.cpu().squeeze(0), 24000)python -m dualcodec.apppip install "dualcodec[tts]"pip install -e .[tts]python -m dualcodec.infer.valle.cli_valle_infer --ref_audio <path_to_ref_audio> --ref_text "TEXT OF YOUR REF AUDIO" --gen_text "This is the generated text" --output_dir test --output_file test.wavpython -m dualcodec.infer.valle.gradio_valle_demopython -m dualcodec.infer.voicebox.cli_voicebox_infer --ref_audio <path_to_ref_audio> --output_dir test --output_file test.wavpip install -U wandb protobuf transformerspip install "dualcodec[tts]"cd to the project root folder (the folder that contains this readme):1git clone https://github.com/jiaqili3/DualCodec.git
2cd DualCodec1accelerate launch train.py --config-name=dualcodec_train \
2model=dualcodec_12hz_16384_4096_8vq \
3trainer.batch_size=3 \
4data.segment_speech.segment_length=240001accelerate launch train.py --config-name=dualcodec_train \
2model=dualcodec_25hz_16384_1024_12vq \
3trainer.batch_size=3 \
4data.segment_speech.segment_length=24000
5

pip install "dualcodec[train]"cd to the project root folder (the folder that contains this readme).huggingface-cli download amphion/dualcodec --local-dir dualcodec_ckpts1accelerate launch train.py --config-name=dualcodec_ft_12hzv1 \
2trainer.batch_size=3 \
3data.segment_speech.segment_length=240001accelerate launch train.py --config-name=dualcodec_ft_25hzv1 \
2trainer.batch_size=3 \
3data.segment_speech.segment_length=24000@inproceedings{dualcodec,
title = {DualCodec: A Low-Frame-Rate, Semantically-Enhanced Neural Audio Codec for Speech Generation},
author = {Li, Jiaqi and Lin, Xiaolong and Li, Zhekai and Huang, Shixi and Wang, Yuancheng and Wang, Chaoren and Zhan, Zhenpeng and Wu, Zhizheng},
booktitle = {Proceedings of Interspeech 2025},
year = {2025}
}1@article{amphion2,
2 title = {Overview of the Amphion Toolkit (v0.2)},
3 author = {Jiaqi Li and Xueyao Zhang and Yuancheng Wang and Haorui He and Chaoren Wang and Li Wang and Huan Liao and Junyi Ao and Zeyu Xie and Yiqiao Huang and Junan Zhang and Zhizheng Wu},
4 year = {2025},
5 journal = {arXiv preprint arXiv:2501.15442},
6}
7
8@inproceedings{amphion,
9 author={Xueyao Zhang and Liumeng Xue and Yicheng Gu and Yuancheng Wang and Jiaqi Li and Haorui He and Chaoren Wang and Ting Song and Xi Chen and Zihao Fang and Haopeng Chen and Junan Zhang and Tze Ying Tang and Lexiao Zou and Mingxuan Wang and Jun Han and Kai Chen and Haizhou Li and Zhizheng Wu},
10 title={Amphion: An Open-Source Audio, Music and Speech Generation Toolkit},
11 booktitle={{IEEE} Spoken Language Technology Workshop, {SLT} 2024},
12 year={2024}
13}