#!/bin/bash # Version : 0.3 # Author : Mats Karlsson @ Rebtel # Date : 2006-05-09 # Scoop : Convert voice prompts from wav format to FreeSWITCH (www.freeswitch.org) # native formats (using res_convert in Asterisk). # Converts to G.729, G.723, G.711 Alaw/Ulaw, and GSM # # Requirements: # Asterisk 1.4 or 1.6 with res_convert loaded # G.729 codec installed in Asterisk # Digium hardware transcoder for G.723 # sox # # # Thanx to Kristian Kielhofner for the help and inspiration to create this script. # # Modified by Kristian Kielhofner to support multiple formats # more easily # # Modified again by Kristian Kielhofner to support FreeSWITCH #Source directory (where are your files?) SDIR=/root/fs-native/sounds #Dest directory (where do you want them to go?) DDIR=/root/fs-native/conv # Formats to convert to. Asterisk format:mod_native extension FORMATS="g729:G729 g723:G723 alaw:PCMA ulaw:PCMU gsm:GSM" # Convert Wav to SLN and resample wavs to 8KHz that is demanded by Asterisk # This looks really ugly but I wanted it to work recursively # But don't resample if we are already 8KHz - TODO: use sox instead of file # TODO: Support G.722, Siren, CELT, etc for X in `find $SDIR -iname *.wav`; do FNAME=`echo $X | sed -e s,$SDIR,,g` DNAME=`echo $FNAME | sed -e s,.wav,.sln,g` MKDIR=`dirname $DNAME` mkdir -p $DDIR/$MKDIR if `file $SDIR/$FNAME | grep -q "8000 Hz"`; then echo "Converting $FNAME to sln using sox" sox $SDIR/$FNAME -t raw -r 8000 -s -w -c 1 $DDIR/$DNAME else echo "Converting and resampling $FNAME to sln using sox" sox $SDIR/$FNAME -t raw -r 8000 -s -w -c 1 $DDIR/$DNAME resample -ql fi done for Y in `find $DDIR -iname *.sln`; do FNAME=`echo $Y |sed -e s,$DDIR,,g` for i in $FORMATS; do # Convert SLN to $FORMAT with help of asterisk and convert (see ref) FORMAT=`echo $i | cut -d: -f1` EXTEN=`echo $i | cut -d: -f2` ANAME=`echo $FNAME | sed -e s,.sln,.$FORMAT,g` DNAME=`echo $FNAME | sed -e s,.sln,.$EXTEN,g` # Asterisk requires the Asterisk-style extension to know format echo "Converting $FNAME to $FORMAT using asterisk" asterisk -rx "file convert $DDIR/$FNAME $DDIR/$ANAME" > /dev/null # Move it to mod_native_file compatible naming mv $DDIR/$ANAME $DDIR/$DNAME done done # Remove Asterisk sln files # find $DDIR -iname *.sln | xargs rm -f