Batch convert mp3 files to WAV format for using in asterisk telephony system

Batch convert mp3 files to WAV format for using in asterisk telephony system (16bit mono 8000 hz) in CENTOS 6

First install sox with mp3 support:

 yum remove sox

Install prerequisites:

# yum install gcc-c++ libmad libmad-devel libid3tag libid3tag-devel lame lame-devel flac-devel libvorbis-devel

Install latest sox package from source:

# mkdir /usr/local/src/SoX
# cd /usr/local/src/SoX/
# wget http://softlayer-dal.dl.sourceforge.net/project/sox/sox/14.4.2/sox-14.4.2.tar.gz
# tar xvfz sox-14.4.2.tar.gz
# cd sox-14.4.2
# ./configure
make
make install
Create a shell script to read all mp3 files in the current folder and convert them to the wav format. This shell script will process files with spaces as well. We are converting to wav 16bit Mono 8khz so that asterisk can play them.

#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for f in *
do
  sox $f  -b 16 -c 1 -r 8000 "${f%.*}".wav
done
IFS=$SAVEIFS










Comments