justinsalamon / scaper

A library for soundscape synthesis and augmentation
BSD 3-Clause "New" or "Revised" License
384 stars 56 forks source link

Windows does not permit audio self-concatenation in sox #29

Closed lostanlen closed 6 years ago

lostanlen commented 6 years ago

Elizabeth Mendoza (@Elizabeth-12324) uses scaper v0.2.0 and has succeeded in using scaper for pasting long sounds on her Windows 10 machine. However, short sounds (below 500 ms) cause a "Permission denied" error while calling sc.generate. See the full backtrace below my signature.

As you can see, the line at fault is cbn.build([filepath] * n_tiles, concat_file.name, 'concatenate') in get_integrated_lufs

This line appeared in v0.2.0 in PR #28, which closed issues #13 and #18. It seems that this PR brought a bug on Windows.

@Elizabeth-12324 and myself looked at the page of SoX known bugs: http://sox.sourceforge.net/Docs/Bugs and this mailing list thread: https://sourceforge.net/p/sox/mailman/message/20864618/

IIRC, @rabitt discouraged using the same inputfile and outpufile in pysox 27 https://github.com/rabitt/pysox/issues/27

I don't know if there is an easy and portable fix for this. Could it be that the concatenated file has the same name than the original, and that avoiding conflating the two names make the LUFS concatenation Windows-friendly?

Vincent

---------------------------------------------------------------------------
SoxError                                  Traceback (most recent call last)
<ipython-input-14-4823d7c3b010> in <module>()
     31             disable_sox_warnings=False,
     32             no_audio=False,
---> 33             txt_path=txtfile)
     34
     35

~\Anaconda3\lib\site-packages\scaper\core.py in generate(self, audio_path, jams_path, allow_repeated_label, allow_repeated_source, reverb, disable_sox_warnings, no_audio, txt_path, txt_sep, disable_instantiation_warnings)
   1703         if not no_audio:
   1704             self._generate_audio(audio_path, ann, reverb=reverb,
-> 1705                                  disable_sox_warnings=disable_sox_warnings)
   1706
   1707         # Finally save JAMS to disk too

~\Anaconda3\lib\site-packages\scaper\core.py in _generate_audio(self, audio_path, ann, reverb, disable_sox_warnings)
   1570                             # NOW compute LUFS
   1571                             fg_lufs = get_integrated_lufs(
-> 1572                                 tmpfiles_internal[-1].name)
   1573
   1574                             # Normalize to specified SNR with respect to

~\Anaconda3\lib\site-packages\scaper\audio.py in get_integrated_lufs(filepath, min_duration)
     98
     99             cbn = sox.Combiner()
--> 100             cbn.build([filepath] * n_tiles, concat_file.name, 'concatenate')
    101
    102             loudness_stats = r128stats(concat_file.name)

~\Anaconda3\lib\site-packages\sox\combine.py in build(self, input_filepath_list, output_filepath, combine_type, input_volumes)
     98         if status != 0:
     99             raise SoxError(
--> 100                 "Stdout: {}\nStderr: {}".format(out, err)
    101             )
    102         else:

SoxError: Stdout:
Stderr: sox FAIL formats: can't open output file `C:\Users\User\AppData\Local\Temp\tmpv8959m5l.wav': Permission denied
lostanlen commented 6 years ago

@justinsalamon maybe this can be solved with delete=False and deleting manually after use? do you want me to try that?

justinsalamon commented 6 years ago

The problem appears to be not with self-concatenation, but with temporary files on windows, re-opening #20 and closing this one out.