File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88"""
99
1010import os
11+ import pathlib
1112
1213import 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 )
You can’t perform that action at this time.
0 commit comments