Recording Audio for Asterisk

Standards
The audio standard for most Voice over IP is 8000Hz, 16Bit, Mono. Asterisk is going to expect that all audio conforms to this standard. There are a lot of codecs that are used to compress the audio, the most common being ULAW, GSM, and G729. The PSTN will only accept ULAW or G729. G729 is patented, so you have to pay for a license to use it. Digium, the company that controls Asterisk, charges $10 per channel for G729! ULAW isn’t very compressed but the sound quality is great and it’s free.

Software
Perhaps the best utility for recording audio on your computer is Audacity (I say the “best” because it is cross platform, open source and works very well.)

Unfortunately, while Audacity is great at what it does, the formats that it can save audio files to aren’t ideal for telephony applications. By default Asterisk prefers audio files that are encoded with the GSM or ULAW codec.
This is not to say that Asterisk can’t deal with WAV or other types of files (it can in some cases), but for transmission over VoIP connections those formats will have to be converted on the fly which uses processing power and you can’t be sure of the results.

Fortunately we have an application called SoX (Sound eXchange) installed on the server to help you out.

Command for ULAW and GSM:

sox originalfile.wav -r 8000 -c1 newfile.ul

sox originalfile.wav -r 8000 -c1 newfile.gsm

The “-r 8000” means resample the file to 8000Hz. “-c1” means only one channel (mono) in the output file (just in case you start with a stereo file).

SoX has a lot more capabilities as well which you will find out about in your reading.

To use your brand new sound with Asterisk, you should copy it into your Asterisk Sounds directory (asterisk_sounds):

When you call it up for playback you must use the full path (minus the extension).

exten => s,n,Playback(/home/ck987/asterisk_sounds/mynewsound);

It is probably also a good idea to change the group and permissions of the file if you later want to have Asterisk modify it in some way.

chgrp asterisk /home/ck987/asterisk_sounds/mynewsound.ulaw

chmod 664 /home/ck987/asterisk_sounds/mynewsound.ulaw

More Information:
VoIP info on Recording audio for Asterisk
SoX – Sound eXchange
Hacks 24, 25 and 26 from O’Reilly’s VoIP Hacks book