HOWTO Convert audio files
A huge variety of file formats are used to store and distribute digital audio. The most commonly used for compressed audio is mp3, and the most common format for raw audio is .wav.
But there are many other audio formats, and you likely want to be able to convert between the various formats.
 .wav, the middle-man for most audio conversion
If you want to convert between compressed audio formats then there is no way around decoding the original compressed format to .wav before re-encoding the file to another common format such as .wav.
mplayer \ -quiet \ -vo null \ -vc dummy \ -ao pcm:waveheader:file="rawaudio.wav" "convertthis.rm"
This gives you audio.wav with the audio.
You may want to use -af to change sample-rate or other options. Example:
mplayer \ -quiet \ -vo null \ -vc dummy \ -af volume=0,resample=44100:0:1 \ -ao pcm:waveheader:file="rawaudio.wav" "convertthis.wma"
Note that you will not gain anything (except more used harddrive space) by resampling a file to a higher sample-rate.
 ogg files
.ogg files are best decoded with oggdec. So, you could for example use this (very dangerous!) little script to convert any .ogg file in your folder to wav:
#!/bin/bash oggdec *ogg lame --preset 192 -ms -h *wav # rm -f *ogg rm -f *wav done
As you should clearly see, it removes any .wav file already present in your current folder when it converts any .ogg file there to .wav, and if you comment out the file above then that's nuked also. But it works, it's automated, there's not much to it.
 Fixing Broken WAV File Headers Using Mplayer
Some very cheap MP3 players include a voice recording capability but create WAV files with broken headers that will not load into editing or playing programs, but do play using MPlayer. These broken WAV files may resist other attempts to fix their headers with wavfix.pl or ecasound. You can use Mplayer to fix the broken WAV files in the following way:
mplayer \ -quiet \ -vo null \ -vc dummy \ -ao pcm:waveheader:file="audio_FIXED.wav" audio_BROKEN.wav
 Converting your .wav to other formats
 To mp3
 Using lame
LAME is a great command-line tool for converting audio files to MP3. Basic usage:
lame (options) input.wav output.mp3
These are nice general settings to use:
lame -V0 -h -b 160 --vbr-new input.wav output.mp3
- -V n 0 <= n <= 9
- Enable VBR (Variable BitRate) and specifies the value of VBR quality (default = 4). 0 = highest quality.
- Use some quality improvements. Encoding will be slower, but the result will be of higher quality. The behaviour is the same as the -q 2 switch. This switch is always enabled when using VBR.
- -b n
- For MPEG1 (sampling frequencies of 32, 44.1 and 48 kHz) n = 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320
- For MPEG2 (sampling frequencies of 16, 22.05 and 24 kHz) n = 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160
- Default is 128 for MPEG1 and 64 for MPEG2.
- Invokes the newest VBR algorithm. During the development of version 3.90, considerable tuning was done on this algorithm, and it is now considered to be on par with the original --vbr-old. It has the added advantage of being very fast (over twice as fast as --vbr-old).
See the Lame manual page for more LAME encoding options.
 To ogg
..which creates input.ogg. Ogg is a very nice format used by some Linux users, but it is not supported by very many vendors. Windows users can play .ogg files, but need to install a codec (which is included with WinAmp).
Check the oggenc man page for all the available options.
Many video game venders use .ogg for game sounds and music, and an increasing number of mp3 players are beginning to support the .ogg vorbis format. Many tests have shown that .ogg provides equal or better sound quality when compared with .mp3s, but with lower bit rate and smaller file size.
 Batch converting audio files
This little script may be of interest and value:
#!/bin/bash # # Usage: convertomp3 fileextention # if [ $1 = "" ];then echo 'Please give a audio file extention as argument.' exit 1 fi for i in *.$1 do if [ -f "$i" ]; then rm -f "$i.wav" mkfifo "$i.wav" mplayer \ -quiet \ -vo null \ -vc dummy \ -af volume=0,resample=44100:0:1 \ -ao pcm:waveheader:file="$i.wav" "$i" & dest=`echo "$i"|sed -e "s/$1$/mp3/"` lame -V0 -h -b 160 --vbr-new "$i.wav" "$dest" rm -f "$i.wav" fi done
Running convertomp3 wma will covert every .wma file in the current folder to .mp3.