WWW FAQs: Why do my MP3 files sound bad in Flash Player?

2006-11-06: Why does your wonderful MP3 file sound like Alvin and the Chipmunks when you play it back in the XSPF Web Music Player, or another Flash-based player? And how can you make it stop? An urgent question if there ever was one!


I recommend the excellent, free Audacity software in many of my audio articles. Audacity, along with the LAME MP3 encoder, does a great job of recording, editing, and converting audio to the MP3 format for use on your website. And as I explain in the article how do I embed sound and music in a web page, the Flash-based XSPF Web Music Player makes it easy to put that music on your website.

Where The Trouble Starts

Unfortunately, there's one catch: Audacity and Flash don't always play nicely together. If you're recording high-quality MP3 files at 128kbps or more— and for quality recordings of multiple performers in a band, you definitely should be— then you won't have any problems. But if you are recording lower-bitrate MP3 files, perhaps to save disk space and download time for speech or acoustic "singer/songwriter" performances, then Audacity can produce files that Flash player hates. And that's when the high-pitched chipmunk sounds start!

The Sampling Rate Problem

MP3 files always start out at a certain "sampling rate-" a certain number of cycles per second. For our purposes it's good enough to know that high sampling rates sound great, and low sampling rates sound... not so great. But for speech and one-person acoustic performances, they can be just fine.

The problem is that Flash Player only supports two sampling rates: 22,050 samples per second, and 44,100 samples per second. And at low bitrates, Audacity likes to create MP3 files with lots of different sampling rates, such as 16,000 or 32,000 samples per second.

So, what's the solution? Currently the best fix is to convert your audio files to MP3s manually, using the command line version of the LAME MP3 encoder.

The Solution

Sound scary? It's not! All you need to do is visit the LAME Binaries for Windows page and pick up the latest version of LAME for Windows (users of non-Windows operating systems should visit the LAME home page to locate a version of LAME for their operating system). Windows will offer to open the zip file for you. Do that, and select "Extract all files." Then extract the files to a folder that's convenient for you. I use c:\audio for most of my audio work.

Once you have the LAME tools on your computer, all you have to do is record your music to a WAV file with Audacity. Follow the steps in the article How do I convert my music to MP3 format— but instead of exporting an MP3 file, directly from Audacity, select "Export as WAV..." instead.

Export your song as c:\audio\mysong.wav.

Then open the Windows command line prompt by following these steps:

1. Start -> Run

2. In the "Open:" field, enter: cmd.exe

3. Click "OK"

Now, move to your c:\audio folder with the following command:

cd \audio
Be sure to press "enter" after entering this command.

Finally, type this command to convert your WAV file to an MP3 file with a sample rate that Flash Player will accept:

lame -b 48 --resample 22.05 mysong.wav mysong.mp3

If you get a mssage saying that "'lame' is not recognized as an internal or external command," then you did not extract lame.exe and the rest of the contents of the LAME zip file to c:\audio as I suggested. Go back and fix that.
This command will create an MP3 file called mysong.mp3 with a very low bitrate of 48kbps and a sampling rate of 22,050 samples per second. Flash Player will have no trouble with this file. For slightly higher quality, as you might wish for an acoustic guitar performance, use -b 64. For very high quality, you can use -b 128 and --resample 44.1. But Audacity will do that automatically if you set the MP3 bitrate to 128 on the "File Formats" tab of Audacity's "Audacity Preferences" window. So you will use this technique most often when you want a low-bitrate, low-bandwidth, fast-downloading file.

Converting Existing MP3 Files

You can also "fix" your existing MP3 files with LAME. This is a good technique if you are not willing or able to go back to the original source material. But be aware that although LAME tries to minimize the damage, there is a loss of quality when you re-encode or "transcode" an MP3 file like this. MP3 achieves its wonderful file sizes through "lossy" encoding - throwing away the parts of the audio that the ear doesn't really notice. Doing that more than once can have bad consequences.

That said, here's how to "fix" an existing MP3 file with a sampling rate Flash can't handle. I assume that your existing file is mysongin.mp3 and you want to produce a new file called mysongout.mp3. Substitute your own file names:

lame --resample 22.05 mysongin.mp3 mysongout.mp3

Notice that I haven't changed the bitrate here, only the sampling rate, because that's what Flash is angry about. But you can also specify -b 32, for instance, to downgrade to a very small (and, unfortunately, very low-quality) 32kbps file. You can also force monophonic (non-stereo) output with the -a option, which will also save space.

Yes, you could specify a bitrate higher than the original MP3 file, but it wouldn't do you any good! You can't get something for nothing— you need good source material to make a quality product.

For more information, see the articles what bitrate should I use for my audio files? and how do I embed sound and music in a web page?

Thanks to Dan York for being the first to accurately describe both the problem and its solution.

Legal Note: yes, you may use sample HTML, Javascript, PHP and other code presented above in your own projects. You may not reproduce large portions of the text of the article without our express permission.

Got a LiveJournal account? Keep up with the latest articles in this FAQ by adding our syndicated feed to your friends list!