#!/bin/bash ROOT="/opt/asterisk-1.2.7.1/var/spool/voicemail" LOG="/var/log/asterisk/vm-audio" CONTEXT="${1}" EXTEN="${2}" COUNT="${3}" VMDIR="${ROOT}/${CONTEXT}/${EXTEN}/INBOX" echo "Checking ${VMDIR}" >> ${LOG} checkExit() { if ! [ "${1}" = "0" ]; then echo "${2}" >> ${LOG} exit 1 fi } if ! [ -d "${VMDIR}" ]; then checkExit 1 "${VMDIR} is not a directory" fi for file in $( ls -1 ${VMDIR}/*.txt 2>> ${LOG} ); do FIXCOUNT=$( grep -c "volume-fix" ${file} 2>> ${LOG} ) if [ ${FIXCOUNT} = 0 ]; then BASE=$( echo "${file}" | sed -e "s/.txt$//" 2>> ${LOG} ) VMFILE="${BASE}.WAV" SCALE=$( sox "${VMFILE}" -e stat -v 2>&1 ) if ! [ $? = 0 ]; then echo "Unable to convert file: ${VMFILE}" >> ${LOG} continue fi if ! [ "${SCALE}" = "1.000" ]; then NFILE="/tmp/${$}.wav" sox ${VMFILE} -v ${SCALE} ${NFILE} >> ${LOG} 2>&1 if ! [ $? = 0 ]; then echo "Unable to scale file: ${VMFILE}" >> ${LOG} rm -f ${NFILE} > /dev/null 2>> ${LOG} continue fi mv -f "${NFILE}" "${VMFILE}" > /dev/null 2>> ${LOG} echo "volume-fix=true" >> ${file} 2>> ${LOG} fi fi done