cqchangm commited on
Commit
40b3a1f
·
verified ·
1 Parent(s): f4c093c

Upload 13 files

Browse files
README.md CHANGED
@@ -1,3 +1,160 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CosyVoice
2
+ ## 👉🏻 [CosyVoice Demos](https://fun-audio-llm.github.io/) 👈🏻
3
+ [[CosyVoice Paper](https://fun-audio-llm.github.io/pdf/CosyVoice_v1.pdf)][[CosyVoice Studio](https://www.modelscope.cn/studios/iic/CosyVoice-300M)][[CosyVoice Code](https://github.com/FunAudioLLM/CosyVoice)]
4
+
5
+ For `SenseVoice`, visit [SenseVoice repo](https://github.com/FunAudioLLM/SenseVoice) and [SenseVoice space](https://www.modelscope.cn/studios/iic/SenseVoice).
6
+
7
+ ## Install
8
+
9
+ **Clone and install**
10
+
11
+ - Clone the repo
12
+ ``` sh
13
+ git clone --recursive https://github.com/FunAudioLLM/CosyVoice.git
14
+ # If you failed to clone submodule due to network failures, please run following command until success
15
+ cd CosyVoice
16
+ git submodule update --init --recursive
17
+ ```
18
+
19
+ - Install Conda: please see https://docs.conda.io/en/latest/miniconda.html
20
+ - Create Conda env:
21
+
22
+ ``` sh
23
+ conda create -n cosyvoice python=3.8
24
+ conda activate cosyvoice
25
+ # pynini is required by WeTextProcessing, use conda to install it as it can be executed on all platform.
26
+ conda install -y -c conda-forge pynini==2.1.5
27
+ pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com
28
+
29
+ # If you encounter sox compatibility issues
30
+ # ubuntu
31
+ sudo apt-get install sox libsox-dev
32
+ # centos
33
+ sudo yum install sox sox-devel
34
+ ```
35
+
36
+ **Model download**
37
+
38
+ We strongly recommend that you download our pretrained `CosyVoice-300M` `CosyVoice-300M-SFT` `CosyVoice-300M-Instruct` model and `CosyVoice-ttsfrd` resource.
39
+
40
+ If you are expert in this field, and you are only interested in training your own CosyVoice model from scratch, you can skip this step.
41
+
42
+ ``` python
43
+ # SDK模型下载
44
+ from modelscope import snapshot_download
45
+ snapshot_download('iic/CosyVoice-300M', local_dir='pretrained_models/CosyVoice-300M')
46
+ snapshot_download('iic/CosyVoice-300M-SFT', local_dir='pretrained_models/CosyVoice-300M-SFT')
47
+ snapshot_download('iic/CosyVoice-300M-Instruct', local_dir='pretrained_models/CosyVoice-300M-Instruct')
48
+ snapshot_download('iic/CosyVoice-ttsfrd', local_dir='pretrained_models/CosyVoice-ttsfrd')
49
+ ```
50
+
51
+ ``` sh
52
+ # git模型下载,请确保已安装git lfs
53
+ mkdir -p pretrained_models
54
+ git clone https://www.modelscope.cn/iic/CosyVoice-300M.git pretrained_models/CosyVoice-300M
55
+ git clone https://www.modelscope.cn/iic/CosyVoice-300M-SFT.git pretrained_models/CosyVoice-300M-SFT
56
+ git clone https://www.modelscope.cn/iic/CosyVoice-300M-Instruct.git pretrained_models/CosyVoice-300M-Instruct
57
+ git clone https://www.modelscope.cn/iic/CosyVoice-ttsfrd.git pretrained_models/CosyVoice-ttsfrd
58
+ ```
59
+
60
+ Optionaly, you can unzip `ttsfrd` resouce and install `ttsfrd` package for better text normalization performance.
61
+
62
+ Notice that this step is not necessary. If you do not install `ttsfrd` package, we will use WeTextProcessing by default.
63
+
64
+ ``` sh
65
+ cd pretrained_models/CosyVoice-ttsfrd/
66
+ unzip resource.zip -d .
67
+ pip install ttsfrd-0.3.6-cp38-cp38-linux_x86_64.whl
68
+ ```
69
+
70
+ **Basic Usage**
71
+
72
+ For zero_shot/cross_lingual inference, please use `CosyVoice-300M` model.
73
+ For sft inference, please use `CosyVoice-300M-SFT` model.
74
+ For instruct inference, please use `CosyVoice-300M-Instruct` model.
75
+ First, add `third_party/Matcha-TTS` to your `PYTHONPATH`.
76
+
77
+ ``` sh
78
+ export PYTHONPATH=third_party/Matcha-TTS
79
+ ```
80
+
81
+ ``` python
82
+ from cosyvoice.cli.cosyvoice import CosyVoice
83
+ from cosyvoice.utils.file_utils import load_wav
84
+ import torchaudio
85
+
86
+ cosyvoice = CosyVoice('pretrained_models/CosyVoice-300M-SFT')
87
+ # sft usage
88
+ print(cosyvoice.list_avaliable_spks())
89
+ # change stream=True for chunk stream inference
90
+ for i, j in enumerate(cosyvoice.inference_sft('你好,我是通义生成式语音大模型,请问有什么可以帮您的吗?', '中文女', stream=False)):
91
+ torchaudio.save('sft_{}.wav'.format(i), j['tts_speech'], 22050)
92
+
93
+ cosyvoice = CosyVoice('pretrained_models/CosyVoice-300M')
94
+ # zero_shot usage, <|zh|><|en|><|jp|><|yue|><|ko|> for Chinese/English/Japanese/Cantonese/Korean
95
+ prompt_speech_16k = load_wav('zero_shot_prompt.wav', 16000)
96
+ for i, j in enumerate(cosyvoice.inference_zero_shot('收到好友从远方寄来的生日礼物,那份意外的惊喜与深深的祝福让我心中充满了甜蜜的快乐,笑容如花儿般绽放。', '希望你以后能够做的比我还好呦。', prompt_speech_16k, stream=False)):
97
+ torchaudio.save('zero_shot_{}.wav'.format(i), j['tts_speech'], 22050)
98
+ # cross_lingual usage
99
+ prompt_speech_16k = load_wav('cross_lingual_prompt.wav', 16000)
100
+ for i, j in enumerate(cosyvoice.inference_cross_lingual('<|en|>And then later on, fully acquiring that company. So keeping management in line, interest in line with the asset that\'s coming into the family is a reason why sometimes we don\'t buy the whole thing.', prompt_speech_16k, stream=False)):
101
+ torchaudio.save('cross_lingual_{}.wav'.format(i), j['tts_speech'], 22050)
102
+
103
+ cosyvoice = CosyVoice('pretrained_models/CosyVoice-300M-Instruct')
104
+ # instruct usage, support <laughter></laughter><strong></strong>[laughter][breath]
105
+ for i, j in enumerate(cosyvoice.inference_instruct('在面对挑战时,他展现了非凡的<strong>勇气</strong>与<strong>智慧</strong>。', '中文男', 'Theo \'Crimson\', is a fiery, passionate rebel leader. Fights with fervor for justice, but struggles with impulsiveness.', stream=False)):
106
+ torchaudio.save('instruct_{}.wav'.format(i), j['tts_speech'], 22050)
107
+ ```
108
+
109
+ **Start web demo**
110
+
111
+ You can use our web demo page to get familiar with CosyVoice quickly.
112
+ We support sft/zero_shot/cross_lingual/instruct inference in web demo.
113
+
114
+ Please see the demo website for details.
115
+
116
+ ``` python
117
+ # change iic/CosyVoice-300M-SFT for sft inference, or iic/CosyVoice-300M-Instruct for instruct inference
118
+ python3 webui.py --port 50000 --model_dir pretrained_models/CosyVoice-300M
119
+ ```
120
+
121
+ **Advanced Usage**
122
+
123
+ For advanced user, we have provided train and inference scripts in `examples/libritts/cosyvoice/run.sh`.
124
+ You can get familiar with CosyVoice following this recipie.
125
+
126
+ **Build for deployment**
127
+
128
+ Optionally, if you want to use grpc for service deployment,
129
+ you can run following steps. Otherwise, you can just ignore this step.
130
+
131
+ ``` sh
132
+ cd runtime/python
133
+ docker build -t cosyvoice:v1.0 .
134
+ # change iic/CosyVoice-300M to iic/CosyVoice-300M-Instruct if you want to use instruct inference
135
+ # for grpc usage
136
+ docker run -d --runtime=nvidia -p 50000:50000 cosyvoice:v1.0 /bin/bash -c "cd /opt/CosyVoice/CosyVoice/runtime/python/grpc && python3 server.py --port 50000 --max_conc 4 --model_dir iic/CosyVoice-300M && sleep infinity"
137
+ cd grpc && python3 client.py --port 50000 --mode <sft|zero_shot|cross_lingual|instruct>
138
+ # for fastapi usage
139
+ docker run -d --runtime=nvidia -p 50000:50000 cosyvoice:v1.0 /bin/bash -c "cd /opt/CosyVoice/CosyVoice/runtime/python/fastapi && MODEL_DIR=iic/CosyVoice-300M fastapi dev --port 50000 server.py && sleep infinity"
140
+ cd fastapi && python3 client.py --port 50000 --mode <sft|zero_shot|cross_lingual|instruct>
141
+ ```
142
+
143
+ ## Discussion & Communication
144
+
145
+ You can directly discuss on [Github Issues](https://github.com/FunAudioLLM/CosyVoice/issues).
146
+
147
+ You can also scan the QR code to join our official Dingding chat group.
148
+
149
+ <img src="./asset/dingding.png" width="250px">
150
+
151
+ ## Acknowledge
152
+
153
+ 1. We borrowed a lot of code from [FunASR](https://github.com/modelscope/FunASR).
154
+ 2. We borrowed a lot of code from [FunCodec](https://github.com/modelscope/FunCodec).
155
+ 3. We borrowed a lot of code from [Matcha-TTS](https://github.com/shivammehta25/Matcha-TTS).
156
+ 4. We borrowed a lot of code from [AcademiCodec](https://github.com/yangdongchao/AcademiCodec).
157
+ 5. We borrowed a lot of code from [WeNet](https://github.com/wenet-e2e/wenet).
158
+
159
+ ## Disclaimer
160
+ The content provided above is for academic purposes only and is intended to demonstrate technical capabilities. Some examples are sourced from the internet. If any content infringes on your rights, please contact us to request its removal.
campplus.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a6ac6a63997761ae2997373e2ee1c47040854b4b759ea41ec48e4e42df0f4d73
3
+ size 28303423
configuration.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"framework":"Pytorch","task":"text-to-speech"}
cosyvoice.yaml ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # set random seed, so that you may reproduce your result.
2
+ __set_seed1: !apply:random.seed [1986]
3
+ __set_seed2: !apply:numpy.random.seed [1986]
4
+ __set_seed3: !apply:torch.manual_seed [1986]
5
+ __set_seed4: !apply:torch.cuda.manual_seed_all [1986]
6
+
7
+ # fixed params
8
+ sample_rate: 22050
9
+ text_encoder_input_size: 512
10
+ llm_input_size: 1024
11
+ llm_output_size: 1024
12
+ spk_embed_dim: 192
13
+
14
+ # model params
15
+ # for all class/function included in this repo, we use !<name> or !<new> for intialization, so that user may find all corresponding class/function according to one single yaml.
16
+ # for system/third_party class/function, we do not require this.
17
+ llm: !new:cosyvoice.llm.llm.TransformerLM
18
+ text_encoder_input_size: !ref <text_encoder_input_size>
19
+ llm_input_size: !ref <llm_input_size>
20
+ llm_output_size: !ref <llm_output_size>
21
+ text_token_size: 60515
22
+ speech_token_size: 4096
23
+ length_normalized_loss: True
24
+ lsm_weight: 0
25
+ spk_embed_dim: !ref <spk_embed_dim>
26
+ text_encoder: !new:cosyvoice.transformer.encoder.ConformerEncoder
27
+ input_size: !ref <text_encoder_input_size>
28
+ output_size: 1024
29
+ attention_heads: 16
30
+ linear_units: 4096
31
+ num_blocks: 6
32
+ dropout_rate: 0.1
33
+ positional_dropout_rate: 0.1
34
+ attention_dropout_rate: 0.0
35
+ normalize_before: True
36
+ input_layer: 'linear'
37
+ pos_enc_layer_type: 'rel_pos_espnet'
38
+ selfattention_layer_type: 'rel_selfattn'
39
+ use_cnn_module: False
40
+ macaron_style: False
41
+ use_dynamic_chunk: False
42
+ use_dynamic_left_chunk: False
43
+ static_chunk_size: 1
44
+ llm: !new:cosyvoice.transformer.encoder.TransformerEncoder
45
+ input_size: !ref <llm_input_size>
46
+ output_size: !ref <llm_output_size>
47
+ attention_heads: 16
48
+ linear_units: 4096
49
+ num_blocks: 14
50
+ dropout_rate: 0.1
51
+ positional_dropout_rate: 0.1
52
+ attention_dropout_rate: 0.0
53
+ input_layer: 'linear_legacy'
54
+ pos_enc_layer_type: 'rel_pos_espnet'
55
+ selfattention_layer_type: 'rel_selfattn'
56
+ static_chunk_size: 1
57
+ sampling: !name:cosyvoice.utils.common.ras_sampling
58
+ top_p: 0.8
59
+ top_k: 25
60
+ win_size: 10
61
+ tau_r: 0.1
62
+
63
+ flow: !new:cosyvoice.flow.flow.MaskedDiffWithXvec
64
+ input_size: 512
65
+ output_size: 80
66
+ spk_embed_dim: !ref <spk_embed_dim>
67
+ output_type: 'mel'
68
+ vocab_size: 4096
69
+ input_frame_rate: 25
70
+ only_mask_loss: True
71
+ encoder: !new:cosyvoice.transformer.encoder.ConformerEncoder
72
+ output_size: 512
73
+ attention_heads: 8
74
+ linear_units: 2048
75
+ num_blocks: 6
76
+ dropout_rate: 0.1
77
+ positional_dropout_rate: 0.1
78
+ attention_dropout_rate: 0.1
79
+ normalize_before: True
80
+ input_layer: 'linear'
81
+ pos_enc_layer_type: 'rel_pos_espnet'
82
+ selfattention_layer_type: 'rel_selfattn'
83
+ input_size: 512
84
+ use_cnn_module: False
85
+ macaron_style: False
86
+ length_regulator: !new:cosyvoice.flow.length_regulator.InterpolateRegulator
87
+ channels: 80
88
+ sampling_ratios: [1, 1, 1, 1]
89
+ decoder: !new:cosyvoice.flow.flow_matching.ConditionalCFM
90
+ in_channels: 240
91
+ n_spks: 1
92
+ spk_emb_dim: 80
93
+ cfm_params: !new:omegaconf.DictConfig
94
+ content:
95
+ sigma_min: 1e-06
96
+ solver: 'euler'
97
+ t_scheduler: 'cosine'
98
+ training_cfg_rate: 0.2
99
+ inference_cfg_rate: 0.7
100
+ reg_loss_type: 'l1'
101
+ estimator: !new:cosyvoice.flow.decoder.ConditionalDecoder
102
+ in_channels: 320
103
+ out_channels: 80
104
+ channels: [256, 256]
105
+ dropout: 0.0
106
+ attention_head_dim: 64
107
+ n_blocks: 4
108
+ num_mid_blocks: 12
109
+ num_heads: 8
110
+ act_fn: 'gelu'
111
+
112
+ hift: !new:cosyvoice.hifigan.generator.HiFTGenerator
113
+ in_channels: 80
114
+ base_channels: 512
115
+ nb_harmonics: 8
116
+ sampling_rate: !ref <sample_rate>
117
+ nsf_alpha: 0.1
118
+ nsf_sigma: 0.003
119
+ nsf_voiced_threshold: 10
120
+ upsample_rates: [8, 8]
121
+ upsample_kernel_sizes: [16, 16]
122
+ istft_params:
123
+ n_fft: 16
124
+ hop_len: 4
125
+ resblock_kernel_sizes: [3, 7, 11]
126
+ resblock_dilation_sizes: [[1, 3, 5], [1, 3, 5], [1, 3, 5]]
127
+ source_resblock_kernel_sizes: [7, 11]
128
+ source_resblock_dilation_sizes: [[1, 3, 5], [1, 3, 5]]
129
+ lrelu_slope: 0.1
130
+ audio_limit: 0.99
131
+ f0_predictor: !new:cosyvoice.hifigan.f0_predictor.ConvRNNF0Predictor
132
+ num_class: 1
133
+ in_channels: 80
134
+ cond_channels: 512
135
+
136
+ # processor functions
137
+ parquet_opener: !name:cosyvoice.dataset.processor.parquet_opener
138
+ get_tokenizer: !name:cosyvoice.tokenizer.tokenizer.get_tokenizer
139
+ multilingual: True
140
+ num_languages: 100
141
+ language: 'en'
142
+ task: 'transcribe'
143
+ allowed_special: 'all'
144
+ tokenize: !name:cosyvoice.dataset.processor.tokenize
145
+ get_tokenizer: !ref <get_tokenizer>
146
+ allowed_special: !ref <allowed_special>
147
+ filter: !name:cosyvoice.dataset.processor.filter
148
+ max_length: 40960
149
+ min_length: 0
150
+ token_max_length: 200
151
+ token_min_length: 1
152
+ resample: !name:cosyvoice.dataset.processor.resample
153
+ resample_rate: !ref <sample_rate>
154
+ feat_extractor: !name:matcha.utils.audio.mel_spectrogram
155
+ n_fft: 1024
156
+ num_mels: 80
157
+ sampling_rate: !ref <sample_rate>
158
+ hop_size: 256
159
+ win_size: 1024
160
+ fmin: 0
161
+ fmax: 8000
162
+ center: False
163
+ compute_fbank: !name:cosyvoice.dataset.processor.compute_fbank
164
+ feat_extractor: !ref <feat_extractor>
165
+ parse_embedding: !name:cosyvoice.dataset.processor.parse_embedding
166
+ normalize: True
167
+ shuffle: !name:cosyvoice.dataset.processor.shuffle
168
+ shuffle_size: 1000
169
+ sort: !name:cosyvoice.dataset.processor.sort
170
+ sort_size: 500 # sort_size should be less than shuffle_size
171
+ batch: !name:cosyvoice.dataset.processor.batch
172
+ batch_type: 'dynamic'
173
+ max_frames_in_batch: 2000
174
+ padding: !name:cosyvoice.dataset.processor.padding
175
+
176
+ # dataset processor pipeline
177
+ data_pipeline: [
178
+ !ref <parquet_opener>,
179
+ !ref <tokenize>,
180
+ !ref <filter>,
181
+ !ref <resample>,
182
+ !ref <compute_fbank>,
183
+ !ref <parse_embedding>,
184
+ !ref <shuffle>,
185
+ !ref <sort>,
186
+ !ref <batch>,
187
+ !ref <padding>,
188
+ ]
189
+
190
+ # train conf
191
+ train_conf:
192
+ optim: adam
193
+ optim_conf:
194
+ lr: 0.001
195
+ scheduler: warmuplr
196
+ scheduler_conf:
197
+ warmup_steps: 2500
198
+ max_epoch: 200
199
+ grad_clip: 5
200
+ accum_grad: 2
201
+ log_interval: 100
202
+ save_per_step: -1
flow.decoder.estimator.fp32.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e37e81b4ab4c0c66d7c68fbe56da62b246c56254ecb72d8e9afd2770b8e34020
3
+ size 328627300
flow.encoder.fp32.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8c8e56b3153519bb319899f5a760f3ad7d689cb3703be3addd083204bfc22d34
3
+ size 103558803
flow.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1411de192039a21d53f0bf1968feb50586ce71d81ea1443f8163f4d1c46c5455
3
+ size 419901370
hift.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:91e679b6ca1eff71187ffb4f3ab0444935594cdcc20a9bd12afad111ef8d6012
3
+ size 81896716
llm.llm.fp16.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b1514cfbfa5e0a56eee93c55a4a576ad859ccc042194f129880c37d710dec757
3
+ size 809092215
llm.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:23bc18a6d53b516868c7827fdedfd86df16642913e168ed6949fe07464c7d6ae
3
+ size 1260708412
llm.text_encoder.fp16.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4e564b954897af8abd013c33a21e29de6eb9d5cb5afdb6bd84e7e4be968985ff
3
+ size 205829251
speech_tokenizer_v1.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:56285ddd4a83e883ee0cb9f8d69c1089b53a94b1f78ff7e4a0224a27eb4cb486
3
+ size 522625011
spk2info.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e3b1d62ca87cdcb25a9003fa0c8f2cba5c94f55b0d5f80f0b63ef8c22d919cfc
3
+ size 7772