Skip to content

Commit f000d7d

Browse files
authored
Update separator.py
1 parent 85c581e commit f000d7d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

audio_separator/separator/separator.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,10 +617,13 @@ def demix(self, mix, is_match_mix=False):
617617
mix_part_ = mixture[:, start:end]
618618
if end != i + chunk_size:
619619
pad_size = (i + chunk_size) - end
620-
mix_part_ = np.concatenate((mix_part_, np.zeros((2, pad_size), dtype="float32")), axis=-1)
621-
620+
# Optimize padding
621+
if pad_size > 0:
622+
mix_part_ = np.pad(mix_part_, ((0, 0), (0, pad_size)), mode='constant')
623+
622624
# Converts the chunk to a tensor for processing.
623-
mix_part = torch.tensor([mix_part_], dtype=torch.float32).to(self.device)
625+
mix_part = torch.from_numpy(mix_part_).float().to(self.device)
626+
624627
# Splits the chunk into smaller batches if necessary.
625628
mix_waves = mix_part.split(self.batch_size)
626629
total_batches = len(mix_waves)

0 commit comments

Comments
 (0)