I have had many jobs (consulting and Salary) that have involved using
Asterisk in a “Call-Center” environment. Whenever an agent would make a
sale, the call would need to be recorded for verification purposes.
Now I could talk about Asterisk and call-recording for pages upon pages,
but I will be focusing on large .wav to .mp3 conversion jobs on the
Linux/Asterisk server itself. First off, Asterisk can record calls
using several different methods. The first method being that you setup a
feature called Automon in /etc/asterisk/features.conf and use *1 (or
whatever you specify) to record a call in progress. The second method
is recording every call that comes in through a specific DID or enters a
specific queue. Another method is to setup a ‘call genie’ that you
conference your phone to and it records the entire call-bridge. There
are pros and cons to every type of recording method and format. You can
use GSM, wav, g729, etc. to record calls. Not matter what method you
use, the simple script I wrote will convert your .wav files to .mp3 and
also retain the timestamp of when the file was initially created
(recorded). The options I use for mlame are what makes this script
retain its awesome-ness over time. The options allow the final-result
mp3 to be compressed and compatable with Asterisk. This means that you
can playback your .mp3 files that you converted over Asterisk.
Installation Instructions:
1. Copy the below script to your server and save it as convert_recordings.sh.
========================================
#!/bin/bash
#Make sure to install Lame and copy mlame to your .wav dir
#If you specify your own filenames, use NO spaces.
recorddir="/var/spool/asterisk/monitor"
for i in `ls $recorddir/*.wav`; do
cd $recorddir
$recorddir/mlame -f -o "-b 16 -m m -q 9 --resample 8" $i
date=`ls -l $i | awk '{print $7,$6,2008,$8}'`
mp3=`echo $i | sed 's/.wav/.mp3/g'`
touch -d "$date" $mp3
#Uncomment the below line if you want your .wavs moved to a different directory.
#This way you can review the timestamps and mp3 files before deleting the .wav
#mv $i /wav_recordings
done
============================
2. Put the script anywhere you wish, I tend to leave it in my home directory
3. chmod +x convert_recordings.sh
4. You need to install lame. Get the file from the lame site.
5. Extract the tarball. For Example… tar -zxvf lame-398-2.tar.gz
6. cd lame-398-2
7. ./configure
8. make
9. make install
10. Now copy the mlame file from lame-398-2/misc/mlame to your .wav directory /var/spool/asterisk/monitor (or wherever your .wavs are)
11. chmod +x mlame
12. Edit the convert_recordings.sh recorddir variable to match your .wav directory path (no trailing ‘/’). The default directory is set to /var/spool/asterisk/monitor
13. Run the script by navigating to the directory and ./recordings_convert.sh
You should see it take a few seconds for each file and go on. I usually test it out by letting it convert a few files then Cntrl + C and ls -l the directory to check the filesizes and timestamps. There is a commented out section at the bottom of recordings_convert.sh that moves the .wav files to a separate directory (easier to check if it worked) and in my case, I keep the old files for a month or so for job security reasons. If you lose a bunch of verification recordings, you are going to have major problems.
Cron it, at it, and happy converting.
__________________________________
Code for .g729 to MP3 script. Very dirty, but works, please test on a small group of test files first.
Installation Instructions:
1. Copy the below script to your server and save it as convert_recordings.sh.
========================================
#!/bin/bash
#Make sure to install Lame and copy mlame to your .wav dir
#If you specify your own filenames, use NO spaces.
recorddir="/var/spool/asterisk/monitor"
for i in `ls $recorddir/*.wav`; do
cd $recorddir
$recorddir/mlame -f -o "-b 16 -m m -q 9 --resample 8" $i
date=`ls -l $i | awk '{print $7,$6,2008,$8}'`
mp3=`echo $i | sed 's/.wav/.mp3/g'`
touch -d "$date" $mp3
#Uncomment the below line if you want your .wavs moved to a different directory.
#This way you can review the timestamps and mp3 files before deleting the .wav
#mv $i /wav_recordings
done
============================
2. Put the script anywhere you wish, I tend to leave it in my home directory
3. chmod +x convert_recordings.sh
4. You need to install lame. Get the file from the lame site.
5. Extract the tarball. For Example… tar -zxvf lame-398-2.tar.gz
6. cd lame-398-2
7. ./configure
8. make
9. make install
10. Now copy the mlame file from lame-398-2/misc/mlame to your .wav directory /var/spool/asterisk/monitor (or wherever your .wavs are)
11. chmod +x mlame
12. Edit the convert_recordings.sh recorddir variable to match your .wav directory path (no trailing ‘/’). The default directory is set to /var/spool/asterisk/monitor
13. Run the script by navigating to the directory and ./recordings_convert.sh
You should see it take a few seconds for each file and go on. I usually test it out by letting it convert a few files then Cntrl + C and ls -l the directory to check the filesizes and timestamps. There is a commented out section at the bottom of recordings_convert.sh that moves the .wav files to a separate directory (easier to check if it worked) and in my case, I keep the old files for a month or so for job security reasons. If you lose a bunch of verification recordings, you are going to have major problems.
Cron it, at it, and happy converting.
__________________________________
Code for .g729 to MP3 script. Very dirty, but works, please test on a small group of test files first.
#!/bin/bash
#Author: Gregg Hansen 20080414
#Used to convert from .g729 -in and -out files to .mp3
#Run on Recordings server
for i in `ls /ramdiskunload/*.g729`;
do
#convert all .g729 to wav first, then soxmix
DST=`echo $i | sed 's/.g729/.wav/g'`
asterisk -rx "file convert $i $DST"
rm -f $i
mv $DST /recordings
done
#all files should now be in the /recordings directory
#use soxmix and mlame to convert them to one file => mp3
for j in `ls /recordings/*-in.wav`;
do
INFILE=`echo $j | sed 's/-in/-out/g'`
MIXED=`echo $j | sed 's/-in//g'`
soxmix $j $INFILE $MIXED
rm -f $j
rm -f $INFILE
/root/test/mlame -f -o "-b 16 -m m -q 9 --resample 8" $MIXED
done
-----------------------------------------------------------------
Code for .g729 to wav script. Very dirty, but works, please test on a small group of test files first.
#!/bin/bash
#Author: Gregg Hansen 20080414
#Used to convert from .g729 -in and -out files to .mp3
#Run on Recordings server
for i in `ls /root/mix/*.gsm`;
do
#convert all .g729 to wav first, then soxmix
LDST=/root/mix/recordings
DST=`echo $i | sed 's/.gsm/.wav/g'`
asterisk -rx "file convert $i $DST"
rm -f $i
mv $DST $LDST
done
#all files should now be in the /recordings directory
#use soxmix and mlame to convert them to one file => mp3
for j in `ls /root/mix/recordings/*-in.wav`;
do
INFILE=`echo $j | sed 's/-in/-out/g'`
MIXED=`echo $j | sed 's/-in//g'`
soxmix $j $INFILE $MIXED
rm -f $j
rm -f $INFILE
#/root/lame/misc/mlame -f -o "-b 16 -m m -q 9 --resample 8" $MIXED
done
I am getting the error as "/bin/ls: Argument list too long" when trying to run the script.
ReplyDeleteit might be due to a large number of files.brief me what you want to exactly, like what kind of script you are looking for
ReplyDelete