Skip to content

Commit 17d3dda

Browse files
authored
make multiprocessing in hifigan dataset creation optional
1 parent b2c3e62 commit 17d3dda

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

TrainingInterfaces/Spectrogram_to_Wave/HiFIGAN/HiFiGANDataset.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,22 @@ def __init__(self,
3232
# datasets and then concat them. If we just did all
3333
# datasets at once, there could be multiple sampling
3434
# rates.
35-
resource_manager = Manager()
36-
self.waves = resource_manager.list()
37-
# make processes
38-
path_splits = list()
39-
process_list = list()
40-
for i in range(loading_processes):
41-
path_splits.append(list_of_paths[i * len(list_of_paths) // loading_processes:(i + 1) * len(list_of_paths) // loading_processes])
42-
for path_split in path_splits:
43-
process_list.append(Process(target=self.cache_builder_process, args=(path_split,), daemon=True))
44-
process_list[-1].start()
45-
for process in process_list:
46-
process.join()
35+
if loading_processes == 1:
36+
self.waves = list()
37+
self.cache_builder_process(list_of_paths)
38+
else:
39+
resource_manager = Manager()
40+
self.waves = resource_manager.list()
41+
# make processes
42+
path_splits = list()
43+
process_list = list()
44+
for i in range(loading_processes):
45+
path_splits.append(list_of_paths[i * len(list_of_paths) // loading_processes:(i + 1) * len(list_of_paths) // loading_processes])
46+
for path_split in path_splits:
47+
process_list.append(Process(target=self.cache_builder_process, args=(path_split,), daemon=True))
48+
process_list[-1].start()
49+
for process in process_list:
50+
process.join()
4751
numpy_waves = list(self.waves)
4852
self.waves = list()
4953
for wave in numpy_waves:
@@ -56,7 +60,10 @@ def cache_builder_process(self, path_split):
5660
wave, sr = sf.read(audio_file)
5761
if (len(wave) / sr) > ((self.samples_per_segment + 50) / self.desired_samplingrate): # + 50 is just to be extra sure
5862
# catch files that are too short to apply meaningful signal processing
59-
self.waves.append(librosa.resample(y=wave, orig_sr=self._orig_sr, target_sr=self.desired_samplingrate))
63+
try:
64+
self.waves.append(librosa.resample(y=wave, orig_sr=self._orig_sr, target_sr=self.desired_samplingrate))
65+
except BrokenPipeError:
66+
print(f"Something is likely wrong with this file: {path} - Perhaps the audio is too short?")
6067

6168
def __getitem__(self, index):
6269
"""

0 commit comments

Comments
 (0)