Asterisk Does Not Translate From Wav To Alaw

Home » Asterisk Tips » Asterisk Does Not Translate From Wav To Alaw
Asterisk Tips No Comments

Use sox to downsample to 8khz (and 1 chan), and the problems should go away. While you are at it, you could use sox to convert to the target format in a single operation.

The scripts that Digium uses to take Allison’s voice prompts (at 48khz) to the different formats, convert things to slin (raw) as a central format, but in my experience, the fewer steps the better. But I doubt that anyone could detect the difference in the end result.

Here’s what I do with CD-qual sounds to turn them into the common Asterisk formats:

Assume $i is the name of the .wav file you want to convert:

x=`basename $i .wav`
sox -v 0.7 $i -r 16000 -c 1 -t sw $x.sln16
sox -v 0.7 $i -r 8000 -c 1 -t sw $x.raw
sox -r 8000 -c 1 -t sw $x.raw -t gsm $x.gsm ## OR ### sox -v 0.7 $i -r 8000 -t gsm $x.gsm
sox -r 8000 -c 1 -t sw $x.raw -t ul $x.ulaw ## OR ### sox -v 0.7 $i -r 8000 -t ul $x.ulaw
sox -r 8000 -c 1 -t sw $x.raw -t al $x.alaw ## OR ### sox -v 0.7 $i -r 8000 -t wav $x.wav
rm $x.raw
y=`pwd`
sudo asterisk -rx “file convert $y/$i $y/$x.g722″

 

I’m ignoring the siren & g729 formats; use asterisk for those in like format, depending on your asterisk version and codecs. Allison normalizes the volume of sounds she distributes; use the -v 0.7 to bring the volume down a bit to the standard, and your sounds won’t stick out against rest of Allison’s existing recordings in Asterisk. Digium uses a filter program to ‘heighten’ the sounds a little; That’s the main reason, I think, that they use the .raw format as an in-between. I’ve been skipping this step, as it doesn’t seem critical, in which case the direct conversion is probably preferable.

I suggest, that if you are converting sounds for Asterisk’s sake, that you convert to all the possible formats. Disk space is cheap, and you’ll squeeze a little extra performance out of Asterisk by allowing it to pick the ‘best’ format. Dahdi type interfaces would prefer the ulaw/alaw formats; High-def phones like Snom (and appropriate Polycoms, etc) could use the g722. Ulaw and gsm transcodings are cheap, but no transcoding is cheaper still.

If you load “res_convert.so”, you will have a CLI command “file convert …”.
Usage: file convert
Convert from file_in to file_out. If an absolute path is not given, the default Asterisk sounds directory will be used.

Example:
file convert tt-weasels.gsm tt-weasels.ulaw

or,

asterisk -rx “file convert /home/user/tt-weasels.gsm /home/user/tt-weasels.g729″