Search code examples
language-agnosticaudioogg

Manipulating multi-track ogg files programatically


I'm planning to create a program for manipulating multi-track OGG files, but I don't have any experience with the relevant libraries, so I'm looking for recommendations about which language/library to use for this. I don't really have any preference for the language, I'll happily code it in C, C#, Python, whatever makes things the easiest (or even possible). Perhaps it's even a possibility to automate Audacity somehow?

In terms of requirements, I'm not looking for anything particularly fancy. It will probably be a command-line program, I don't need to be able to play the audio, draw image representations of the waveforms, etc. The program will basically be used as a converter, but I need to do some processing before outputting. That is, I need the ability to programatically remove some tracks, set panning per-track, change track volumes, etc. Nothing too complex, just some basic processing, and then output the result in either MP3 or a format easily converted to MP3, such as WAV.

Any suggestions or general information would be appreciated, thanks.


Solution

  • SoX can do a lot of this stuff, just using command-line scripts.

    I've used Python + Audiolab to do more complex audio processing stuff:

    from audiolab import oggread, wavwrite
    
    # Read in a file
    data, fs, enc = oggread('test.ogg')
    
    # Keep just the first two channels
    newdata = data[:,0:2]
    
    # Reduce by -6 dB
    newdata *= 0.5
    
    # Write to a new file
    wavwrite(data, 'filename.wav', fs, enc)