How to add silent stretches to MP3 using Python?
python.list at tim.thechases.com
Sun Aug 15 02:57:54 CEST 2010
> 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 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.
or "apt-get install mp3wrap" here on my Debian box
More information about the Python-list