How to set sample rate and encoding of audios generated by Monitor()

Hello everyone, I am new to Asterisk. Recently I am given a task to automatically record calls using Asterisk. The required sample rate is 8000 and sample encoding is “8-bit a-law”. Now I am using Monitor() in extensions.conf to make audio recording. However, the sample encoding of generated recordings is “16-bit Signed Integer PCM”.

I thought there should exist some methods for me to change the sample encoding, but I didn’t find it. Then I tried to change it using sox like this in hangup handler:

exten => _x.,n,System(sox “/home/telephone/asterisk_recording/${CALLERID(number)}/${FILENAME}-in_temp.wav” -b 8 -e a-law “/home/telephone/asterisk_recording/${CALLERID(number)}/${FILENAME}-in.wav”)

The first wav file in this command is the original audio make by Monitor(), and the second is what I want. But it cannot give me satisfying result. No matter how long the original audio is, the volume of second file is only 58 bytes with no length and cannot be played. If I run the same command in Terminal after the call is finished, then everything goes fine.

I also tried StopMonitor(), but it didn’t work.

So, I wonder is there any way for me to set the sample rate and sample encoding of audios generated by Monitor() without running other commands out of Asterisk?


Most people would use MixMonitor these days.

You are probably trying to process the files whilst they are still open, so the media is present, but the metadata that gives its length is not. You can use StopMonitor to close out the files.

You can presumably use the MONITOR_EXEC variable to specify post processing after the files are closed.

If you want A-lay, you can specify alaw as the file format, but you will not get RIFF (.wav) wrappers; it will be a pure G.711 media stream with no metadata.

MixMonitor also will not write RIFF headers on A-law data.

The only formats on which Asterisk will write RIFF headers are .wav (8khZ, 16bit, signed linear) and .wav49 (alias .WAV) (standard rate GSM).

1 Like