Asterisk Audio Formats Explained

Getting Started -- Last reviewed 2026-06-26 audio music-on-hold sox formats codec Found this useful? Upvote it. ×

Asterisk plays audio files for music on hold, IVR prompts, and voicemail greetings. For best performance, these files should be in a native codec format so Asterisk does not need to transcode them in real time. This guide explains each supported format, when to use it, and how to convert files on the command line.

Supported formats

Format Extension Use case
G.711 u-law .ulaw North American telephony (T1/PRI lines). Most common Asterisk format.
G.711 a-law .alaw European and international telephony (E1 lines).
GSM .gsm Good compression, widely compatible. Default for many Asterisk installations.
WAV (PCM) .wav Uncompressed 8 kHz 16-bit. Highest quality, largest file size.
Signed Linear .sln Raw PCM with no header. Asterisk internal format. Smallest overhead.
G.722 .g722 Wideband (16 kHz). Higher quality on PJSIP endpoints that support it.

All narrowband formats use 8 kHz sample rate and mono (single channel). G.722 uses 16 kHz for wideband audio on endpoints that support it.

ulaw vs alaw: which one do I need?

Both are G.711 codecs encoding audio at 64 kbps. They sound nearly identical but are not interchangeable. U-law (mu-law) is the standard in North America and Japan, used on T1/PRI lines. A-law is the standard in Europe and most other regions, used on E1 lines.

Check what codec your SIP trunk or ISDN lines use and convert to match. If your system handles both (common with PJSIP), provide files in both formats and let Asterisk pick the right one.

When to use G.722 wideband

G.722 uses 16 kHz sampling (twice the bandwidth of G.711) and sounds noticeably better for voice. If your PJSIP endpoints negotiate G.722 (most modern IP phones support it), providing .g722 files means callers on hold or listening to IVR prompts get wideband audio. Asterisk will fall back to narrowband formats for endpoints that do not support G.722.

G.722 conversion requires ffmpeg since sox does not support the codec natively.

Why provide multiple formats?

When Asterisk needs to play audio, it looks for a file in the codec that matches the caller's channel. If your MOH directory only has .wav files but the caller is on a G.711 u-law channel, Asterisk transcodes in real time, using CPU. On a busy system with many concurrent calls on hold, this adds up.

If you provide the same file in multiple formats (.ulaw, .alaw, .gsm, .wav, .g722), Asterisk picks the best match with zero transcoding overhead.

Converting files with sox

sox (Sound eXchange) is the standard command-line tool for Asterisk audio conversion. The basic command resamples to 8 kHz, converts to mono, and encodes to the target format:

sox input.mp3 -r 8000 -c 1 -t ul output.ulaw
sox input.mp3 -r 8000 -c 1 -t al output.alaw
sox input.mp3 -r 8000 -c 1 output.gsm
sox input.mp3 -r 8000 -c 1 -b 16 output.wav
ffmpeg -i input.mp3 -ar 16000 -ac 1 -acodec g722 output.g722

Add lowpass 3400 highpass 300 after the output filename for telephone bandpass filtering. Add gain -n -3 for volume normalization.

If you prefer not to install sox locally, the Asterisk Audio Converter runs the same commands on the server and lets you download all formats at once.

Rotating hold-music start positions

Asterisk's default music-on-hold behavior selects a file randomly from the directory but always plays it from the beginning. With only one track, every caller hears the same opening chords. Rotated variants create the perception of variety without needing additional source music: take a single track, clip it at evenly spaced points, and append the clipped portion to the end.

This matters even for small phone systems. A dental office, a small law firm, or a retail shop may not get many calls, but the callers they do get (patients, clients, vendors) are often the same people calling back. Without rotation, those repeat callers hear the exact same 30 seconds of hold music every time. With rotated variants, Asterisk picks a different start point for each hold session, so the music feels fresh even though it comes from one source file.

Place all the variants in your Asterisk MOH directory. Asterisk will randomize across them automatically:

[default]
mode=files
directory=/var/lib/asterisk/moh/default
; Place hold-music.ulaw, hold-music-offset-30s.ulaw, etc. in this directory

Rotation works best with tracks at least 10-15 seconds long. Very short clips produce abrupt seams when rotated.

See also

User Notes

Know a tip or gotcha for this topic? Share it below and help others.

Contribute a note

Share a tip, gotcha, or practical example. Keep it under 2000 characters. No questions (use the Asterisk community forums for support). Wrap code in backticks.

Moderated before publishing. Email never shown.
Related Snippets