An updated version of our script to bulk convert wav call recordings to mp3 as mentioned here.

This version may be redistributed freely, as long as the copyright message remains.

#!/bin/bash
# A Script to Convert FreePBX call recordings from WAV to MP3
# Also updates the CDR database, for correct downloads through the web UI
# Version 3 - 2018/07/16
#
# Changelog
# v3 - Skip Replay Gain Analysis
# v2 - Skip broken files (but show an error message)
# v1 - Initial version
#
# Copyright Jaytag Computer Limited 2018 - www.jaytag.co.uk
#
# You may use or modify this script as you wish as long as this copyright
# message remains. Redistribution is permitted.

# Set the Asterisk Recording Directory
recorddir="/var/spool/asterisk/monitor/"

# Start the Loop
for wavfile in `find $recorddir -name \*.wav`; do

# Make Variables from the WAV file names
wavfilenopath="$(echo $wavfile | sed 's/.*\///')"
mp3file="$(echo $wavfile | sed s/".wav"/".mp3"/)"
mp3filenopath="$(echo $mp3file | sed 's/.*\///')"

# Convert the WAV files to MP3, exit with an error message if the conversion fails
nice lame -b 16 -m m -q 9-resample --noreplaygain "$wavfile" "$mp3file" && rm -frv $wavfile || echo "$wavfile encoding failed"

# Update the CDR Database, only if conversion is sucessful
if [ -e "$mp3file" ]
then
mysql -u root -s -N -D asteriskcdrdb<<<"UPDATE cdr SET recordingfile='$mp3filenopath' WHERE recordingfile = '$wavfilenopath'"
echo "DBUPDATE -------------------------------------------------------"
echo "DBUPDATE - $wavfilenopath changed to $mp3filenopath in CDR DB"
echo "DBUPDATE -------------------------------------------------------"
echo ""
fi

# On-Screen display of variables for debugging/logging
# echo ""
# echo "File -------------------------------------------------------"
# echo "Wav File : " $wavfile
# echo "Wav No Path : " $wavfilenopath
# echo "MP3 File : " $mp3file
# echo "MP3 No Path : " $mp3filenopath
# echo "End File ---------------------------------------------------"
# echo ""

# End the Loop
done

Previous Post Next Post