2

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!

DRT
  • 21
  • 2
  • 1
    Why do you need to increase the bitrate? – Tetsujin Jul 10 '21 at 12:56
  • This is for a community radio station, and some show hosts and listeners are having issues with sound quality. – DRT Jul 10 '21 at 12:58
  • 3
    Increasing the bitrate isn't going to increase quality, it's just going to fill with empty bits. You can't put back what's already been removed. – Tetsujin Jul 10 '21 at 13:00
  • I'm not an expert on this by any means, so I appreciate your thoughts on it. How do we keep as much sound quality as possible when changing from the ogg file to mp3? My understanding is that with '-C 192.2', the '.2' also increases sound quality. – DRT Jul 10 '21 at 13:04
  • 2
    The optimum would be to retain the bitrate of the incoming file. You cannot "add quality". – Tetsujin Jul 10 '21 at 13:08
  • I guess I'm confused. We have our original ogg files that sound great, then they are converted to mp3 using sox. I believe the default for sox is 128kbps? So we end up with an mp3 file at 128. Wouldn't changing the default to 192.2 make a better sounding file? – DRT Jul 10 '21 at 13:13
  • 1
    I could be misunderstanding, but I would think that changing the bitrate (192) and quality (.2) would help retain bitrate, and not be an attempt to add it. – DRT Jul 10 '21 at 13:15
  • As long as the source file, was of equivalent or higher bitrate. – DRT Jul 10 '21 at 13:17
  • I updated my question to include information on the source file. I'm hoping to retain some of the original quality by increasing the bitrate of the mp3 that is produced using SoX. My issue is that the '-C 192.2' is not changing the bitrate from 128. Any help on this would be appreciated, thanks! – DRT Jul 10 '21 at 13:58
  • Is this any use? https://superuser.com/questions/15327/how-to-convert-ogg-to-mp3 – Tetsujin Jul 10 '21 at 14:33
  • https://stackoverflow.com/a/26721905 might be useful – Jacob Jul 10 '21 at 14:39
  • Everything points to using -C exactly how I am using it, yet it's not working. The mp3's consistently come out w/a bitrate of 128. I'm wondering if I should be doing something a bit different because I am using sox inside of python? – DRT Jul 10 '21 at 15:31

1 Answers1

1

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.

Daniel B
  • 60,360
  • 9
  • 122
  • 163
  • Thanks! I tried this out, and still no luck. Mp3 still came out at 128!? I will keep digging though, and welcome any suggestions. – DRT Jul 10 '21 at 18:12
  • Works for me. Maybe your version of SoX is broken. Maybe try calling it with `-V3` to get useful debugging info. – Daniel B Jul 10 '21 at 18:35
  • This does work! The program is creating two mp3's, both at 192kbps. They are then joined into a single mp3 using another function, and that's why I wasn't seeing the results. I'm one step closer to getting this done, thanks for your help! – DRT Jul 10 '21 at 20:45