Python Forum
Using SoX in Python to Increase mp3 Bitrate - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Using SoX in Python to Increase mp3 Bitrate (/thread-34243.html)



Using SoX in Python to Increase mp3 Bitrate - DRT - Jul-10-2021

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:

    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]
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?

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).

Any thoughts would be greatly appreciated, thanks!


RE: Using SoX in Python to Increase mp3 Bitrate - DRT - Jul-10-2021

Update... to make it work in an array, just had to do this:

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