# Asterisk Call Recording with MixMonitor: Formats, Stereo, Retention

Source: https://srvscripts.com/guides/asterisk-call-recording-mixmonitor/
Updated: 2026-10-06
Publisher: srvScripts (https://srvscripts.com/)

**Short answer:** Asterisk records calls with the `MixMonitor()` application, for example `MixMonitor(/var/spool/asterisk/monitor/${UNIQUEID}.wav)`. Add `r(file)` and `t(file)` to also save each direction separately, then merge the two into a stereo file with `sox -M`. FreePBX wraps the same application: it writes to `/var/spool/asterisk/monitor/YYYY/MM/DD/` in the format set by **Call Recording Format** (wav by default). Asterisk never deletes recordings, so you need your own retention job.

We ran these commands on our lab server (Debian 12, FreePBX 17.0.33, Asterisk 22.11) on 6 October 2026: we recorded a test call with the `r()` and `t()` options and merged the result to stereo. The output blocks below come from that run.

## How MixMonitor works

MixMonitor attaches an audiohook to a channel and writes what it hears to a file. By default it mixes both directions into one mono file. The syntax, from Asterisk 22’s own help (`core show application MixMonitor`), is:

```
MixMonitor(filename.extension[,options[,command]])
```

- **filename.extension**: an absolute path, or a name relative to the monitor directory in `asterisk.conf` (`/var/spool/asterisk/monitor` on a default install). The extension sets the format: `wav`, `WAV` (GSM in a WAV container), `gsm`, `ulaw`, `alaw`, `sln` and others your build supports.

- **options**: letters that change behaviour (table below).

- **command**: a shell command run after the recording ends, for example to convert or upload the file.

MixMonitor does not answer the call. In your own dialplan, put it after `Answer()` or `Progress()`, or before `Dial()` so it records the bridged call. `StopMixMonitor()` stops it early and releases the file.

To see which formats your server can write, run `core show file formats`.

## Useful MixMonitor options

These are the options listed by Asterisk 22.11 on our lab server:

| Option | Effect |
| --- | --- |
| a | Append to an existing file instead of overwriting |
| b | Only record while the channel is bridged (skips ringing and IVR) |
| B([interval]) | Play a periodic beep while recording (default every 15 seconds) |
| r(file) | Also write the received audio to its own file |
| t(file) | Also write the transmitted audio to its own file |
| D | Write a 2-channel interleaved stream instead of mixing; you must use a .raw extension |
| n | With r()/t(), do not insert silence to keep the two files in sync |
| s(seconds) | Do not record until this many seconds have passed (skip announcements) |
| v(x) / V(x) / W(x) | Adjust heard, spoken or both volumes (-4 to 4) |
| p / P | Beep when recording starts / stops |
| i(var) | Store the MixMonitor ID in a variable, for StopMixMonitor(ID) |
| m(mailbox) | Copy the recording into a voicemail box |

The Asterisk 22 help text warns twice about command injection: do not put untrusted values such as `${CALLERID(num)}` or `${CALLERID(name)}` into the filename or command arguments unless you wrap them in `FILTER()`.

## Record a call in stereo with r() and t()

Speech analytics, transcription and QA tools work much better with the agent on one channel and the caller on the other. MixMonitor gives you two ways to get there.

### Option 1: separate legs, merged afterwards

This is the dialplan we used in a temporary test context on lab3. It writes a normal mixed file plus one file per direction:

```
exten => rec-stereo,1,Answer()
 same => n,Set(RDIR=/var/spool/asterisk/monitor/srvs-test-voip)
 same => n,MixMonitor(${RDIR}/mixed-${UNIQUEID}.wav,r(${RDIR}/rx-${UNIQUEID}.wav)t(${RDIR}/tx-${UNIQUEID}.wav))
 same => n,Playback(demo-congrats)
 same => n,Hangup()
```

The directory must exist and be writable by the `asterisk` user:

```
install -d -o asterisk -g asterisk /var/spool/asterisk/monitor/srvs-test-voip
```

We placed a test call with a Local channel, so one side played `hello-world` and the other played `demo-congrats`:

```
asterisk -rx "channel originate Local/rec-stereo@srvs-test-voip application Playback hello-world"
```

Three files appeared, all 8 kHz, 16-bit mono WAV of the same length (output from `soxi`, trimmed):

```
== mixed-1791263274.21.wav
Channels       : 1
Sample Rate    : 8000
Precision      : 16-bit
Duration       : 00:00:01.40 = 11200 samples ~ 105 CDDA sectors
== rx-1791263274.21.wav
Channels       : 1
Sample Rate    : 8000
Duration       : 00:00:01.40 = 11200 samples ~ 105 CDDA sectors
== tx-1791263274.21.wav
Channels       : 1
Sample Rate    : 8000
Duration       : 00:00:01.40 = 11200 samples ~ 105 CDDA sectors
```

Because MixMonitor pads the r() and t() files with silence to keep them aligned (unless you pass `n`), they merge cleanly. `sox -M` puts the first file on the left channel and the second on the right:

```
sox -M rx-1791263274.21.wav tx-1791263274.21.wav stereo-1791263274.21.wav
soxi stereo-1791263274.21.wav
```

```
Channels       : 2
Sample Rate    : 8000
Duration       : 00:00:01.40 = 11200 samples ~ 105 CDDA sectors
```

Each leg had different audio (RMS amplitude 0.168 on rx and 0.132 on tx in our test), which confirms the two directions really were separated. You can run the merge in MixMonitor’s third argument so it happens when the call ends, but keep that command simple and do not feed it caller-controlled strings.

### Option 2: one interleaved file with D

The `D` option writes a single 2-channel stream. The Asterisk help says you must use a `.raw` extension, otherwise the file is corrupt. Raw files have no header, so you need to tell sox the format when converting. We did not run this option on lab3; option 1 is easier to handle.

## Call recording in FreePBX 17

FreePBX calls MixMonitor for you. On our FreePBX 17 lab, the generated dialplan (`extensions_additional.conf`) records with a line of this shape:

```
MixMonitor(${MIXMON_DIR}${YEAR}/${MONTH}/${DAY}/${CALLFILENAME}.${MON_FMT},a${MONITOR_REC_OPTION}i(${LOCAL_MIXMON_ID})${MIXMON_BEEP},${MIXMON_POST})
```

Where recording is switched on:

- **Per extension:** the extension’s **Recording Options** cover Inbound External Calls, Outbound External Calls, Inbound Internal Calls, Outbound Internal Calls and On Demand Recording.

- **Per route or queue:** inbound routes, outbound routes, ring groups and queues have their own recording settings.

- **Call Recording module:** creates a destination with a **Call Recording Mode** (Force, Yes, Don’t Care, Never) you can place in a call flow.

- **On demand:** the feature code **In-Call Asterisk Toggle Call Recording** (default `*1` in the FreePBX 17 core module) starts and stops recording during a call when the extension allows it.

Three Advanced Settings control the files. We read their current values on lab3 with `fwconsole setting`:

```
fwconsole setting MIXMON_FORMAT     # "Call Recording Format", default wav
fwconsole setting MIXMON_DIR        # "Override Call Recording Location", empty = default spool
fwconsole setting MIXMON_POST       # "Post Call Recording Script", empty by default
```

With `MIXMON_DIR` empty, files land in `/var/spool/asterisk/monitor/YYYY/MM/DD/`. The format choices offered are wav, WAV, ulaw, alaw, sln, gsm and g729. The CDR field `recordingfile` holds the file name, which is what the CDR Reports page uses for playback.

**Post Call Recording Script** runs after hangup and accepts variables such as `^{CALLFILENAME}`, `^{MIXMON_FORMAT}` and `^{MIXMON_DIR}` (the `^{}` form delays evaluation until the script runs). That is the hook to convert to MP3 or push files to storage.

## Formats and disk space

Recording size depends on the format, not the call codec. Asterisk transcodes to whatever extension you choose.

| Format | What it is | Rough size per minute (8 kHz) |
| --- | --- | --- |
| wav | 16-bit signed linear PCM in WAV | ~960 KB (8000 samples x 2 bytes x 60 s) |
| ulaw / alaw | G.711, 8 bits per sample, no header | ~480 KB |
| WAV / gsm | GSM 06.10 compressed | Much smaller; lower quality |
| MP3 (converted later) | Not written by MixMonitor itself | Depends on bitrate |

The PCM and G.711 figures are arithmetic from the sample rate; GSM depends on framing, so check a real file with `ls -l`. Plan disk space from your own call volume: minutes per day x size per minute x retention days.

Can MixMonitor write MP3 directly? Our FreePBX 17 lab lists an `mp3` format in `core show file formats`, because the `format_mp3` add-on is loaded. But in the Asterisk 22 source that module’s write function only logs `I Can't write MP3 only read them.` It is for playback, not recording.

For MP3, record in wav and convert afterwards. Our [recordings-to-MP3 script](/scripts/asterisk-recordings-to-mp3/) bulk-converts FreePBX recordings and updates the CDR, the [MP3 conversion guide](/guides/convert-asterisk-recordings-to-mp3/) explains the steps, and the browser-based [Call Recording Converter](/tools/call-recording-converter/) handles one-off GSM, WAV49, mu-law and SLN files.

## Retention: delete old recordings safely

Neither Asterisk nor open-source FreePBX deletes recordings on a schedule. Decide a retention period that matches your legal and contract obligations, then automate it. First list what would be removed:

```
find /var/spool/asterisk/monitor -type f -mtime +90 \( -name '*.wav' -o -name '*.WAV' -o -name '*.mp3' -o -name '*.gsm' \) | head
find /var/spool/asterisk/monitor -type f -mtime +90 | wc -l
```

The next command permanently deletes files. Make sure older recordings are backed up or exported first if anyone may need them (disputes, compliance), and run the dry-run list above before enabling it.

```
find /var/spool/asterisk/monitor -type f -mtime +90 \( -name '*.wav' -o -name '*.WAV' -o -name '*.mp3' -o -name '*.gsm' \) -delete
find /var/spool/asterisk/monitor -mindepth 1 -type d -empty -delete
```

Schedule it with cron, for example daily at 03:15 in `/etc/cron.d/recording-retention`, and run it as root or the asterisk user. Deleting files leaves CDR rows that point to missing recordings; that is harmless but the play button in CDR Reports will fail for those rows.

## Common problems

- **No file at all:** the directory does not exist or is not owned by `asterisk`. Check `ls -ld` on the target and watch `/var/log/asterisk/full` for MixMonitor warnings.

- **Recording starts during ringing or IVR:** add the `b` option, or use `s(seconds)` to skip a fixed announcement.

- **Only one side audible:** usually a media path problem, not recording. If the live call is one-way, the recording will be too; see our [one-way audio guide](/guides/voip-one-way-audio/).

- **File is unreadable after using D:** the extension was not `.raw`.

- **Recording missing from CDR Reports:** the `recordingfile` CDR field is empty or the file moved. Converting to MP3 without updating CDR has the same effect.

- **Disk full:** check `du -sh /var/spool/asterisk/monitor` and add the retention job above.

**Official documentation:** [Asterisk: MixMonitor application](https://docs.asterisk.org/Latest_API/API_Documentation/Dialplan_Applications/MixMonitor/) · [Asterisk: StopMixMonitor application](https://docs.asterisk.org/Latest_API/API_Documentation/Dialplan_Applications/StopMixMonitor/) · [SoX documentation](https://sourceforge.net/projects/sox/)

**Related:** [Asterisk Recordings to MP3: Bulk Convert FreePBX Call Recordings](/scripts/asterisk-recordings-to-mp3/) · [Convert Asterisk Call Recordings to MP3 (FreePBX, Issabel)](/guides/convert-asterisk-recordings-to-mp3/) · [Call Recording Converter: GSM, WAV49, µ-law and SLN to MP3](/tools/call-recording-converter/) · [VoIP One-Way Audio Fix: 6 Checks for NAT and RTP](/guides/voip-one-way-audio/)

**See also:** [Transcribe Asterisk and FreePBX Call Recordings on Your Own Server (faster-whisper, Tested)](/guides/transcribe-asterisk-recordings-faster-whisper/)

## Frequently asked questions

### Where does FreePBX store call recordings?

By default in /var/spool/asterisk/monitor/YYYY/MM/DD/. The Advanced Setting Override Call Recording Location (MIXMON_DIR) changes the base folder.

### How do I record each side of the call separately?

Add r(file) and t(file) to MixMonitor. They write the received and transmitted audio to separate files, which you can merge into stereo with sox -M.

### Can Asterisk record directly to MP3?

No. The format_mp3 add-on can play MP3 files but its write function refuses to write them. Record in wav and convert with lame, ffmpeg or a post-recording script.

### Does Asterisk delete old recordings automatically?

No. Add a cron job with find -mtime to remove files older than your retention period, after a dry run and a backup.

### Why is the D option output unreadable?

D writes a raw interleaved two-channel stream. Asterisk requires the .raw extension for it, and you must tell your converter the sample format.
