[asterisk-users] Voiceprompts i.e. voicemail and conferencing in multiple codecs

Kenny Watson kwatson at geniusgroupltd.com
Tue Jul 6 04:36:10 CDT 2010



----- Original Message -----
From: "Steve Edwards" <asterisk.org at sedwards.com>
To: "Asterisk Users Mailing List - Non-Commercial Discussion" <asterisk-users at lists.digium.com>
Sent: Friday, 2 July, 2010 5:08:14 PM
Subject: Re: [asterisk-users] Voiceprompts i.e. voicemail and conferencing in multiple codecs

On Fri, 2 Jul 2010, Kenny Watson wrote:

> for i in `ls -R /var/lib/asterisk/sounds/uk/*wav`;  # do recursive ls and only list wav files and loop through each one
>     do # start do loop
>     CONV=`echo $i|sed 's/.wav/.g729/g'` # set CONV variable as filename with wav swapped for G729
>     asterisk -rx "file convert $i $CONV" # run convert command placing original filename and new filename in command
>     done # end loop

First off, Digium provides "core" prompts in many encodings at

 	http://downloads.asterisk.org/pub/telephony/sounds/

Assuming those packages don't meet your needs, this script doesn't do what 
you intended.

Because you specified "*wav," the "ls -R" is not recursing through the 
directories, it's only listing the wav files in the specified directory. 
Without the "*wav," ls would recurse, but it wouldn't display the path.

The "find" command is a better tool for this.

Compare:

 	$ ls -R /var/lib/asterisk/sounds/*wav | wc -l
 	241

and

 	$ find /var/lib/asterisk/sounds/ -name '*.wav' | wc -l
 	1596

And then, a few suggestions* on "better practices."

) Use "$(" and ")" instead of back-ticks. They can be nested and they 
survive emailing, printers (the human kind), telephones, and strange fonts 
better.

) Use shell functions instead of processes. You create 2 processes for 
every file just to substitute the file type.

) Use upper case for variables** so they "stand out."

) Don't use single character variable names -- we don't code in FORTRAN 
any more do we? Also, they're obtuse and a bitch to search for in an 
editor.

) Use comments before a block of code instead of line by line.

 	# Recurse through the input path, [ab]using Asterisk*** to
 	# convert WAV files to G729
 		INPUT_PATH=/var/lib/asterisk/sounds/
 		for	INPUT in $(find ${INPUT_PATH} -name '*.wav')
 			do
 			OUTPUT=${INPUT%.wav}.g729
 			asterisk -r -x "file convert ${INPUT} ${OUTPUT}"
 			done
 	# (end of snippet)

I'm sure some shell weenie could code it all up in a single arcane line of 
cruft, but the goal should be clarity and maintainability.

*) I recognize some of these suggestions reflect my "religious beliefs." 
If you all would "get over it" and "just convert" we can all "just get 
along."

**) Being an "old-school c weenie" I don't know why I prefer upper case 
for variables in shell scripts, but I do. Whatever case you prefer, be 
consistent.

***) I know command line g729 encoders are hard to come by, but do you 
really want to explain to your boss that you crashed the PBX trying to 
convert some really funny Alison prompts you found on the net but one of 
them had a funky header and it exposed a hither-to unknown bug?

-- 
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards       sedwards at sedwards.com      Voice: +1-760-468-3867 PST
Newline                                              Fax: +1-760-731-3000

-- 
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
               http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Hi Steve,

Thank you for the extensive response, I'm using some UK prompts on my system so would like to convert them to g729.

The new script and tips on scripting will be helpful.

Thanks

Kenny



More information about the asterisk-users mailing list