修复cosyvoice2的flow合成前后爆音
Author: deyituoCreated Mar 7, 2025Updated Sep 14, 2026
CausalMaskedDiffWithXvec forward() 开头修改为:
token = batch['speech_token'].to(device)
token_len = batch['speech_token_len'].to(device)
feat = batch['speech_feat'].to(device)
feat_len = batch['speech_feat_len'].to(device)
embedding = batch['embedding'].to(device)
token_len = torch.minimum(token_len, feat_len.int() // self.token_mel_ratio)
feat_len = (token_len * self.token_mel_ratio).int()
token = token[:, :token_len.max()].contiguous()
feat = feat[:, :feat_len.max(), :].contiguous()
assert feat.size(1) == token.size(1) * self.token_mel_ratio, f"feat: {feat.size()}, token: {token.size()}"
Source: QwenAudio/CosyVoice