Hecheng0625 commited on
Commit
8d51020
1 Parent(s): 4050191

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +146 -0
README.md ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## FACodec: Speech Codec with Attribute Factorization used for NaturalSpeech 3
2
+
3
+ [![arXiv](https://img.shields.io/badge/arXiv-Paper-<COLOR>.svg)](https://arxiv.org/pdf/2403.03100.pdf)
4
+ [![demo](https://img.shields.io/badge/FACodec-Demo-red)](https://speechresearch.github.io/naturalspeech3/)
5
+ [![model](https://img.shields.io/badge/%F0%9F%A4%97%20HuggingFace-Models-pink)](https://huggingface.co/amphion/naturalspeech3_facodec)
6
+ [![hf](https://img.shields.io/badge/%F0%9F%A4%97%20HuggingFace-Spaces-yellow)](https://huggingface.co/spaces/amphion/naturalspeech3_facodec)
7
+
8
+ ## Overview
9
+
10
+ FACodec is a core component of the advanced text-to-speech (TTS) model NaturalSpeech 3. FACodec converts complex speech waveform into disentangled subspaces representing speech attributes of content, prosody, timbre, and acoustic details and reconstruct high-quality speech waveform from these attributes. FACodec decomposes complex speech into subspaces representing different attributes, thus simplifying the modeling of speech representation.
11
+
12
+ Research can use FACodec to develop different modes of TTS models, such as non-autoregressive based discrete diffusion (NaturalSpeech 3) or autoregressive models (like VALL-E).
13
+
14
+ ## Useage
15
+
16
+ Download the pre-trained FACodec model from HuggingFace: [Pretrained FACodec checkpoint](https://huggingface.co/amphion/naturalspeech3_facodec)
17
+
18
+ Install Amphion
19
+ ```bash
20
+ git https://github.com/open-mmlab/Amphion.git
21
+ ```
22
+
23
+ Few lines of code to use the pre-trained FACodec model
24
+ ```python
25
+ from AmphionOpen.models.ns3_codec import FACodecEncoder, FACodecDecoder
26
+
27
+ fa_encoder = FACodecEncoder(
28
+ ngf=32,
29
+ up_ratios=[2, 4, 5, 5],
30
+ out_channels=256,
31
+ )
32
+
33
+ fa_decoder = FACodecDecoder(
34
+ in_channels=256,
35
+ upsample_initial_channel=1024,
36
+ ngf=32,
37
+ up_ratios=[5, 5, 4, 2],
38
+ vq_num_q_c=2,
39
+ vq_num_q_p=1,
40
+ vq_num_q_r=3,
41
+ vq_dim=256,
42
+ codebook_dim=8,
43
+ codebook_size_prosody=10,
44
+ codebook_size_content=10,
45
+ codebook_size_residual=10,
46
+ use_gr_x_timbre=True,
47
+ use_gr_residual_f0=True,
48
+ use_gr_residual_phone=True,
49
+ )
50
+
51
+ fa_encoder = torch.load("ns3_facodec_encoder.bin")
52
+ fa_decoder = torch.load("ns3_facodec_decoder.bin")
53
+
54
+ fa_encoder.eval()
55
+ fa_decoder.eval()
56
+
57
+ ```
58
+
59
+ Test
60
+ ```python
61
+ test_wav_path = "test.wav"
62
+ test_wav = librosa.load(test_wav_path, sr=16000)[0]
63
+ test_wav = torch.from_numpy(test_wav).float()
64
+ test_wav = test_wav.unsqueeze(0).unsqueeze(0)
65
+
66
+ with torch.no_grad():
67
+
68
+ # encode
69
+ enc_out = fa_encoder(test_wav)
70
+ print(enc_out.shape)
71
+
72
+ # quantize
73
+ vq_post_emb, vq_id, _, quantized, spk_embs = fa_decoder(enc_out, eval_vq=False, vq=True)
74
+
75
+ # latent after quantization
76
+ print(vq_post_emb.shape)
77
+
78
+ # codes
79
+ print("vq id shape:", vq_id.shape)
80
+
81
+ # get prosody code
82
+ prosody_code = vq_id[:1]
83
+ print("prosody code shape:", prosody_code.shape)
84
+
85
+ # get content code
86
+ cotent_code = vq_id[1:3]
87
+ print("content code shape:", cotent_code.shape)
88
+
89
+ # get residual code (acoustic detail codes)
90
+ residual_code = vq_id[3:]
91
+ print("residual code shape:", residual_code.shape)
92
+
93
+ # speaker embedding
94
+ print("speaker embedding shape:", spk_embs.shape)
95
+
96
+ # decode (recommand)
97
+ recon_wav = fa_decoder.inference(vq_post_emb, spk_embs)
98
+ print(recon_wav.shape)
99
+ sf.write("recon.wav", recon_wav[0][0].cpu().numpy(), 16000)
100
+ ```
101
+
102
+
103
+
104
+ ## Some Q&A
105
+
106
+ Q1: What audio sample rate does FACodec support? What is the hop size? How many codes will be generated for each frame?
107
+
108
+ A1: FACodec supports 16KHz speech audio. The hop size is 200 samples, and (16000/200) * 6 (total number of codebooks) codes will be generated for each frame.
109
+
110
+ Q2: Is it possible to train an autoregressive TTS model like VALL-E using FACodec?
111
+
112
+ A2: Yes. In fact, the authors of NaturalSpeech 3 have already employ explore the autoregressive generative model for discrete token generation with FACodec. They use an autoregressive language model to generate prosody codes, followed by a non-autoregressive model to generate the remaining content and acoustic details codes.
113
+
114
+ Q3: Is it possible to train a latent diffusion TTS model like NaturalSpeech2 using FACodec?
115
+
116
+ A3: Yes. You can use the latent getted after quanzaition as the modelling target for the latent diffusion model.
117
+
118
+ Q4: Can FACodec compress and reconstruct audio from other domains? Such as sound effects, music, etc.
119
+
120
+ A4: Since FACodec is designed for speech, it may not be suitable for other audio domains. However, it is possible to use the FACodec model to compress and reconstruct audio from other domains, but the quality may not be as good as the original audio.
121
+
122
+ Q5: Can FACodec be used for content feature for some other tasks like voice conversion?
123
+
124
+ A5: I think the answer is yes. Researchers can use the content code of FACodec as the content feature for voice conversion. We hope to see more research in this direction.
125
+
126
+ ## Citations
127
+
128
+ If you use our FACodec model, please cite the following paper:
129
+
130
+ ```bibtex
131
+ @misc{ju2024naturalspeech,
132
+ title={NaturalSpeech 3: Zero-Shot Speech Synthesis with Factorized Codec and Diffusion Models},
133
+ author={Zeqian Ju and Yuancheng Wang and Kai Shen and Xu Tan and Detai Xin and Dongchao Yang and Yanqing Liu and Yichong Leng and Kaitao Song and Siliang Tang and Zhizheng Wu and Tao Qin and Xiang-Yang Li and Wei Ye and Shikun Zhang and Jiang Bian and Lei He and Jinyu Li and Sheng Zhao},
134
+ year={2024},
135
+ eprint={2403.03100},
136
+ archivePrefix={arXiv},
137
+ primaryClass={eess.AS}
138
+ }
139
+
140
+ @article{zhang2023amphion,
141
+ title={Amphion: An Open-Source Audio, Music and Speech Generation Toolkit},
142
+ author={Xueyao Zhang and Liumeng Xue and Yicheng Gu and Yuancheng Wang and Haorui He and Chaoren Wang 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},
143
+ journal={arXiv},
144
+ year={2024},
145
+ volume={abs/2312.09911}
146
+ }