How to convert audio files to ulaw, alaw, gsm, g722, etc. for Asterisk

After ordering the voice acting from a professional announcer and cutting in the sound editor, it was necessary to save the sounds in different formats, the original was in wav, so I’ll give an example of converting through sox (it already was in the system with Asterisk):

sox -V vm-intro.wav -r 8000 -c 1 -t ul vm-intro.ulaw
sox -V vm-intro.wav -r 8000 -c 1 -t al vm-intro.alaw
sox -V vm-intro.wav -r 8000 -c 1 -t gsm vm-intro.gsm

The codec g722 does not seem to support it, at least in man sox did not find it, so it installed ffmpeg (on the Ubuntu Server system):

sudo apt-get install ffmpeg

And performed the conversion:

ffmpeg -i vm-intro.wav -ar 16000 -acodec g722 vm-intro.g722

Standard directory with Asterisk sounds – /usr/share/asterisk/sounds

SMS sending script via Goip4 gateway

Here is an example of a script written in PHP, for sending SMS messages through the Goip4 gateway.
The script receives data from the SQL database with a query and alternately sends SMS to each number, and also writes an entry about sending it to a special sms table.
Continue reading “SMS sending script via Goip4 gateway”

Managing Asterisk modules

Let’s connect to the Asterisk console:

sudo asterisk -rvv

Let’s see what modules are already in use:

module show

Files of modules with the extension * .so are in the directory /usr/lib/asterisk/modules/

To load and unload a module, commands are used (the module name is specified without a file extension, for example, not chan_sip.so, but chan_sip):

module load NAME
module unload NAME

In order for the necessary modules to be loaded automatically when starting Asterisk, they must be specified in the file /etc/asterisk/modules.conf, for example, open it in the text editor nano:

sudo nano /etc/asterisk/modules.conf

You can enable the autoloading of all existing modules in the folder /usr/lib/asterisk/modules/:

[modules]
autoload=yes

And then we can exclude unnecessary ones using the following commands:

noload => module.so

Either prohibit downloading all and specify only those that are needed, for example:

;SIP VoIP driver
load => chan_sip.so
load => res_rtp_asterisk.so
load => app_dial.so
load => bridge_simple.so
load => res_features.so
load => res_musiconhold.so
load => res_adsi.so
load => pbx_config.so
; List of required codecs
load => codec_a_mu.so
load => codec_adpcm.so
load => codec_alaw.so
load => codec_ulaw.so
load => codec_gsm.so
load => codec_ilbc.so
load => codec_lpc10.so
; If you use Dahdi cards for analog lines
load => chan_dahdi.so
; Call parking
load => res_parking.so 
; Below are the modules I needed when setting up call recording
; требуется если используется res_monitor.so
load => func_periodic_hook.so
; Required if res_monitor.so is used, the function STRFTIME
load => func_strings.so
; Required if res_monitor.so is used to determine the number, function CALLERID
load => func_callerid.so
; Required if res_monitor.so is used for MixMonitor
load => app_dial.so
; For recording calls
load => res_monitor.so
; To support WAV format
load => format_wav.so
; For MP3 format support
load => format_mp3.so
; To record statistics of calls to MySQL database
load => cdr_mysql.so
; To enable SNMP functionality, for example, to collect statistics by various monitoring systems
load => res_snmp.so
; To make calls from the context of the placed files to the directory /var/spool/asterisk/outgoing/
load => pbx_spool.so

To apply the changes in the /etc/asterisk/modules.conf file, execute the command from the Asterisk console:

module reload

If necessary, you can reboot Asterisk as follows:

sudo service asterisk restart