justinsalamon/scaper

Bug in `generate_from_jams` when `save_isolated_events` is True, and a `trim` operation was called prior to generating.

pseeth opened this issue · 1 comments

Through some happenstance, I noticed that this will happen here:

scaper/scaper/core.py

Lines 181 to 196 in 33def12

if 'slice' in ann.sandbox.keys():
for sliceop in ann.sandbox['slice']:
# must use temp file in order to save to same file
tmpfiles = []
audio_files = [audio_outfile] + ann.sandbox.scaper.isolated_events_audio_path
with _close_temp_files(tmpfiles):
for audio_file in audio_files:
# Create tmp file
tmpfiles.append(
tempfile.NamedTemporaryFile(suffix='.wav', delete=False))
# Save trimmed result to temp file
tfm = sox.Transformer()
tfm.trim(sliceop['slice_start'], sliceop['slice_end'])
tfm.build(audio_file, tmpfiles[-1].name)
# Copy result back to original file
shutil.copyfile(tmpfiles[-1].name, audio_outfile)

Should be easy to fix. audio_outfile should be audio_file here. I'll make a test, get it to fail, then issue a fix in a PR.

Fixed via #115