Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Using SoX in Python to Increase mp3 Bitrate

Writer Matthew Martinez

I am trying to increase the bitrate on an mp3 in an audio archiving program written in Python, that uses SoX.

Here's a portion of the code:

 #fullHour is a boolean DeltaSeconds = chunk['TimeDelta'].total_seconds() fullHour = (3540 < DeltaSeconds < 3660 ) targetMp3 = ''.join((tmpFolder, '/', str(x), '.mp3')) if fullHour: # no trim necesary, just convert to mp3 # print tab,'fullHour [',str(x),']' # print tab,' ','SourceOgg -> ', str(SourceOgg) # print tab,' ', 'targetMp3 -> ', str(targetMp3) cmd = ['sox', SourceOgg, targetMp3] print cmd call(cmd)

This is what I tried:

cmd = ['sox', SourceOgg, '-C 192.2', targetMp3]

According to the documentation, this should work. Here is the full project: AutoCharlie

The source file is an ogg (Sample Rate 44100,Bits per sample 32, Bitrate 499 kpbs).

I ran this in the command line on my Ubuntu machine, and it worked perfectly:

sox old.ogg -C 192.2 new.mp3

So I believe it's something specific to running the command in python. I may be missing something with the syntax?

Any thoughts would be greatly appreciated, thanks!

12

1 Answer

It’s really simple. The command you say works, sox old.ogg -C 192.2 new.mp3, would look like this in array notation:

[ 'sox', 'old.ogg', '-C', '192.2', 'new.mp3']

Note how every space starts a new argument, because it is not quoted or escaped.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy