When I export to MP3, audio expands by a little bit

I’m trying to create a bunch of MP3 recordings of exactly 2 seconds in length. I edited them in Audacity and saved them as Audacity projects. Everything is exactly 2.00 seconds long when I do so. But, when I export the audio to MP3 and then re-open the MP3 file in Audacity, the file is now 2.038 seconds long.

I’ve tried reinstalling Audacity, but I get the same results.

I’ve attached one of the recordings, with both the aup and mp3 files.

I’m using Windows 10, Audacity 2.1.2, installed from EXE installer.

Thanks for your help!

apple.aup (1.42 KB)

MP3 files always have a bit of padding at the start. It’s a limitation of the MP3 format. The only solution is to use a different format (such as WAV)

Thanks for the info. I see that it’s exactly 2.00 seconds if I use WAV format. I tried reducing the length to 1.96 seconds in Audacity and when I export to mp3 it pads it out to 2.011 seconds, so that’s about as close as I can get.

Out of interest, what are these 2 second files for? Is there a reason why they need to be MP3 format?

I’m concatenating them into one big audio file to use as an audio sprite (in JavaScript). If the lengths aren’t accurate, I won’t access the right chunk of audio in the audio sprite. I wanted the small size of mp3, but if I make the sound clips mono and reduce the sample rate, it might be doable as a wav file.

How about using Ogg Vorbis? http://www.vorbis.com/
File size is similar to MP3. Sound quality is similar (better at high bit-rates). Possible patent issues of MP3 are avoided, and Ogg does not have the problem of padding at the start of the file.

steve, thanks for the suggestion of using the ogg format for audio files. They do compress nicely! However, I haven’t been able to get it to play properly in my JavaScript code. I still may need to do something so that they concatenate properly. I’m just using file_get_contents() in JavaScript. I’m not sure if you’re familiar with that. It just reads it in as text, so if I need to adjust the headers or anything else in the ogg file, it wouldn’t take care of that. This may be a programming question but perhaps you know about the ogg file format. BTW, the concatenated file plays ok in VLC Media Player but not from within the JavaScript in a browser.