Spaces:
Sleeping
Sleeping
Commit
·
056a44f
1
Parent(s):
4f7d68b
Pick new chunk if too short
Browse files- remfx/datasets.py +6 -13
- remfx/utils.py +9 -4
remfx/datasets.py
CHANGED
@@ -210,23 +210,16 @@ class EffectDataset(Dataset):
|
|
210 |
while len(chunks) == 0:
|
211 |
random_dataset_choice = random.choice(self.files)
|
212 |
random_file_choice = random.choice(random_dataset_choice)
|
213 |
-
chunks
|
214 |
-
random_file_choice, self.chunk_size
|
215 |
)
|
216 |
random_chunk = random.choice(chunks)
|
217 |
-
|
218 |
-
random_chunk, orig_sr, sample_rate
|
219 |
-
)
|
220 |
-
if resampled_chunk.shape[-1] < chunk_size:
|
221 |
-
# Skip if chunk is too small
|
222 |
-
continue
|
223 |
# Sum to mono
|
224 |
-
if
|
225 |
-
|
226 |
|
227 |
-
dry, wet, dry_effects, wet_effects = self.process_effects(
|
228 |
-
resampled_chunk
|
229 |
-
)
|
230 |
output_dir = self.proc_root / str(num_chunk)
|
231 |
output_dir.mkdir(exist_ok=True)
|
232 |
torchaudio.save(output_dir / "input.wav", wet, self.sample_rate)
|
|
|
210 |
while len(chunks) == 0:
|
211 |
random_dataset_choice = random.choice(self.files)
|
212 |
random_file_choice = random.choice(random_dataset_choice)
|
213 |
+
chunks = create_sequential_chunks(
|
214 |
+
random_file_choice, self.chunk_size, self.sample_rate
|
215 |
)
|
216 |
random_chunk = random.choice(chunks)
|
217 |
+
|
|
|
|
|
|
|
|
|
|
|
218 |
# Sum to mono
|
219 |
+
if random_chunk.shape[0] > 1:
|
220 |
+
random_chunk = random_chunk.sum(0, keepdim=True)
|
221 |
|
222 |
+
dry, wet, dry_effects, wet_effects = self.process_effects(random_chunk)
|
|
|
|
|
223 |
output_dir = self.proc_root / str(num_chunk)
|
224 |
output_dir.mkdir(exist_ok=True)
|
225 |
torchaudio.save(output_dir / "input.wav", wet, self.sample_rate)
|
remfx/utils.py
CHANGED
@@ -127,8 +127,8 @@ def create_random_chunks(
|
|
127 |
|
128 |
|
129 |
def create_sequential_chunks(
|
130 |
-
audio_file: str, chunk_size: int
|
131 |
-
) ->
|
132 |
"""Create sequential chunks of size chunk_size (seconds) from an audio file.
|
133 |
Return sample_index of start of each chunk and original sr
|
134 |
"""
|
@@ -138,8 +138,13 @@ def create_sequential_chunks(
|
|
138 |
for start in chunk_starts:
|
139 |
if start + chunk_size > audio.shape[-1]:
|
140 |
break
|
141 |
-
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
143 |
|
144 |
|
145 |
def spectrogram(
|
|
|
127 |
|
128 |
|
129 |
def create_sequential_chunks(
|
130 |
+
audio_file: str, chunk_size: int, sample_rate: int
|
131 |
+
) -> List[torch.Tensor]:
|
132 |
"""Create sequential chunks of size chunk_size (seconds) from an audio file.
|
133 |
Return sample_index of start of each chunk and original sr
|
134 |
"""
|
|
|
138 |
for start in chunk_starts:
|
139 |
if start + chunk_size > audio.shape[-1]:
|
140 |
break
|
141 |
+
chunk = audio[:, start : start + chunk_size]
|
142 |
+
resampled_chunk = torchaudio.functional.resample(chunk, sr, sample_rate)
|
143 |
+
# Skip chunks that are too short
|
144 |
+
if resampled_chunk.shape[-1] < chunk_size:
|
145 |
+
continue
|
146 |
+
chunks.append(chunk)
|
147 |
+
return chunks
|
148 |
|
149 |
|
150 |
def spectrogram(
|