Recording Calls in FreePBX 2.5

Exclusive offer: get 50% off this eBook here
FreePBX 2.5 Powerful Telephony Solutions

FreePBX 2.5 Powerful Telephony Solutions — Save 50%

Configure, deploy, and maintain an enterprise-class VoIP PBX

£14.99    £7.50
by Alex Robar | August 2009 | Networking & Telephony Open Source

In this article by Alex Robar, we will learn about the call recording features of FreePBX. We will learn how to set up permanent or selective call recordings for specific extensions, conferences, or queues. We will discuss the various recording formats, general call recording options, recording calls, and finally maintaining call recordings using cron.

Asterisk has a wonderful, built-in ability to record calls. No additional software is required to make this happen. When Asterisk records a call, both sides of the call are recorded and written out to a file for playback on a computer. Call recording is often performed in call centers to ensure call quality, or to keep calls for later review, should the need arise. Asterisk provides the ability to record all of the calls, or to selectively record calls.

In this article, we will look the following:

     
  • General recording options
  • Recording calls to extensions
  • Recording calls to queues
  • Recording calls to conferences
  • Maintaining call recordings

Before enabling call recording for your PBX, make sure that you are aware of the legalities surrounding call recordings and privacy laws. Call recordings are prohibited in certain places, unless the caller is told that the call will be recorded. For example, in the state of California all of the parties on the call must consent to the call being recorded before it begins. Playing back a message stating that the call is being recorded prior to the call being answered is considered a valid form of consent.

Recording formats

FreePBX allows calls to be recorded in the following formats:

  • WAV
  • WAV49
  • ULAW
  • ALAW
  • SLN
  • GSM

Each format has its own ratio of file size to recording quality, and certain formats will not play on all of the computers. A comparison between all of the  available formats is as follows:

FreePBX 2.5 Powerful Telephony Solutions Configure, deploy, and maintain an enterprise-class VoIP PBX
Published: August 2009
eBook Price: £14.99
Book Price: £24.99
See more
Select your format and quantity:

Format

Description

WAV

Uncompressed WAV format recording. Sound quality will be very

good, but the file will be very large in size (roughly 1 megabyte per

minute of the recording). WAV format recordings are natively playable

on nearly all of the computers without additional software.

WAV49

WAV format recorded using the GSM codec. As GSM is a compressed codec, the sound quality is compromised. Sound quality on a GSM recording is usually equivalent to the quality that is achieved during mobile telephone calls. File size is much smaller than a standard WAV (roughly 100 kilobytes per minute of the recording); WAV49 files are often difficult to play on computers without additional software that understands the GSM codec.

ULAW or ALAW

G.711 codec recording. The recording quality is excellent, and should

sound exactly like the call did to all of the parties who were on the

original call. File size is very large (similar to the WAV format at

about 1 megabyte per minute). ULAW and ALAW recordings are very

difficult to play on most computers. There are very few computers that will play the recording without additional software that understands

the G.711 codec.

SLN

Asterisk native SLINEAR format. Recordings that are in SLN format

will have the same quality and file size as WAV recordings. SLN recordings are raw WAV, little endian 16-bit signed linear (PCM)

format recordings. Most computers will play these files, although some software packages refuse to play them unless the extension is renamed to .wav from .sln.

GSM

GSM codec recording. As with WAV49 calls, the quality of GSM

recordings is less than that of ULAW/ALAW or WAV calls, but is

generally acceptable for most purposes. GSM recordings weigh in at

around 100 kilobytes per minute.

One very important aspect of call recording to keep in mind is that if the recording uses a different codec than the original call, transcoding must occur. For example, a call that uses the G.711 ULAW codec that is being recorded using the WAV49 format will need to be transcoded into the GSM codec before being saved. Transcoding recordings place additional load on a server's disk I/O and processor resources. On high traffic systems, it is possible to max out all of the available resources if the transcoding recordings are not accounted for.

In general, the rule of thumb for recording will be the same as it is for selecting the codec that a trunk or extension will use: try to make everything match. If all of the calls are using the GSM codec, then it would be safe to record those calls in the GSM format. A system that has all of the calls in G.711 ULAW format would be put under an unnecessary amount of stress to record in GSM format. If transcoding is required (for example, limited disk space dictates the use of GSM recordings), be sure to size the resources of the system accordingly in order to allow the additional load.

General call recording options

FreePBX has several settings that govern the global operation of call recording. These settings determine if call recording should be globally enabled or disabled, which format to record calls in, and a command to run after a call  has been recorded (if desired).

In order to access the global options, click on General Settings in the navigation menu on the left as shown in the following screenshot:

Recording Calls in FreePBX 2.5

The Call Recording section has the settings that we are interested in:

Recording Calls in FreePBX 2.5

The Extension Recording Override option allows all user-level automatic call recording to be disabled. A user can be set up to record all of the calls (which will be discussed shortly). If this option is set to Enabled, all of the user settings will be ignored and calls will not be recorded automatically. Note that this option neither affects recording settings for queues or conferences, which can be set up in order to record all of the calls, nor does it affect on-demand recording. This setting only affects users who have been set up to automatically record all of the calls. If this field is  set to Disabled then the user-level recording options will be respected.

The Call recording format field allows us to change the format of the call in which it will be stored. The default value is wav, but can be changed to WAV (WAV49—a GSM file stored as a wav), ulaw, alaw, sln, gsm, and g729. More information on recording formats can be found earlier in this article in the Recording  formats section.

Recording calls to extensions

FreePBX allows all of the calls to a particular user to be recorded, or for calls to be selectively recorded. FreePBX allows the choice between recording only incoming calls, only outgoing calls, or both.

