Skip to content

Commit 279a09a

Browse files
Fix #2973 bug with period in path (#2974)
Co-authored-by: Parcollet Titouan <parcollet.titouan@gmail.com>
1 parent ac674c0 commit 279a09a

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

speechbrain/augment/preparation.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99

1010
import os
11+
import pathlib
1112

1213
import torchaudio
1314

@@ -180,17 +181,17 @@ def _handle_long_waveform(
180181
The index of the audio file in the list.
181182
"""
182183
os.remove(filename)
184+
filename = pathlib.Path(filename)
183185
for j in range(int(duration / max_length)):
184186
start = int(max_length * j * rate)
185187
stop = int(min(max_length * (j + 1), duration) * rate)
186-
ext = filename.split(".")[1]
187-
new_filename = filename.replace("." + ext, "_" + str(j) + "." + ext)
188+
new_filename = filename.with_stem(filename.stem + f"_{j}")
188189

189190
torchaudio.save(new_filename, signal[:, start:stop], rate)
190191
csv_row = (
191192
f"{ID}_{index}_{j}",
192193
str((stop - start) / rate),
193-
new_filename,
194+
str(new_filename),
194195
ext,
195196
"\n",
196197
)

0 commit comments

Comments
 (0)