Asterisk Sound Files

Asterisk is able to play audio files in a variety of formats as long as the necessary software for each format is installed. It's not difficult to convert an audio file for use with the majority of Asterisk installations. This article is a convenient reminder of the command line parameters required for the task.

Normally I edit audio files using Audacity and save the results into WAV or MP3 format files. Next, the files need to be converted into a format that is convenient for common installations of asterisk. One such format is called Signed PCM. The details that we want to target for this conversion are:

  • a sample rate of 8k per second
  • 16 bit (signed) samples
  • a single channel (mono)
  • a .sln file extension (because it is recognized by asterisk.)

Many current Linux distros offer a convenient program called SOX that can perform the actual conversion. Fedora/Redhat/CentOS users can get this software by simply installing sox. Ubuntu users need to install both the sox package and a package containing additional plugins:

$ sudo apt-get install sox libsox-fmt-all    (Ubuntu users)
$ sudo yum install sox (Fedora/Redhat/CentOS users)

To convert a common wav or mp3 file into the desired Signed PCM format we can use the following sox command:

sox <input-file.wav/.mp3>     \
    --type raw                \ # using a raw format (sox does not recognize the .sln extension)
    --encoding signed-integer \ # Signed samples
    --bits 16                 \ # 16 bit sample width
    --channels 1              \ # single (mono) channel
    --rate 8k                 \ # 8k sample rate

The long options above are easier to remember but they are not supported by older copies of sox that you will tend to find installed with many common asterisk installations. The short options are as follows:

sox <input-file.wav/.mp3>         \
    -t raw     \ # using a raw format
    -s         \ # Signed samples
    -w         \ # 16 bit samples
    -c 1       \ # mono / single channel
    -r 8000    \ # 8k sample rate

You can play the resulting file using the play program, like this:

play --type raw                \ # using a raw format (sox does not recognize the .sln extension)
     --encoding signed-integer \ # Signed samples
     --bits 16                 \ # 16 bit samples
     --channels 1              \ # mono / single channel
     --rate 8k                 \ # 8k rate

(Older versions of sox use soxplay instead of play.) The play utility will confirm the specifications of the converted file:


 File Size: 856k      Bit Rate: 128k
  Encoding: Signed PCM    
  Channels: 1 @ 16-bit   
Samplerate: 8000Hz       
Replaygain: off         
  Duration: 00:00:53.50  

In:100%  00:00:53.50 [00:00:00.00] Out:428k  [      |      ] Hd:4.9 Clip:0    

Note that the high bitrates are not really useful on the PSTN but they work. The higher bitrates require additional CPU overhead so it's a good idea to avoid them if possible.