Skip to content

Commit f6a8c80

Browse files
author
刘柏基
committed
[feature] modify pad to trim
1 parent 4ce31ca commit f6a8c80

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

cosyvoice/dataset/processor.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,10 @@ def compute_fbank(data,
177177
waveform = sample['speech']
178178
feat = feat_extractor(waveform).squeeze(dim=0).transpose(0, 1)
179179

180-
# padding with replicate mode (align to speech_token len * token_mel_ratio)
181-
pad_len = sample["speech_token"].shape[0] * token_mel_ratio - feat.shape[0]
182-
if pad_len > 0:
183-
feat_to_pad = feat[-1:].repeat((pad_len, 1))
184-
feat = torch.cat([feat, feat_to_pad], dim=0)
180+
# trim to align speech_token and speech_feat
181+
token_len = min(feat.shape[0] // token_mel_ratio, sample["speech_token"].shape[0])
182+
feat = feat[:token_mel_ratio * token_len]
183+
sample["speech_token"] = sample["speech_token"][:token_len]
185184

186185
sample['speech_feat'] = feat
187186
yield sample

0 commit comments

Comments
 (0)