I have a Python script that calls an external program (sox
to be precise). Now I have to do several things with sox
, but always have to wait until one file is done writing so I can use it as an input file in my next command.
subprocess.wait()
doesn't work, because the execution of sox
will be done, but the file won't be done writing.
Here is the code I have:
import tempfile
import shlex
file_url = '/some/file.wav'
out_file = 'some/out.wav'
tmp_file = tempfile.NamedTemporaryFile()
pad_cmd = 'sox ' + file_url + ' ' + tmp_file.name + ' pad 0.0 3.0'
subprocess.call(shlex.split(pad_cmd))
trim_cmd = 'sox ' + tmp_file.name + ' -t wav ' + out_file + ' trim 0.0 3.0'
Any way to wait for the file to finish writing to tmp_file.name
without using a timer that waits for a fixed amount of time. Or is there a built-in way in sox
to use the output file as input? The special filename -
didn't work for pad
and trim
.