4

I am trying to use subprocess.call to run a sox command as follows:

import subprocess
subprocess.call(['sox','-n','-b','16','output.wav','synth','2.25','sine','300','vol','0.5'])

While this command works fine on a unix command line, here I get the following error:

OSError: [Errno 2] No such file or directory 

I also tried this using os.system:

os.system('sox -n -b 16 output.wav synth 2.25 sine 300 vol 0.5')

And I get a command not found error. Calling other unix commands works fine for me, e.g.

subprocess.call(['say' ,'hello'])

Any ideas? I'm running OS 10.8.4, python 2.7.6, sox 14.4.1.

  • 2
    Most likely is that `sox` is not in the PATH when called from python, try using the full path name for the program. – cdarke Jan 08 '15 at 22:47
  • 2
    Argh. Yup, I just hadn't figured out the right way to specify it:`subprocess.call(['/Applications/sox-14.4.1/sox', '-n','-b','16','output.wav','synth','2.25','sine','300','vol','0.5'])` – Jennifer Culbertson Jan 09 '15 at 14:36

4 Answers4

1

Try using cmdstring = "sox -n -b 16 relative_path/output.wav synth 2.25 sine 300 vol 0.5"

Then calling os.system(cmdstring)

Ankit Shah
  • 196
  • 1
  • 6
1

Use this with Shell = True as follows:

subprocess.call(command, shell=True)
Aish
  • 189
  • 7
0

You'd probably be wise to switch to pysox, which provides python bindings to sox.

mlissner
  • 17,359
  • 18
  • 106
  • 169
0

Saw this when I was trying to find an answer to a different problem.

I do use subprocess to play mp3 files with the sox play command, but I had to split the command and parameters up using '.Popen' - don't think I could get it to work with call

SOX_CMD = '/usr/bin/play'

# use replace to escape any spaces in path
split_char = "~"
play_command = SOX_CMD + split_char + audio_file +  split_char + "-V1" + split_char + "trim" + split_char + start_time
print('PLAY COMMAND : ' + play_command)
SOX_PROCESS = subprocess.Popen(play_command.split(split_char), stdout=SOX_LOG_FILE_HANDLE, stderr=SOX_LOG_FILE_HANDLE)
dbmitch
  • 5,361
  • 4
  • 24
  • 38