Views
No views yet
1git clone https://github.com/open-mmlab/Amphion.git
2# create env
3bash ./models/tts/maskgct/env.sh| Model Name | Description |
|---|---|
| Semantic Codec | Converting speech to semantic tokens. |
| Acoustic Codec | Converting speech to acoustic tokens and reconstructing waveform from acoustic tokens. |
| MaskGCT-T2S | Predicting semantic tokens with text and prompt semantic tokens. |
| MaskGCT-S2A | Predicts acoustic tokens conditioned on semantic tokens. |
1from huggingface_hub import hf_hub_download
2
3# download semantic codec ckpt
4semantic_code_ckpt = hf_hub_download("amphion/MaskGCT", filename="semantic_codec/model.safetensors")
5
6# download acoustic codec ckpt
7codec_encoder_ckpt = hf_hub_download("amphion/MaskGCT", filename="acoustic_codec/model.safetensors")
8codec_decoder_ckpt = hf_hub_download("amphion/MaskGCT", filename="acoustic_codec/model_1.safetensors")
9
10# download t2s model ckpt
11t2s_model_ckpt = hf_hub_download("amphion/MaskGCT", filename="t2s_model/model.safetensors")
12
13# download s2a model ckpt
14s2a_1layer_ckpt = hf_hub_download("amphion/MaskGCT", filename="s2a_model/s2a_model_1layer/model.safetensors")
15s2a_full_ckpt = hf_hub_download("amphion/MaskGCT", filename="s2a_model/s2a_model_full/model.safetensors")1from models.tts.maskgct.maskgct_utils import *
2from huggingface_hub import hf_hub_download
3import safetensors
4import soundfile as sf
5
6if __name__ == "__main__":
7
8 # build model
9 device = torch.device("cuda:0")
10 cfg_path = "./models/tts/maskgct/config/maskgct.json"
11 cfg = load_config(cfg_path)
12 # 1. build semantic model (w2v-bert-2.0)
13 semantic_model, semantic_mean, semantic_std = build_semantic_model(device)
14 # 2. build semantic codec
15 semantic_codec = build_semantic_codec(cfg.model.semantic_codec, device)
16 # 3. build acoustic codec
17 codec_encoder, codec_decoder = build_acoustic_codec(cfg.model.acoustic_codec, device)
18 # 4. build t2s model
19 t2s_model = build_t2s_model(cfg.model.t2s_model, device)
20 # 5. build s2a model
21 s2a_model_1layer = build_s2a_model(cfg.model.s2a_model.s2a_1layer, device)
22 s2a_model_full = build_s2a_model(cfg.model.s2a_model.s2a_full, device)
23
24 # download checkpoint
25 ...
26
27 # load semantic codec
28 safetensors.torch.load_model(semantic_codec, semantic_code_ckpt)
29 # load acoustic codec
30 safetensors.torch.load_model(codec_encoder, codec_encoder_ckpt)
31 safetensors.torch.load_model(codec_decoder, codec_decoder_ckpt)
32 # load t2s model
33 safetensors.torch.load_model(t2s_model, t2s_model_ckpt)
34 # load s2a model
35 safetensors.torch.load_model(s2a_model_1layer, s2a_1layer_ckpt)
36 safetensors.torch.load_model(s2a_model_full, s2a_full_ckpt)
37
38 # inference
39 prompt_wav_path = "./models/tts/maskgct/wav/prompt.wav"
40 save_path = "[YOUR SAVE PATH]"
41 prompt_text = " We do not break. We never give in. We never back down."
42 target_text = "In this paper, we introduce MaskGCT, a fully non-autoregressive TTS model that eliminates the need for explicit alignment information between text and speech supervision."
43 # Specify the target duration (in seconds). If target_len = None, we use a simple rule to predict the target duration.
44 target_len = 18
45
46 maskgct_inference_pipeline = MaskGCT_Inference_Pipeline(
47 semantic_model,
48 semantic_codec,
49 codec_encoder,
50 codec_decoder,
51 t2s_model,
52 s2a_model_1layer,
53 s2a_model_full,
54 semantic_mean,
55 semantic_std,
56 device,
57 )
58
59 recovered_audio = maskgct_inference_pipeline.maskgct_inference(
60 prompt_wav_path, prompt_text, target_text, "en", "en", target_len=target_len
61 )
62 sf.write(save_path, recovered_audio, 24000) 1@article{wang2024maskgct,
2 title={MaskGCT: Zero-Shot Text-to-Speech with Masked Generative Codec Transformer},
3 author={Wang, Yuancheng and Zhan, Haoyue and Liu, Liwei and Zeng, Ruihong and Guo, Haotian and Zheng, Jiachen and Zhang, Qiang and Zhang, Xueyao and Zhang, Shunsi and Wu, Zhizheng},
4 journal={arXiv preprint arXiv:2409.00750},
5 year={2024}
6}
7@inproceedings{amphion,
8 author={Zhang, Xueyao and Xue, Liumeng and Gu, Yicheng and Wang, Yuancheng and Li, Jiaqi and He, Haorui and Wang, Chaoren and Song, Ting and Chen, Xi and Fang, Zihao and Chen, Haopeng and Zhang, Junan and Tang, Tze Ying and Zou, Lexiao and Wang, Mingxuan and Han, Jun and Chen, Kai and Li, Haizhou and Wu, Zhizheng},
9 title={Amphion: An Open-Source Audio, Music and Speech Generation Toolkit},
10 booktitle={{IEEE} Spoken Language Technology Workshop, {SLT} 2024},
11 year={2024}
12}