(self, prefix)
| 121 | self.process_data('train') |
| 122 | |
| 123 | def process_data(self, prefix): |
| 124 | data_dir = hparams['binary_data_dir'] |
| 125 | args = [] |
| 126 | builder = IndexedDatasetBuilder(f'{data_dir}/{prefix}') |
| 127 | lengths = [] |
| 128 | f0s = [] |
| 129 | total_sec = 0 |
| 130 | if self.binarization_args['with_spk_embed']: |
| 131 | voice_encoder = VoiceEncoder().cuda() |
| 132 | |
| 133 | meta_data = list(self.meta_data(prefix)) |
| 134 | for m in meta_data: |
| 135 | args.append(list(m) + [self.phone_encoder, self.binarization_args]) |
| 136 | num_workers = int(os.getenv('N_PROC', os.cpu_count() // 3)) |
| 137 | for f_id, (_, item) in enumerate( |
| 138 | zip(tqdm(meta_data), chunked_multiprocess_run(self.process_item, args, num_workers=num_workers))): |
| 139 | if item is None: |
| 140 | continue |
| 141 | item['spk_embed'] = voice_encoder.embed_utterance(item['wav']) \ |
| 142 | if self.binarization_args['with_spk_embed'] else None |
| 143 | if not self.binarization_args['with_wav'] and 'wav' in item: |
| 144 | print("del wav") |
| 145 | del item['wav'] |
| 146 | builder.add_item(item) |
| 147 | lengths.append(item['len']) |
| 148 | total_sec += item['sec'] |
| 149 | if item.get('f0') is not None: |
| 150 | f0s.append(item['f0']) |
| 151 | builder.finalize() |
| 152 | np.save(f'{data_dir}/{prefix}_lengths.npy', lengths) |
| 153 | if len(f0s) > 0: |
| 154 | f0s = np.concatenate(f0s, 0) |
| 155 | f0s = f0s[f0s != 0] |
| 156 | np.save(f'{data_dir}/{prefix}_f0s_mean_std.npy', [np.mean(f0s).item(), np.std(f0s).item()]) |
| 157 | print(f"| {prefix} total duration: {total_sec:.3f}s") |
| 158 | |
| 159 | @classmethod |
| 160 | def process_item(cls, item_name, ph, txt, tg_fn, wav_fn, spk_id, encoder, binarization_args): |
no test coverage detected