CosyVoice commited on
Commit
0d487c6
1 Parent(s): 4ee072d
Files changed (2) hide show
  1. README.md +224 -3
  2. asset/dingding.png +0 -0
README.md CHANGED
@@ -1,3 +1,224 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CosyVoice
2
+
3
+ ## 👉🏻 [CosyVoice2 Demos](https://funaudiollm.github.io/cosyvoice2/) 👈🏻
4
+ [[CosyVoice2 Paper](https://fun-audio-llm.github.io/pdf/CosyVoice_v1.pdf)][[CosyVoice2 Studio](https://www.modelscope.cn/studios/iic/CosyVoice2-0.5B)]
5
+
6
+ ## 👉🏻 [CosyVoice Demos](https://fun-audio-llm.github.io/) 👈🏻
7
+ [[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)]
8
+
9
+ For `SenseVoice`, visit [SenseVoice repo](https://github.com/FunAudioLLM/SenseVoice) and [SenseVoice space](https://www.modelscope.cn/studios/iic/SenseVoice).
10
+
11
+ ## Roadmap
12
+
13
+ - [x] 2024/12
14
+
15
+ - [x] CosyVoice2-0.5B model release
16
+ - [x] CosyVoice2-0.5B streaming inference with no quality degradation
17
+
18
+ - [x] 2024/07
19
+
20
+ - [x] Flow matching training support
21
+ - [x] WeTextProcessing support when ttsfrd is not avaliable
22
+ - [x] Fastapi server and client
23
+
24
+ - [x] 2024/08
25
+
26
+ - [x] Repetition Aware Sampling(RAS) inference for llm stability
27
+ - [x] Streaming inference mode support, including kv cache and sdpa for rtf optimization
28
+
29
+ - [x] 2024/09
30
+
31
+ - [x] 25hz cosyvoice base model
32
+ - [x] 25hz cosyvoice voice conversion model
33
+
34
+ - [ ] TBD
35
+
36
+ - [ ] CosyVoice2-0.5B bistream inference support
37
+ - [ ] CosyVoice2-0.5B training and finetune recipie
38
+ - [ ] CosyVoice-500M trained with more multi-lingual data
39
+ - [ ] More...
40
+
41
+ ## Install
42
+
43
+ **Clone and install**
44
+
45
+ - Clone the repo
46
+ ``` sh
47
+ git clone --recursive https://github.com/FunAudioLLM/CosyVoice.git
48
+ # If you failed to clone submodule due to network failures, please run following command until success
49
+ cd CosyVoice
50
+ git submodule update --init --recursive
51
+ ```
52
+
53
+ - Install Conda: please see https://docs.conda.io/en/latest/miniconda.html
54
+ - Create Conda env:
55
+
56
+ ``` sh
57
+ conda create -n cosyvoice python=3.10
58
+ conda activate cosyvoice
59
+ # pynini is required by WeTextProcessing, use conda to install it as it can be executed on all platform.
60
+ conda install -y -c conda-forge pynini==2.1.5
61
+ pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com
62
+
63
+ # If you encounter sox compatibility issues
64
+ # ubuntu
65
+ sudo apt-get install sox libsox-dev
66
+ # centos
67
+ sudo yum install sox sox-devel
68
+ ```
69
+
70
+ **Model download**
71
+
72
+ We strongly recommend that you download our pretrained `CosyVoice-300M` `CosyVoice-300M-SFT` `CosyVoice-300M-Instruct` model and `CosyVoice-ttsfrd` resource.
73
+
74
+ 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.
75
+
76
+ ``` python
77
+ # SDK模型下载
78
+ from modelscope import snapshot_download
79
+ snapshot_download('iic/CosyVoice2-0.5B', local_dir='pretrained_models/CosyVoice2-0.5B')
80
+ snapshot_download('iic/CosyVoice-300M', local_dir='pretrained_models/CosyVoice-300M')
81
+ snapshot_download('iic/CosyVoice-300M-25Hz', local_dir='pretrained_models/CosyVoice-300M-25Hz')
82
+ snapshot_download('iic/CosyVoice-300M-SFT', local_dir='pretrained_models/CosyVoice-300M-SFT')
83
+ snapshot_download('iic/CosyVoice-300M-Instruct', local_dir='pretrained_models/CosyVoice-300M-Instruct')
84
+ snapshot_download('iic/CosyVoice-ttsfrd', local_dir='pretrained_models/CosyVoice-ttsfrd')
85
+ ```
86
+
87
+ ``` sh
88
+ # git模型下载,请确保已安装git lfs
89
+ mkdir -p pretrained_models
90
+ git clone https://www.modelscope.cn/iic/CosyVoice2-0.5B.git pretrained_models/CosyVoice2-0.5B
91
+ git clone https://www.modelscope.cn/iic/CosyVoice-300M.git pretrained_models/CosyVoice-300M
92
+ git clone https://www.modelscope.cn/iic/CosyVoice-300M-25Hz.git pretrained_models/CosyVoice-300M-25Hz
93
+ git clone https://www.modelscope.cn/iic/CosyVoice-300M-SFT.git pretrained_models/CosyVoice-300M-SFT
94
+ git clone https://www.modelscope.cn/iic/CosyVoice-300M-Instruct.git pretrained_models/CosyVoice-300M-Instruct
95
+ git clone https://www.modelscope.cn/iic/CosyVoice-ttsfrd.git pretrained_models/CosyVoice-ttsfrd
96
+ ```
97
+
98
+ Optionaly, you can unzip `ttsfrd` resouce and install `ttsfrd` package for better text normalization performance.
99
+
100
+ Notice that this step is not necessary. If you do not install `ttsfrd` package, we will use WeTextProcessing by default.
101
+
102
+ ``` sh
103
+ cd pretrained_models/CosyVoice-ttsfrd/
104
+ unzip resource.zip -d .
105
+ pip install ttsfrd-0.3.6-cp38-cp38-linux_x86_64.whl
106
+ ```
107
+
108
+ **Basic Usage**
109
+
110
+ For zero_shot/cross_lingual inference, please use `CosyVoice2-0.5B` or `CosyVoice-300M` model.
111
+ For sft inference, please use `CosyVoice-300M-SFT` model.
112
+ For instruct inference, please use `CosyVoice-300M-Instruct` model.
113
+ We strongly recommend using `CosyVoice2-0.5B` model for better streaming performance.
114
+
115
+ First, add `third_party/Matcha-TTS` to your `PYTHONPATH`.
116
+
117
+ ``` sh
118
+ export PYTHONPATH=third_party/Matcha-TTS
119
+ ```
120
+
121
+ ``` python
122
+ from cosyvoice.cli.cosyvoice import CosyVoice, CosyVoice2
123
+ from cosyvoice.utils.file_utils import load_wav
124
+ import torchaudio
125
+
126
+ ## cosyvoice2 usage
127
+ cosyvoice2 = CosyVoice('pretrained_models/CosyVoice-300M-SFT', load_jit=False, load_onnx=False, load_trt=False)
128
+ # sft usage
129
+ prompt_speech_16k = load_wav('zero_shot_prompt.wav', 16000)
130
+ for i, j in enumerate(cosyvoice2.inference_zero_shot('收到好友从远方寄来的生日礼物,那份意外的惊喜与深深的祝福让我心中充满了甜蜜的快乐,笑容如花儿般绽放。', '希望你以后能够做的比我还好呦。', prompt_speech_16k, stream=True)):
131
+ torchaudio.save('zero_shot_{}.wav'.format(i), j['tts_speech'], cosyvoice2.sample_rate)
132
+
133
+ ## cosyvoice usage
134
+ cosyvoice = CosyVoice('pretrained_models/CosyVoice-300M-SFT', load_jit=True, load_onnx=False, fp16=True)
135
+ # sft usage
136
+ print(cosyvoice.list_avaliable_spks())
137
+ # change stream=True for chunk stream inference
138
+ for i, j in enumerate(cosyvoice.inference_sft('你好,我是通义生成式语音大模型,请问有什么可以帮您的吗?', '中文女', stream=False)):
139
+ torchaudio.save('sft_{}.wav'.format(i), j['tts_speech'], cosyvoice.sample_rate)
140
+
141
+ cosyvoice = CosyVoice('pretrained_models/CosyVoice-300M-25Hz') # or change to pretrained_models/CosyVoice-300M for 50Hz inference
142
+ # zero_shot usage, <|zh|><|en|><|jp|><|yue|><|ko|> for Chinese/English/Japanese/Cantonese/Korean
143
+ prompt_speech_16k = load_wav('zero_shot_prompt.wav', 16000)
144
+ for i, j in enumerate(cosyvoice.inference_zero_shot('收到好友从远方寄来的生日礼物,那份意外的惊喜与深深的祝福让我心中充满了甜蜜的快乐,笑容如花儿般绽放。', '希望你以后能够做的比我还好呦。', prompt_speech_16k, stream=False)):
145
+ torchaudio.save('zero_shot_{}.wav'.format(i), j['tts_speech'], cosyvoice.sample_rate)
146
+ # cross_lingual usage
147
+ prompt_speech_16k = load_wav('cross_lingual_prompt.wav', 16000)
148
+ 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)):
149
+ torchaudio.save('cross_lingual_{}.wav'.format(i), j['tts_speech'], cosyvoice.sample_rate)
150
+ # vc usage
151
+ prompt_speech_16k = load_wav('zero_shot_prompt.wav', 16000)
152
+ source_speech_16k = load_wav('cross_lingual_prompt.wav', 16000)
153
+ for i, j in enumerate(cosyvoice.inference_vc(source_speech_16k, prompt_speech_16k, stream=False)):
154
+ torchaudio.save('vc_{}.wav'.format(i), j['tts_speech'], cosyvoice.sample_rate)
155
+
156
+ cosyvoice = CosyVoice('pretrained_models/CosyVoice-300M-Instruct')
157
+ # instruct usage, support <laughter></laughter><strong></strong>[laughter][breath]
158
+ 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)):
159
+ torchaudio.save('instruct_{}.wav'.format(i), j['tts_speech'], cosyvoice.sample_rate)
160
+ ```
161
+
162
+ **Start web demo**
163
+
164
+ You can use our web demo page to get familiar with CosyVoice quickly.
165
+ We support sft/zero_shot/cross_lingual/instruct inference in web demo.
166
+
167
+ Please see the demo website for details.
168
+
169
+ ``` python
170
+ # change iic/CosyVoice-300M-SFT for sft inference, or iic/CosyVoice-300M-Instruct for instruct inference
171
+ python3 webui.py --port 50000 --model_dir pretrained_models/CosyVoice-300M
172
+ ```
173
+
174
+ **Advanced Usage**
175
+
176
+ For advanced user, we have provided train and inference scripts in `examples/libritts/cosyvoice/run.sh`.
177
+ You can get familiar with CosyVoice following this recipie.
178
+
179
+ **Build for deployment**
180
+
181
+ Optionally, if you want to use grpc for service deployment,
182
+ you can run following steps. Otherwise, you can just ignore this step.
183
+
184
+ ``` sh
185
+ cd runtime/python
186
+ docker build -t cosyvoice:v1.0 .
187
+ # change iic/CosyVoice-300M to iic/CosyVoice-300M-Instruct if you want to use instruct inference
188
+ # for grpc usage
189
+ 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"
190
+ cd grpc && python3 client.py --port 50000 --mode <sft|zero_shot|cross_lingual|instruct>
191
+ # for fastapi usage
192
+ docker run -d --runtime=nvidia -p 50000:50000 cosyvoice:v1.0 /bin/bash -c "cd /opt/CosyVoice/CosyVoice/runtime/python/fastapi && python3 server.py --port 50000 --model_dir iic/CosyVoice-300M && sleep infinity"
193
+ cd fastapi && python3 client.py --port 50000 --mode <sft|zero_shot|cross_lingual|instruct>
194
+ ```
195
+
196
+ ## Discussion & Communication
197
+
198
+ You can directly discuss on [Github Issues](https://github.com/FunAudioLLM/CosyVoice/issues).
199
+
200
+ You can also scan the QR code to join our official Dingding chat group.
201
+
202
+ <img src="./asset/dingding.png" width="250px">
203
+
204
+ ## Acknowledge
205
+
206
+ 1. We borrowed a lot of code from [FunASR](https://github.com/modelscope/FunASR).
207
+ 2. We borrowed a lot of code from [FunCodec](https://github.com/modelscope/FunCodec).
208
+ 3. We borrowed a lot of code from [Matcha-TTS](https://github.com/shivammehta25/Matcha-TTS).
209
+ 4. We borrowed a lot of code from [AcademiCodec](https://github.com/yangdongchao/AcademiCodec).
210
+ 5. We borrowed a lot of code from [WeNet](https://github.com/wenet-e2e/wenet).
211
+
212
+ ## Citations
213
+
214
+ ``` bibtex
215
+ @article{du2024cosyvoice,
216
+ title={Cosyvoice: A scalable multilingual zero-shot text-to-speech synthesizer based on supervised semantic tokens},
217
+ author={Du, Zhihao and Chen, Qian and Zhang, Shiliang and Hu, Kai and Lu, Heng and Yang, Yexin and Hu, Hangrui and Zheng, Siqi and Gu, Yue and Ma, Ziyang and others},
218
+ journal={arXiv preprint arXiv:2407.05407},
219
+ year={2024}
220
+ }
221
+ ```
222
+
223
+ ## Disclaimer
224
+ 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.
asset/dingding.png ADDED