Convert audio file from WAV to MP3

This an example on converting audio file from wav format to mp3 with the help of Sound eXchange( a.k.a SOX ), and Lame Aint an MP3 Encoder (a.k.a. Lame).

Before using this script, please make sure you have both sox and lame installed.

#!/bin/bash -e
# Coded by Joseph.Chen <joseph@admon.org>, 2009-11
# It's intended to covert wav to mp3

# Make sure that /usr/local/bin is in the PATH
PATH=$PATH:/usr/local/bin

tdir=`mktemp -t -d`
trap "rm -rf $tdir" EXIT
cd ${tdir}

test -f audio.wav
sox audio.wav -r 44100 -w audio-new.wav
lame --silent -m m --abr 15 -o audio-new.wav audio.mp3
test -f audio.mp3 && echo "The file has been converted sucessfully!"

We also shared some Bash/PHP scripts at forum.admon.org, and if you want some help, please feel free to raise a thread on the Forum.

Share Button

Leave a comment

Your email address will not be published. Required fields are marked *