Categories
Asterisk Linux

Recording and mixing Asterisk’s calls

One of the most valuable features of the Asterisk PBX server is its recording support. However, before playing the audio files, we must merge both sides of the recorded call. This article was written based on Asterisk version 16 and Sox v14.4.1.

The first step is enabling this feature in the extensions file /etc/asterisk/extensions.conf. The application used for recording is MixMonitor.

In this example, we used the parameter as follows:

exten => s,n,MixMonitor(${UNIQUEID}.wav49)

Note that, ${UNIQUEID} is the filename and .wav49 is the extension, which means that Asterisk will convert audio files by using the WAV format.

After settings are applied, the new recording files will be placed on the directory /var/spool/asterisk/monitor

Before listening to these audios, you should mix them whether they were created from incoming or outgoing calls. Here, we use the the program called sox.

Mixing incoming calls:

/usr/bin/sox -m DIR_MONITOR/FILENAME-in.wav DIR_MONITOR/FILENAME-out.wav OUTPUT-PATH

Where:

DIR_MONITOR: The full path of audio files (/var/spool/asterisk/monitor).

FILENAME: The unique ID given by Asterisk when it was created. In this case, we have (-in) for one side of the call and (-out) for the other one. For example, 1617641548.58651-in.wav and 1617641548.58651-out.wav

OUTPUT-PATH: The full path containing the directory and the filename of the new mixed audio. For example: /var/spool/asterisk/records/my-record.wav

Mixing outgoing calls:

In this case, we must set the frequency to 8000 Mhz, define the channels to mono, and its format to WAV. It is important to notice that we just handle one single file.

/usr/bin/sox DIR_MONITOR/FILENAME.WAV -r 8000 -c 1 -e signed-integer OUTPUT-PATH

I strongly recommend that you make a script to deal with these recordings, store the new files safety and erase the previous ones. This is important to save disc space of the Asterisk server.

Categories
Asterisk Database Linux

Asterisk + ODBC + Mysql

The latest versions of the Asterisk PBX server connect to the Mysql database server by using ODBC. In this tutorial, I will show you how to set this up.

My test environment is CentOS Linux released on 7.9.2009, Asterisk 16.16.0, unixODBC 2.3.1, and Mysql Community Server 8.

I am taking for granted that you already have your Mysql installed and running. If you have not taken this step yet, you should use a tutorial like this one.

1 – Install the Unix ODBC:

# yum -y install unixODBC

2 – Download the official Mysql library connector from: https://dev.mysql.com/downloads/connector/odbc/

# wget https://cdn.mysql.com//Downloads/Connector-ODBC/8.0/mysql-connector-odbc-8.0.23-linux-glibc2.12-x86-64bit.tar.gz

Decompress the package in /usr/local directory or wherever you like.

# tar -zxvf mysql-connector-odbc-8.0.23-linux-glibc2.12-x86-64bit.tar.gz -C /usr/local

3 – Edit the file /etc/odbcinst.ini and insert the following code block:

[MySQL_ANSI]
Driver=/usr/local/mysql-odbc/lib/libmyodbc8a.so
sageCount=1

4 – Edit the file /etc/odbc.ini and create your connection:

[asterisk-connector]
Description = MySQL connection
Driver = MySQL_ANSI
Database = asterisk
Server = 127.0.0.1
Port = 3306

5 – Now, you must configure your Asterisk to use the connection. The file which contains that information is /etc/asterisk/res_odbc.conf

[asterisk]
enabled => yes
dsn => asterisk-connector
username => user
password => secret
pre-connect => yes
max_connections => 100

6 – Finally, make sure that Asterisk is using the ODBC module, take a look at the file /etc/asterisk/modules.conf and find the following line:

preload => res_odbc.so

If you have any questions, please use the comment box below.