How to add silent stretches to MP3 using Python?

K

kj

Here's the problem: I have about 25,000 mp3 files, each lasting,
*on average*, only a few seconds, though the variance is wide (the
longest one lasts around 20 seconds). (These files correspond to
sample sentences for foreign language training.)

The problem is that there is basically no padding before and after
the sound signal. I want to prepend about 2 seconds of silence to
each file, and append another silent stretch at the end lasting
either 2 seconds or some multiplier of the duration of the original
file, whichever is greater.

I know that manipulating MP3 audio programmatically is usually not
easy, but this has got to be one of the simplest manipulations
possible, so I'm hoping I'll be able to pull it off with Python.

But I have not had much luck finding a Python library to do this.
If someone knows how to do this, and could give me some pointers,
I'd appreciate it.

TIA!

~K
 
T

Tim Chase

Here's the problem: I have about 25,000 mp3 files, each lasting,
*on average*, only a few seconds, though the variance is wide (the
longest one lasts around 20 seconds). (These files correspond to
sample sentences for foreign language training.)

The problem is that there is basically no padding before and after
the sound signal. I want to prepend about 2 seconds of silence to
each file, and append another silent stretch at the end lasting
either 2 seconds or some multiplier of the duration of the original
file, whichever is greater.

I know that manipulating MP3 audio programmatically is usually not
easy, but this has got to be one of the simplest manipulations
possible, so I'm hoping I'll be able to pull it off with Python.

But I have not had much luck finding a Python library to do this.
If someone knows how to do this, and could give me some pointers,
I'd appreciate it.

While it's (1) not 100% python and (2) doesn't allow for your "2
seconds...or some multiplier of the duration, whichever is
greater", you can use mp3wrap[1] to losslessly join the files.
If you happen to make a 2-seconds-of-silence MP3, you can then
join your files together with the silence. For 25k files, you
might have to stitch subsets of them together incrementally and
then stitch together the resulting files.

-tkc


[1] http://mp3wrap.sourceforge.net/
or "apt-get install mp3wrap" here on my Debian box
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top