2

I'm looking to combine a range of different audio files (mp3) in Python. One of the requirements is that I need to be able to specify a delay at the end of each file. To illustrate, something like:

[file1.mp3--------3 seconds----------][delay---------2 seconds--------][file2.mp3]-------------4 seconds][delay---------2 seconds][file3.mp3----------3 seconds---------]

Does anyone here know of any mp3 libraries that can accomplish this? Python isn't really a necessity here. If it'll be easier in another language, that'll be fine.

NRaf
  • 7,407
  • 13
  • 52
  • 91

2 Answers2

2

I think FFmpeg can do this, given the right arguments. No real need to use a library.

Johan Kotlinski
  • 25,185
  • 9
  • 78
  • 101
  • There are other things I'd need to do as well (such as parsing, renaming files, dynamically altering the delay based on the length of the audio file, etc). – NRaf Jan 03 '11 at 01:18
0

To combine wav or aiff files, you can do something like this: (inspiration from here)

import aifc

def concatenate(*items):
    data = []

    for item in items:
        f = aifc.open(item, 'rb')
        data.append([f.getparams(), f.readframes(f.getnframes())])
        f.close()

    output = aifc.open('output.aif', 'wb')
    output.setparams(data[0][0])

    for item in data:
        output.writeframes(item[1])

    output.close()

See the link for the wav format (it's pretty much the same, but with the wave library)

To add silence, I would just make a one second silent file using your favorite audio editor and then concatenate in the proper amount of silence.

Community
  • 1
  • 1
dantiston
  • 5,161
  • 2
  • 26
  • 30