[asterisk-users] Converting MP3 files to wav for Asterisk

Steve Edwards asterisk.org at sedwards.com
Thu Mar 3 10:19:24 CST 2011


On Thu, 3 Mar 2011, Timothy Smith wrote:

> Do you guys know of a better way I can convert mp3 to wav and restore 
> quality?

You can't restore quality lost by converting to MP3. You shouldn't be 
'losing' quality by converting from MP3 to WAV.

> ----------------------------
> #!/bin/bash
> for i in `ls $1/*mp3`

Using "for i in $1/*mp3" will save creating a process.

> do
> lame -a $i $i.wav

Lame is an MP3 encoder. Specifying '.wav' doesn't create a WAV encoded 
file, just a 'single channel' (because of '-a') MP3 encoded file with 
'.wav' tacked on the end of the file name.

> mplayer   -quiet  -vo null  -vc dummy  -ao pcm:waveheader:file="$i.h.wav" $i.wav
> sox $i.h.wav -t raw -r 8000 -s -2 -c 1 `echo $i|sed "s/.mp3/.sln/"`

Using "sox $i.h.wav -t raw -r 8000 -s -2 -c 1 ${i%.mp3}.sln" will save 
creating a process.

> done
> -----------------------------

I tried your commands converting an old Pink Floyd track and it sounded 
about as good as I would expect.

Try something 'simpler'

 	mpg123 -q -w "${TEMP}" "${INPUT}"
 	sox "${TEMP}" -c 1 -s -w -r 8000 "${OUTPUT}"

and see if that helps. Otherwise, how do the 'intermediate' files in your 
process sound? Can you hear when things fall apart?

If you post a link to a sample input file and a 'degraded' output file, 
this may provide more clues.

-- 
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards       sedwards at sedwards.com      Voice: +1-760-468-3867 PST
Newline                                              Fax: +1-760-731-3000



More information about the asterisk-users mailing list