fix: when text and word2ph is empty, get_bert_feature will not crash but return an empty tensor

This commit is contained in:
Jacky He 2025-08-09 18:26:25 +08:00
parent fdf794e31d
commit 5285786b57

View File

@ -180,6 +180,8 @@ def get_bert_feature(text, word2ph):
for i in range(len(word2ph)): for i in range(len(word2ph)):
repeat_feature = res[i].repeat(word2ph[i], 1) repeat_feature = res[i].repeat(word2ph[i], 1)
phone_level_feature.append(repeat_feature) phone_level_feature.append(repeat_feature)
if len(phone_level_feature) == 0:
return torch.empty((res.shape[1], 0), dtype=res.dtype, device=res.device)
phone_level_feature = torch.cat(phone_level_feature, dim=0) phone_level_feature = torch.cat(phone_level_feature, dim=0)
return phone_level_feature.T return phone_level_feature.T