(
self,
configs,
sample_size=65536,
sample_rate=48000,
random_crop=True,
force_channels="stereo",
volume_norm=False,
volume_norm_param=(-16, 2),
strip_silence=False,
pad=True,
)
| 187 | |
| 188 | class SampleDataset(torch.utils.data.Dataset): |
| 189 | def __init__( |
| 190 | self, |
| 191 | configs, |
| 192 | sample_size=65536, |
| 193 | sample_rate=48000, |
| 194 | random_crop=True, |
| 195 | force_channels="stereo", |
| 196 | volume_norm=False, |
| 197 | volume_norm_param=(-16, 2), |
| 198 | strip_silence=False, |
| 199 | pad=True, |
| 200 | ): |
| 201 | super().__init__() |
| 202 | self.filenames = [] |
| 203 | self.sample_weights = [] |
| 204 | |
| 205 | self.augs = torch.nn.Sequential( |
| 206 | PhaseFlipper(), |
| 207 | #nn.Identity() |
| 208 | ) |
| 209 | |
| 210 | |
| 211 | self.root_paths = [] |
| 212 | |
| 213 | self.pad_crop = PadCrop_Normalized_T(sample_size, sample_rate, randomize=random_crop, pad=pad) |
| 214 | self.strip_silence = strip_silence |
| 215 | |
| 216 | self.force_channels = force_channels |
| 217 | |
| 218 | self.encoding = torch.nn.Sequential( |
| 219 | Stereo() if self.force_channels == "stereo" else torch.nn.Identity(), |
| 220 | Mono() if self.force_channels == "mono" else torch.nn.Identity() |
| 221 | ) |
| 222 | |
| 223 | self.sr = sample_rate |
| 224 | |
| 225 | self.volume_norm = VolumeNorm(volume_norm_param, self.sr) if volume_norm else torch.nn.Identity() |
| 226 | |
| 227 | self.custom_metadata_fns = {} |
| 228 | |
| 229 | for config in configs: |
| 230 | self.root_paths.append(config.path) |
| 231 | new_files = get_audio_filenames(config.path, config.keywords, filelist_path=config.filelist_path) |
| 232 | self.filenames.extend(new_files) |
| 233 | self.sample_weights.extend([config.weight] * len(new_files)) |
| 234 | if config.custom_metadata_fn is not None: |
| 235 | self.custom_metadata_fns[config.path] = dill.dumps(config.custom_metadata_fn) |
| 236 | |
| 237 | print(f'Found {len(self.filenames)} files') |
| 238 | |
| 239 | def load_file(self, filename): |
| 240 | ext = filename.split(".")[-1] |
no test coverage detected