Spaces:
Running
on
Zero
Running
on
Zero
Merge pull request #453 from FunAudioLLM/dev/lyuxiang.lx
Browse files- cosyvoice/cli/frontend.py +2 -2
- cosyvoice/cli/model.py +3 -6
- cosyvoice/llm/llm.py +1 -1
- cosyvoice/utils/frontend_utils.py +8 -5
- examples/libritts/cosyvoice/conf/cosyvoice.fromscratch.yaml +3 -3
- examples/libritts/cosyvoice/conf/cosyvoice.yaml +3 -3
- examples/magicdata-read/cosyvoice/conf/cosyvoice.fromscratch.yaml +8 -3
- examples/magicdata-read/cosyvoice/conf/cosyvoice.yaml +8 -3
cosyvoice/cli/frontend.py
CHANGED
@@ -118,10 +118,10 @@ class CosyVoiceFrontEnd:
|
|
118 |
text = text.replace("\n", "")
|
119 |
text = replace_blank(text)
|
120 |
text = replace_corner_mark(text)
|
121 |
-
text = text.replace(".", "
|
122 |
text = text.replace(" - ", ",")
|
123 |
text = remove_bracket(text)
|
124 |
-
text = re.sub(r'[
|
125 |
texts = list(split_paragraph(text, partial(self.tokenizer.encode, allowed_special=self.allowed_special), "zh", token_max_n=80,
|
126 |
token_min_n=60, merge_len=20, comma_split=False))
|
127 |
else:
|
|
|
118 |
text = text.replace("\n", "")
|
119 |
text = replace_blank(text)
|
120 |
text = replace_corner_mark(text)
|
121 |
+
text = text.replace(".", "。")
|
122 |
text = text.replace(" - ", ",")
|
123 |
text = remove_bracket(text)
|
124 |
+
text = re.sub(r'[,,、]+$', '。', text)
|
125 |
texts = list(split_paragraph(text, partial(self.tokenizer.encode, allowed_special=self.allowed_special), "zh", token_max_n=80,
|
126 |
token_min_n=60, merge_len=20, comma_split=False))
|
127 |
else:
|
cosyvoice/cli/model.py
CHANGED
@@ -31,8 +31,8 @@ class CosyVoiceModel:
|
|
31 |
self.llm = llm
|
32 |
self.flow = flow
|
33 |
self.hift = hift
|
34 |
-
self.token_min_hop_len =
|
35 |
-
self.token_max_hop_len =
|
36 |
self.token_overlap_len = 20
|
37 |
# mel fade in out
|
38 |
self.mel_overlap_len = int(self.token_overlap_len / self.flow.input_frame_rate * 22050 / 256)
|
@@ -87,10 +87,7 @@ class CosyVoiceModel:
|
|
87 |
prompt_text_len=torch.tensor([prompt_text.shape[1]], dtype=torch.int32).to(self.device),
|
88 |
prompt_speech_token=llm_prompt_speech_token.to(self.device),
|
89 |
prompt_speech_token_len=torch.tensor([llm_prompt_speech_token.shape[1]], dtype=torch.int32).to(self.device),
|
90 |
-
embedding=llm_embedding.to(self.device).half()
|
91 |
-
sampling=25,
|
92 |
-
max_token_text_ratio=30,
|
93 |
-
min_token_text_ratio=3):
|
94 |
self.tts_speech_token_dict[uuid].append(i)
|
95 |
self.llm_end_dict[uuid] = True
|
96 |
|
|
|
31 |
self.llm = llm
|
32 |
self.flow = flow
|
33 |
self.hift = hift
|
34 |
+
self.token_min_hop_len = 2 * self.flow.input_frame_rate
|
35 |
+
self.token_max_hop_len = 4 * self.flow.input_frame_rate
|
36 |
self.token_overlap_len = 20
|
37 |
# mel fade in out
|
38 |
self.mel_overlap_len = int(self.token_overlap_len / self.flow.input_frame_rate * 22050 / 256)
|
|
|
87 |
prompt_text_len=torch.tensor([prompt_text.shape[1]], dtype=torch.int32).to(self.device),
|
88 |
prompt_speech_token=llm_prompt_speech_token.to(self.device),
|
89 |
prompt_speech_token_len=torch.tensor([llm_prompt_speech_token.shape[1]], dtype=torch.int32).to(self.device),
|
90 |
+
embedding=llm_embedding.to(self.device).half()):
|
|
|
|
|
|
|
91 |
self.tts_speech_token_dict[uuid].append(i)
|
92 |
self.llm_end_dict[uuid] = True
|
93 |
|
cosyvoice/llm/llm.py
CHANGED
@@ -197,7 +197,7 @@ class TransformerLM(torch.nn.Module):
|
|
197 |
offset = 0
|
198 |
att_cache, cnn_cache = torch.zeros((0, 0, 0, 0), device=lm_input.device), torch.zeros((0, 0, 0, 0), device=lm_input.device)
|
199 |
for i in range(max_len):
|
200 |
-
y_pred, att_cache, cnn_cache = self.llm.forward_chunk(lm_input, offset=
|
201 |
att_cache=att_cache, cnn_cache=cnn_cache,
|
202 |
att_mask=torch.tril(torch.ones((1, lm_input.shape[1], lm_input.shape[1]),
|
203 |
device=lm_input.device)).to(torch.bool))
|
|
|
197 |
offset = 0
|
198 |
att_cache, cnn_cache = torch.zeros((0, 0, 0, 0), device=lm_input.device), torch.zeros((0, 0, 0, 0), device=lm_input.device)
|
199 |
for i in range(max_len):
|
200 |
+
y_pred, att_cache, cnn_cache = self.llm.forward_chunk(lm_input, offset=offset, required_cache_size=-1,
|
201 |
att_cache=att_cache, cnn_cache=cnn_cache,
|
202 |
att_mask=torch.tril(torch.ones((1, lm_input.shape[1], lm_input.shape[1]),
|
203 |
device=lm_input.device)).to(torch.bool))
|
cosyvoice/utils/frontend_utils.py
CHANGED
@@ -80,6 +80,13 @@ def split_paragraph(text: str, tokenize, lang="zh", token_max_n=80, token_min_n=
|
|
80 |
pounc = ['.', '?', '!', ';', ':']
|
81 |
if comma_split:
|
82 |
pounc.extend([',', ','])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
st = 0
|
84 |
utts = []
|
85 |
for i, c in enumerate(text):
|
@@ -92,11 +99,7 @@ def split_paragraph(text: str, tokenize, lang="zh", token_max_n=80, token_min_n=
|
|
92 |
st = i + 2
|
93 |
else:
|
94 |
st = i + 1
|
95 |
-
|
96 |
-
if lang == "zh":
|
97 |
-
utts.append(text + '。')
|
98 |
-
else:
|
99 |
-
utts.append(text + '.')
|
100 |
final_utts = []
|
101 |
cur_utt = ""
|
102 |
for utt in utts:
|
|
|
80 |
pounc = ['.', '?', '!', ';', ':']
|
81 |
if comma_split:
|
82 |
pounc.extend([',', ','])
|
83 |
+
|
84 |
+
if text[-1] not in pounc:
|
85 |
+
if lang == "zh":
|
86 |
+
text += "。"
|
87 |
+
else:
|
88 |
+
text += "."
|
89 |
+
|
90 |
st = 0
|
91 |
utts = []
|
92 |
for i, c in enumerate(text):
|
|
|
99 |
st = i + 2
|
100 |
else:
|
101 |
st = i + 1
|
102 |
+
|
|
|
|
|
|
|
|
|
103 |
final_utts = []
|
104 |
cur_utt = ""
|
105 |
for utt in utts:
|
examples/libritts/cosyvoice/conf/cosyvoice.fromscratch.yaml
CHANGED
@@ -18,7 +18,7 @@ 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: 51866
|
22 |
speech_token_size: 4096
|
23 |
length_normalized_loss: True
|
24 |
lsm_weight: 0
|
@@ -66,7 +66,7 @@ flow: !new:cosyvoice.flow.flow.MaskedDiffWithXvec
|
|
66 |
spk_embed_dim: !ref <spk_embed_dim>
|
67 |
output_type: 'mel'
|
68 |
vocab_size: 4096
|
69 |
-
input_frame_rate: 50
|
70 |
only_mask_loss: True
|
71 |
encoder: !new:cosyvoice.transformer.encoder.ConformerEncoder
|
72 |
output_size: 512
|
@@ -135,7 +135,7 @@ hift: !new:cosyvoice.hifigan.generator.HiFTGenerator
|
|
135 |
|
136 |
# processor functions
|
137 |
parquet_opener: !name:cosyvoice.dataset.processor.parquet_opener
|
138 |
-
get_tokenizer: !name:whisper.tokenizer.get_tokenizer
|
139 |
multilingual: True
|
140 |
num_languages: 100
|
141 |
language: 'en'
|
|
|
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: 51866 # change to 60515 if you want to train with CosyVoice-300M-25Hz recipe
|
22 |
speech_token_size: 4096
|
23 |
length_normalized_loss: True
|
24 |
lsm_weight: 0
|
|
|
66 |
spk_embed_dim: !ref <spk_embed_dim>
|
67 |
output_type: 'mel'
|
68 |
vocab_size: 4096
|
69 |
+
input_frame_rate: 50 # change to 25 if you want to train with CosyVoice-300M-25Hz recipe
|
70 |
only_mask_loss: True
|
71 |
encoder: !new:cosyvoice.transformer.encoder.ConformerEncoder
|
72 |
output_size: 512
|
|
|
135 |
|
136 |
# processor functions
|
137 |
parquet_opener: !name:cosyvoice.dataset.processor.parquet_opener
|
138 |
+
get_tokenizer: !name:whisper.tokenizer.get_tokenizer # change to !name:cosyvoice.tokenizer.tokenizer.get_tokenizer if you want to train with CosyVoice-300M-25Hz recipe
|
139 |
multilingual: True
|
140 |
num_languages: 100
|
141 |
language: 'en'
|
examples/libritts/cosyvoice/conf/cosyvoice.yaml
CHANGED
@@ -18,7 +18,7 @@ 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: 51866
|
22 |
speech_token_size: 4096
|
23 |
length_normalized_loss: True
|
24 |
lsm_weight: 0
|
@@ -66,7 +66,7 @@ flow: !new:cosyvoice.flow.flow.MaskedDiffWithXvec
|
|
66 |
spk_embed_dim: !ref <spk_embed_dim>
|
67 |
output_type: 'mel'
|
68 |
vocab_size: 4096
|
69 |
-
input_frame_rate: 50
|
70 |
only_mask_loss: True
|
71 |
encoder: !new:cosyvoice.transformer.encoder.ConformerEncoder
|
72 |
output_size: 512
|
@@ -135,7 +135,7 @@ hift: !new:cosyvoice.hifigan.generator.HiFTGenerator
|
|
135 |
|
136 |
# processor functions
|
137 |
parquet_opener: !name:cosyvoice.dataset.processor.parquet_opener
|
138 |
-
get_tokenizer: !name:whisper.tokenizer.get_tokenizer
|
139 |
multilingual: True
|
140 |
num_languages: 100
|
141 |
language: 'en'
|
|
|
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: 51866 # change to 60515 if you want to train with CosyVoice-300M-25Hz recipe
|
22 |
speech_token_size: 4096
|
23 |
length_normalized_loss: True
|
24 |
lsm_weight: 0
|
|
|
66 |
spk_embed_dim: !ref <spk_embed_dim>
|
67 |
output_type: 'mel'
|
68 |
vocab_size: 4096
|
69 |
+
input_frame_rate: 50 # change to 25 if you want to train with CosyVoice-300M-25Hz recipe
|
70 |
only_mask_loss: True
|
71 |
encoder: !new:cosyvoice.transformer.encoder.ConformerEncoder
|
72 |
output_size: 512
|
|
|
135 |
|
136 |
# processor functions
|
137 |
parquet_opener: !name:cosyvoice.dataset.processor.parquet_opener
|
138 |
+
get_tokenizer: !name:whisper.tokenizer.get_tokenizer # change to !name:cosyvoice.tokenizer.tokenizer.get_tokenizer if you want to train with CosyVoice-300M-25Hz recipe
|
139 |
multilingual: True
|
140 |
num_languages: 100
|
141 |
language: 'en'
|
examples/magicdata-read/cosyvoice/conf/cosyvoice.fromscratch.yaml
CHANGED
@@ -18,7 +18,7 @@ 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: 51866
|
22 |
speech_token_size: 4096
|
23 |
length_normalized_loss: True
|
24 |
lsm_weight: 0
|
@@ -54,6 +54,11 @@ llm: !new:cosyvoice.llm.llm.TransformerLM
|
|
54 |
pos_enc_layer_type: 'rel_pos_espnet'
|
55 |
selfattention_layer_type: 'rel_selfattn'
|
56 |
static_chunk_size: 1
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
flow: !new:cosyvoice.flow.flow.MaskedDiffWithXvec
|
59 |
input_size: 512
|
@@ -61,7 +66,7 @@ flow: !new:cosyvoice.flow.flow.MaskedDiffWithXvec
|
|
61 |
spk_embed_dim: !ref <spk_embed_dim>
|
62 |
output_type: 'mel'
|
63 |
vocab_size: 4096
|
64 |
-
input_frame_rate: 50
|
65 |
only_mask_loss: True
|
66 |
encoder: !new:cosyvoice.transformer.encoder.ConformerEncoder
|
67 |
output_size: 512
|
@@ -130,7 +135,7 @@ hift: !new:cosyvoice.hifigan.generator.HiFTGenerator
|
|
130 |
|
131 |
# processor functions
|
132 |
parquet_opener: !name:cosyvoice.dataset.processor.parquet_opener
|
133 |
-
get_tokenizer: !name:whisper.tokenizer.get_tokenizer
|
134 |
multilingual: True
|
135 |
num_languages: 100
|
136 |
language: 'en'
|
|
|
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: 51866 # change to 60515 if you want to train with CosyVoice-300M-25Hz recipe
|
22 |
speech_token_size: 4096
|
23 |
length_normalized_loss: True
|
24 |
lsm_weight: 0
|
|
|
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
|
|
|
66 |
spk_embed_dim: !ref <spk_embed_dim>
|
67 |
output_type: 'mel'
|
68 |
vocab_size: 4096
|
69 |
+
input_frame_rate: 50 # change to 25 if you want to train with CosyVoice-300M-25Hz recipe
|
70 |
only_mask_loss: True
|
71 |
encoder: !new:cosyvoice.transformer.encoder.ConformerEncoder
|
72 |
output_size: 512
|
|
|
135 |
|
136 |
# processor functions
|
137 |
parquet_opener: !name:cosyvoice.dataset.processor.parquet_opener
|
138 |
+
get_tokenizer: !name:whisper.tokenizer.get_tokenizer # change to !name:cosyvoice.tokenizer.tokenizer.get_tokenizer if you want to train with CosyVoice-300M-25Hz recipe
|
139 |
multilingual: True
|
140 |
num_languages: 100
|
141 |
language: 'en'
|
examples/magicdata-read/cosyvoice/conf/cosyvoice.yaml
CHANGED
@@ -18,7 +18,7 @@ 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: 51866
|
22 |
speech_token_size: 4096
|
23 |
length_normalized_loss: True
|
24 |
lsm_weight: 0
|
@@ -54,6 +54,11 @@ llm: !new:cosyvoice.llm.llm.TransformerLM
|
|
54 |
pos_enc_layer_type: 'rel_pos_espnet'
|
55 |
selfattention_layer_type: 'rel_selfattn'
|
56 |
static_chunk_size: 1
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
flow: !new:cosyvoice.flow.flow.MaskedDiffWithXvec
|
59 |
input_size: 512
|
@@ -61,7 +66,7 @@ flow: !new:cosyvoice.flow.flow.MaskedDiffWithXvec
|
|
61 |
spk_embed_dim: !ref <spk_embed_dim>
|
62 |
output_type: 'mel'
|
63 |
vocab_size: 4096
|
64 |
-
input_frame_rate: 50
|
65 |
only_mask_loss: True
|
66 |
encoder: !new:cosyvoice.transformer.encoder.ConformerEncoder
|
67 |
output_size: 512
|
@@ -130,7 +135,7 @@ hift: !new:cosyvoice.hifigan.generator.HiFTGenerator
|
|
130 |
|
131 |
# processor functions
|
132 |
parquet_opener: !name:cosyvoice.dataset.processor.parquet_opener
|
133 |
-
get_tokenizer: !name:whisper.tokenizer.get_tokenizer
|
134 |
multilingual: True
|
135 |
num_languages: 100
|
136 |
language: 'en'
|
|
|
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: 51866 # change to 60515 if you want to train with CosyVoice-300M-25Hz recipe
|
22 |
speech_token_size: 4096
|
23 |
length_normalized_loss: True
|
24 |
lsm_weight: 0
|
|
|
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
|
|
|
66 |
spk_embed_dim: !ref <spk_embed_dim>
|
67 |
output_type: 'mel'
|
68 |
vocab_size: 4096
|
69 |
+
input_frame_rate: 50 # change to 25 if you want to train with CosyVoice-300M-25Hz recipe
|
70 |
only_mask_loss: True
|
71 |
encoder: !new:cosyvoice.transformer.encoder.ConformerEncoder
|
72 |
output_size: 512
|
|
|
135 |
|
136 |
# processor functions
|
137 |
parquet_opener: !name:cosyvoice.dataset.processor.parquet_opener
|
138 |
+
get_tokenizer: !name:whisper.tokenizer.get_tokenizer # change to !name:cosyvoice.tokenizer.tokenizer.get_tokenizer if you want to train with CosyVoice-300M-25Hz recipe
|
139 |
multilingual: True
|
140 |
num_languages: 100
|
141 |
language: 'en'
|