(self, index)
| 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: |
nothing calls this directly
no test coverage detected