Okay, I’ve found my error. There is nothing wrong with the DataLoader but with get_specs() function. The following lines were the troublemakers:
...
if song0 == song1:
   spec1 = spec0
   offset1 = random.randint(0, spec0_x - duration)
   while abs(offset0 - offset1) < self.overlap:
         offset1 = random.randint(0, spec0_x - duration)
...

The reason is that it can take forever for the code to find a suitable random number. To avoid this one can define a range, in which the random generate should not look. I’ve done it the following way:
...
if song0 == song1:
   spec1 = spec0
   overlap_range = range(max(0, offset0 - self.overlap),
                         min(spec0_x - self.duration, offset0 + self.overlap))
   offset1_range = [i for i in range(0, spec0_x) if
                   (i not in overlap_range) & (i <= spec0_x - self.duration)]
   offset1 = random.choice(offset1_range)
...