MCPcopy Create free account
hub / github.com/MoonInTheRiver/DiffSinger / __getitem__

Method __getitem__

tasks/tts/fs2_utils.py:60–103  ·  view source on GitHub ↗
(self, index)

Source from the content-addressed store, hash-verified

58 return self.indexed_ds[index]
59
60 def __getitem__(self, index):
61 hparams = self.hparams
62 item = self._get_item(index)
63 max_frames = hparams['max_frames']
64 spec = torch.Tensor(item['mel'])[:max_frames]
65 energy = (spec.exp() ** 2).sum(-1).sqrt()
66 mel2ph = torch.LongTensor(item['mel2ph'])[:max_frames] if 'mel2ph' in item else None
67 f0, uv = norm_interp_f0(item["f0"][:max_frames], hparams)
68 phone = torch.LongTensor(item['phone'][:hparams['max_input_tokens']])
69 pitch = torch.LongTensor(item.get("pitch"))[:max_frames]
70 # print(item.keys(), item['mel'].shape, spec.shape)
71 sample = {
72 "id": index,
73 "item_name": item['item_name'],
74 "text": item['txt'],
75 "txt_token": phone,
76 "mel": spec,
77 "pitch": pitch,
78 "energy": energy,
79 "f0": f0,
80 "uv": uv,
81 "mel2ph": mel2ph,
82 "mel_nonpadding": spec.abs().sum(-1) > 0,
83 }
84 if self.hparams['use_spk_embed']:
85 sample["spk_embed"] = torch.Tensor(item['spk_embed'])
86 if self.hparams['use_spk_id']:
87 sample["spk_id"] = item['spk_id']
88 # sample['spk_id'] = 0
89 # for key in self.name2spk_id.keys():
90 # if key in item['item_name']:
91 # sample['spk_id'] = self.name2spk_id[key]
92 # break
93 if self.hparams['pitch_type'] == 'cwt':
94 cwt_spec = torch.Tensor(item['cwt_spec'])[:max_frames]
95 f0_mean = item.get('f0_mean', item.get('cwt_mean'))
96 f0_std = item.get('f0_std', item.get('cwt_std'))
97 sample.update({"cwt_spec": cwt_spec, "f0_mean": f0_mean, "f0_std": f0_std})
98 elif self.hparams['pitch_type'] == 'ph':
99 f0_phlevel_sum = torch.zeros_like(phone).float().scatter_add(0, mel2ph - 1, f0)
100 f0_phlevel_num = torch.zeros_like(phone).float().scatter_add(
101 0, mel2ph - 1, torch.ones_like(f0)).clamp_min(1)
102 sample["f0_ph"] = f0_phlevel_sum / f0_phlevel_num
103 return sample
104
105 def collater(self, samples):
106 if len(samples) == 0:

Callers

nothing calls this directly

Calls 3

_get_itemMethod · 0.95
norm_interp_f0Function · 0.90
updateMethod · 0.80

Tested by

no test coverage detected