In FreePBX users can listen to wav file recordings via the “Call Recordings” tab, This uses a field in the mysql cdr table to say where that recording is and what its called, They are now stored in year/month/day directory structure under /var/spool/asterisk/monitor so if the end user wants the recordings in mp3 format as many do its not just a case of converting them its also a case of updating the database.
Luckily this is fairly straight forward, its just a case of doing a quick query and then converting the file and the updating the database. First you have to install lame, This can be done simply with yum then write a script.
In FreePBX advanced settings, you need to enable “Display” and “Override” readonly settings and then add
/usr/local/sbin/postrecord.sh ^{CDR(linkedid)} to “
The script I use is simple with a bit of basic logging.
#!/bin/bash . postrecconfig.sh date >> /var/log/asterisk/mp3.log pcmwav=$(mysql -u$user -p$secret -s -N -D asteriskcdrdb<<<"select recordingfile from cdr where linkedid LIKE '$1' AND disposition = 'ANSWERED' ORDER by calldate DESC LIMIT 1"); mp3="$(echo $pcmwav | sed s/".wav"/".mp3"/)" nice lame -b 16 -m m -q 9-resample "$path$pcmwav" "$path$mp3" >> /var/log/asterisk/mp3.log touch -r "$path$pcmwav" "$path$mp3" >> /var/log/asterisk/mp3.log mysql -u$user -p$secret -s -N -D asteriskcdrdb<<<"UPDATE cdr SET recordingfile='$mp3' WHERE recordingfile = '$pcmwav'" >> /var/log/asterisk/mp3.log echo $pcmwav >> /var/log/asterisk/mp3.log echo "--------||-------" >> /var/log/asterisk/mp3.log date >> /var/log/asterisk/mp3.log echo "Done" >> /var/log/asterisk/mp3.log echo "--------||-------" >> /var/log/asterisk/mp3.log exit 1 The postrecconfig.sh file looks like user=freepbxuser secret=secret receptemail=info@youremailaddress.com file_age=35 dy=$(date '+%Y') dm=$(date '+%m') dd=$(date '+%d') path=/var/spool/asterisk/monitor/$dy/$dm/$dd/ As can be seen it steps through entry by entry converting and updating the DB, This example is cron'd to run hourly but does not delete the original wav file, this would be done in a separate script run weekly to remove old files. The reason to keep them is so that a backup of the original is held for a period in case of errors.
Hope this is of help to you and your users