In order to set up call recording for a particular user, click on Users or Extensions in the navigation bar on the left (this depends on the operational mode in which FreePBX is running.

Recording Calls in FreePBX 2.5

Click on the name of the user you wish to edit and scroll down to the Recording Options section:

Recording Calls in FreePBX 2.5

The Record Incoming and Record Outgoing settings can be configured as On Demand, Always, or Never.

When the On Demand option is selected, the user can dial *1 during a call to start recording the call. *1 can be dialed again to stop recording the call. The on demand toggle only lasts for the current call. In order to record the next call, the user would have to dial *1 again.

If these options are set to Always, then all of the calls in the selected direction will be recorded. When Always is  selected, pressing *1 will not stop call recording.

If these options are set to Never, then no calls in the selected direction will be recorded. When Never is selected,  pressing *1 will not start recording.

Be sure to click on the Submit button, followed by the orange-colored Apply Configuration Changes bar at the top of  the screen in order to save any changes made to the recording settings.

Recording calls to queues

All the calls to a particular queue can be recorded. This is often used on larger call queues for later call review by management, or to resolve disputes about what was said on a particular call. In order to record all of the calls that are picked up out of a particular queue, click on the Queues link under the Inbound Call Control menu on the left as shown in the following screenshot:

Recording Calls in FreePBX 2.5

Click on the name of the queue in the menu on the right, which needs call recording enabled:

Recording Calls in FreePBX 2.5

Under Queue Options, the Call Recording drop-down menu can be changed to wav49, wav, and gsm.

Recording Calls in FreePBX 2.5

Select the desired recording format, click on the Submit Changes button, and click on the orange-colored Apply Configuration Changes bar in order to enable recording on the queue.

Note that queues tend to have a high volume of calls. It is important to select an appropriate call recording format, and to ensure that recordings are maintained and cleaned up periodically. More information on recording formats can be found earlier in the Recording formats section of this article. Recording maintenance is discussed later in this article in the Maintaining call recordings section.

FreePBX 2.5 Powerful Telephony Solutions Configure, deploy, and maintain an enterprise-class VoIP PBX
Published: August 2009
eBook Price: £14.99
Book Price: £24.99
See more
Select your format and quantity:

Recording calls to conferences

All of the calls to a particular conference room can be recorded. All of the members of the conference will be recorded and merged into a single file. In order to enable call recordings for a particular conference, select Conferences from the Internal Options & Configuration menu on the left as shown in the  following screenshot:

Recording Calls in FreePBX 2.5

Select the conference room that should have recording enabled from the menu on the right:

Recording Calls in FreePBX 2.5

Under Conference Options, the Record Conference drop-down menu will turn recording on or off:

Recording Calls in FreePBX 2.5

Selecting Yes will record the entire conference (from the time the first member joins) in WAV format (more information on the WAV format can be found earlier in this article in the Recording formats section). Selecting a different format to record the conference in is not currently supported. Once Yes has been selected from the Record Conference drop-down menu, click on the Submit Changes button followed by the orange-colored Apply Configuration Changes button in  order to enable call recordings for the conference.

Maintaining call recordings

It is worth noting that call recordings can be quite large. If left unattended, a PBX that automatically records all of the calls will eventually fill up the entire available hard disk space and stop processing calls. It is important to have a maintenance strategy for dealing with call recordings in order to avoid this. While third-party tools exist to maintain recordings,  adequate maintenance can often be performed with simple shell scripts.

The most common way of maintaining call recordings is to automate the deletion of recordings that are older than a certain time frame. The following  script called OldRecordingDeletion.sh will remove all of the recordings  older than 14 days.

#!/bin/bash

# Change this path to reflect your recording storage
# location
RECORDINGS=/var/spool/asterisk/monitor

# Change this number to reflect the maximum age of call
# recordings
RECORDINGEXPIRY=14

# Change this number to reflect the maximum age of the
# deletion logs
LOGEXPIRY=365

# Current date
DATE=`date`

# Delete recordings older than $EXPIRY days
find $RECORDINGS -mtime +$EXPIRY -exec rm -rfv > removal-$DATE.log

# Delete log files older than $LOGEXPRY
find . -mtime +$LOGEXPIRY -exec rm -rf

It is best to run a script like this once a day. Adding the following line to  cron will execute the script from the /etc/recordingdeletion file once  daily at 5:00 a.m.:

0 5 * * * /etc/recordingdeletion/OldRecordingDeletion.sh

More information on using the cron system can be found later in this article  in the Using cron section.

Another possible method of maintaining recordings is to find the longest calls, and only keep them (since the longer calls are often the calls that prove problematic). The script below (SmallRecordingDeletion.sh) will delete all of the recordings under 15 MB.

The following script is written for maintaining recordings of a single format, and defaults to removing recordings that are less than 15 megabytes in size. This is equivalent to about 15 minutes of calls that are recorded in WAV, ULAW, ALAW, or SLN format. For WAV49 or GSM formats, recordings in a 15 megabyte file would contain over two hours of call time. For these formats, the equivalent value for 15 minutes of talk time is about 1.5 megabytes. If recordings are in multiple formats (for example, queues are recorded in GSM format while conferences are in WAV format),  the script would need to be modified to only remove a specific format.

#!/bin/bash

# Change this path to reflect your recording storage
# location
RECORDINGS=/var/spool/asterisk/monitor

# Change this number to reflect the minimum size of
# recordings
RECORDINGSIZE=15

# Change this number to reflect the maximum age of the
# deletion logs
LOGEXPIRY=365

# Current date
DATE=`date`

# Delete recordings older than $EXPIRY days
find $RECORDINGS -size -$RECORDINGSIZE M -exec rm -rfv > removal-$DATE.log

# Delete log files older than $LOGEXPRY
find . -mtime +$LOGEXPIRY -exec rm -rf

This script should also be run once per day. Adding the following line to  cron will execute the script from /etc/recordingdeletion once daily at  5:00 a.m.:

0 5 * * * /etc/recordingdeletion/SmallRecordingDeletion.sh

Using cron

The cron system allows scheduled executions of any command that can be run from the server's command line. The easiest way to add an entry to cron is to edit the crontab file using the following command:

crontab -e

If the crontab file has not been edited previously, crontab manager may ask which editor to use by providing a numbered list such as the one below:

Select an editor. To change later, run 'select-editor'. 
1. /usr/bin/vim.tiny
2. /bin/ed
3. /bin/nano <---- easiest

Press the number that corresponds with the desired editor and then press the Enter key. If crontab has not previously been used, then a blank text file will be opened for editing. If the file has previously been edited, then all of the existing entries will be shown in the text editor.

In order to add a new entry to the file, simply place your cursor at the end of the file (below all other text) and start typing. A crontab entry should use the following syntax: (min) (hour) (day) (month) (dayofweek) (command).  Each token can be replaced as follows:

  • (min) can be replaced with the minute when the command should be run. For example, if the command is to be run at 2:30 a.m., enter 30 for the minute. Valid values are any whole numbers between zero and 59.
  • (hour) should be replaced with the hour when the command should be run. For the previous example, running a command at 2:30 a.m. would replace (hour) with 2. Valid values are any whole numbers between zero and 23.
  • (day) should be replaced with the day of the month that the command should be run on. For example, to run a command on July 20th, enter 20. Valid values are whole numbers between one and 31. Note that the system will not generate an error if the entered date does not exist (for example, entering a cron job to run on September 31st will not generate an   error). If an invalid date is entered, the command will never run.
  • (month) should be replaced with the number corresponding to the month that the command is to be run in. For example, to run the command on July 20 enter 7 (because July is the seventh month). Valid values are whole numbers between one and 12.
  • (dayofweek) should be replaced with the number corresponding to the day of the week that the command should be run on. For example, to run a command on a Thursday, enter 4 (because counting from Sunday as day zero, Thursday is the fourth day of the week). Valid values are whole numbers between zero and seven. Sunday can either be zero or seven, cron will recognize both.
  • (command) should be replaced with the shell command that is being run. As cron does not run under a particular shell, it has no environment variables and does not know the path to various system executables. The full path to a command must be entered. For example, in order to reboot the system each time the cron job is executed, the command would be /sbin/reboot now.

For any of the timing values (minute, hour, day, month, or day of week), an asterisk (*)  can be used to represent all of the possible values. For example, the following cron entry would reload Asterisk's configuration on the fifteenth minute of every hour:

15 * * * * /usr/sbin/asterisk -rx "reload"

A range of values can also be specified in order to execute a command within a specific time frame. For example, the cron entry below would reload Asterisk's configuration once on the fifteenth minute of every hour, but only on business days:

15 * * * 1-5 /usr/sbin/asterisk -rx "reload"

It is also possible to specify a set of values using a comma (,). For example, the cron entry below would reload Asterisk's configuration once per hour on the fifteenth minute of the hour, only during business hours (excluding lunch hour), and only on business days:

15 9,10,11,13,14,15,16,17 * * 1-5 /usr/sbin/asterisk -rx "reload"

The previous entries are a  single cron entry and should be typed on a single line.

Finally, the forward slash (/) can be used to specify what is known as "step values". Step values allow a command to be run a fraction of the amount of times it would be normally within a given time frame. For example, specifying 9-17/2 for the hour field would execute the command every two hours between the hours of 9:00 a.m. and 5:00 p.m. instead of once per hour during that time frame. The following cron entry would reboot the server on the first day of every third month at 2:00 a.m.:

0 2 * */3 * /sbin/reboot now

Once the entry has been completed, save the file and close the text editor (the method to accomplish this is different based on which editor is being used). A message will be displayed indicating that the cron file has been updated with a new version:

crontab: installing new crontab

The schedule for cron entries can be changed any time by reopening the crontab file for editing.

About the Author :


Alex Robar

Alex Robar has worked in the IT industry for seven years. He is currently the Technical Services Manager for a Canadian Managed Services Provider. He has worked with open source telephony solutions for the past four years, and has collaborated on the development and growth of an international Asterisk-based VoIP peering network.

Books From Packt

Asterisk 1.4 – the Professional’s Guide
Asterisk 1.4 – the Professional’s Guide

Cacti 0.8 Network Monitoring
Cacti 0.8 Network Monitoring

Building Enterprise Ready Telephony Systems with sipXecs 4.0
Building Enterprise Ready Telephony Systems with sipXecs 4.0

Joomla! 1.5 SEO
Joomla! 1.5 SEO

Ext JS 3.0 Cookbook
Ext JS 3.0 Cookbook

Pentaho Reporting 3.5 for Java Developers
Pentaho Reporting 3.5 for Java Developers

Solr 1.4 Enterprise Search Server
Solr 1.4 Enterprise Search Server

Symfony 1.3 Web Application Development
Symfony 1.3 Web Application Development

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software