Randomness

Archive for the ‘asterisk’ Category

Original script page;

Asterisk music on hold

This script converts a directory full of MP3s to another directory with the same files in native formats (WAV, GSM and U-Law) – see recipe Music-on-hold without MPG123 for an overview of how this works.

FROMDIR="/root/mp3s"
TODIR="/root/transcodes"
for i in $FROMDIR/*.mp3
do
BASEFILE=$(basename $i .mp3)
echo Converting $BASEFILE
mpg123 -s --rate 44100 --mono $FROMDIR/$BASEFILE.mp3 > $TODIR/$BASEFILE.raw
sox -r 44100 -w -s -c 1 $TODIR/$BASEFILE.raw -r 8000 -c 1 $TODIR/$BASEFILE.wav
sox $TODIR/$BASEFILE.wav -t gsm -r 8000 -b -c 1 $TODIR/$BASEFILE.gsm
sox $TODIR/$BASEFILE.wav -t ul -r 8000 -b -c 1 $TODIR/$BASEFILE.pcm
rm -f $TODIR/$BASEFILE.raw
done

Please set FROMDIR and TODIR as you best see fit (they can also be the same directory).

===============================================

http://astrecipes.net/index.php?from=153&q=astrecipes/music-on-hold+without+mpg123

When playing the music on hold, Asterisk will usually decode MP3 files using the external utility MPG123. This setup is less than perfect, as:
star MPG123 is run as an external process, so it must be launched once for every music class
star MPG123 will sometimes complain of the MP3 data used
star MPG123 will sometimes not loop the sound over, so the caller ends up listening to silence
star MPG123 will sometimes start eating up a lot of CPU with no apparent reason
star Live MP3 decoding is, in any case, an expensive, CPU-hungry activity

In this recipe, we’ll show how to convert the MP3 files to a native WAV format and then use that as a source of sound. The resulting file is surely larger, buy the few megabytes of disk lost are usually well paid-for in Asterisk well-being.

First of all, create a directory for your new music on hold; we may create it as /var/lib/asterisk/moh-default. All files in this directory will be played to the caller, one after the other. Of course, you can also have only one file with your music on hold if you have to.

The following commands will translate the standard file fpm-sunshine.mp3 to a correctly formatted WAV file:

mpg123 -s --rate 44100 --mono /src/mp3/fpm-sunshine.mp3 > fpm-sunshine.raw
sox -r 44100 -w -s -c 1 fpm-sunshine.raw -r 8000 -c 1 fpm-sunshine.wav
rm fpm-sunshine.raw

Repeat as you prefer for all the MP3 files you want to include.

You then have to edit the musiconhold.conf file in order to tell Asterisk to play those files instead of the standard MP3’s:

[default]
mode=files
directory=/var/lib/asterisk/moh-default
random=yes

Create an entry for each of the music classes you want to play (the one above will substitute the default one).

Restart Asterisk and make sure no more MPG123’s are running.

From the Asterisk shell, use the moh classes show command to see which music classes are currently defined and moh files show to see the actual files being played by Asterisk.

If you have a number of files that you want to convert all in one pass, this script to convert music-on-hold to native formats may prove handy.

Further avoiding transcoding
When Asterisk plays back native MOH (as we are doing with this recipe), it checks the sound file by extension and tries to find the one with the minimum cost compared to the current in-use codec, just like it usually does for sound files.
This means that if you have fpm-sunshine.wav and fpm-sunshine.gsm in your moh-default directory, and your telephone is using the GSM codec, Asterisk will try to use the .gsm file in order to avoid any transcoding at all.
While transcoding from SLIN format (the one we used in the WAV file above) is usually the cheapest, if we know that our system uses GSM or U-Law very often, it could be a good idea to transcode to GSM and U-Law too; this is easily obtained with a couple of Sox calls:

sox fpm-sunshine.wav -t gsm -r 8000 -b -c 1 fpm-sunshine.gsm
sox fpm-sunshine.wav -t ul -r 8000 -b -c 1 fpm-sunshine.pcm

The first line transcodes from SLIN to GSM, the second from SLIN to ULaw. This helps keeping the system load to a minimum (playing music-on-hold accounts for a non-trivial portion of most PBXs live activity!)

Pulled from voipinfo.org

Using Ruby on Rails Migrations the below will support any combination of database that ActiveRecord and Asterisk Realtime Architecture support, including of course MySQL and Postgres.

Ruby on Rails Models are then provided to be dropped into any Ruby on Rails application that requires the ability to configure Asterisk via the Asterisk Realtime Architecture.

ActiveRecord::Schema.define() do
#Use the same table for IAX2 and SIP configuration
create_table "devices", :force => true do |t|
t.column :name, :string, :limit => 80
t.column :accountcode, :string, :limit => 20
t.column :amaflags, :string, :limit => 13
t.column :callgroup, :string, :limit => 10
t.column :callerid, :string, :limit => 80
t.column :canreinvite, :string, :limit => 3, :default => 'yes'
t.column :context, :string, :limit => 80
t.column :defaultip, :string, :limit => 15
t.column :dtmfmode, :string, :limit => 7
t.column :fromuser, :string, :limit => 80
t.column :fromdomain, :string, :limit => 80
t.column :fullcontact, :string, :limit => 80
t.column :host, :string, :limit => 31, :default => 'dynamic'
t.column :insecure, :string, :limit => 4
t.column :language, :string, :limit => 2
t.column :mailbox, :string, :limit => 50
t.column :md5secret, :string, :limit => 80
t.column :nat, :string, :limit => 5, :default => 'no'
t.column :deny, :string, :limit => 95
t.column :permit, :string, :limit => 95
t.column :mask, :string, :limit => 95
t.column :pickupgroup, :string, :limit => 10
t.column :port, :string, :limit => 5, :default => ''
t.column :qualify, :string, :limit => 3
t.column :restrictcid, :string, :limit => 1
t.column :rtptimeout, :string, :limit => 3
t.column :rtpholdtimeout, :string, :limit => 3
t.column :secret, :string, :limit => 80
t.column :type, :string, :limit => 6, :default => 'friend'
t.column :username, :string, :limit => 80
t.column :disallow, :string, :limit => 100
t.column :allow, :string, :limit => 100
t.column :musiconhold, :string, :limit => 100
t.column :regseconds, :integer, :limit => 11, :default => 0
t.column :ipaddr, :string, :limit => 15, :default => '0'
t.column :regexten, :string, :limit => 80
t.column :cancallforward, :string, :limit => 3, :default => 'yes'
t.column :setvar, :string, :limit => 100
#Additional fields for IAX2
t.column :dbsecret, :string, :limit => 100
t.column :inkeys, :string, :limit => 100
t.column :outkey, :string, :limit => 100
t.column :auth, :string, :limit => 100
end

#Asterisk extensions table
create_table "extensions", :force => true do |t|
t.column :context, :string, :limit => 20, :null => false
t.column :exten, :string, :limit => 20, :null => false
t.column :priority, :integer, :limit => 4, :default => 0
t.column :app, :string, :limit => 20, :null => false
t.column :appdata, :string, :limit => 128, :null => false
end

#Asterisk queues table
create_table "callqueues", :force => true do |t|
t.column :name, :string, :limit => 128
t.column :musiconhold, :string, :limit => 128
t.column :announce, :string, :limit => 128
t.column :timeout, :integer, :limit => 11
t.column :monitor_join, :boolean
t.column :monitor_format, :string, :limit => 128
t.column :queue_youarenext, :string, :limit => 128
t.column :queue_thereare, :string, :limit => 128
t.column :queue_callswaiting, :string, :limit => 128
t.column :queue_holdtime, :string, :limit => 128
t.column :queue_minutes, :string, :limit => 128
t.column :queue_seconds, :string, :limit => 128
t.column :queue_lessthan, :string, :limit => 128
t.column :queue_thankyou, :string, :limit => 128
t.column :queue_reporthold, :string, :limit => 128
t.column :announce_frequency, :integer, :limit => 11
t.column :announce_round_seconds, :integer, :limit => 11
t.column :announce_holdtime, :string, :limit => 128
t.column :retry, :integer, :limit => 11
t.column :wrapuptime, :integer, :limit => 11
t.column :maxlen, :integer, :limit => 11
t.column :servicelevel, :integer, :limit => 11
t.column :strategy, :string, :limit => 128
t.column :joinempty, :string, :limit => 128
t.column :leavewhenempty, :string, :limit => 128
t.column :eventmemberstatus, :boolean
t.column :eventwhencalled, :boolean
t.column :reportholdtime, :boolean
t.column :memberdelay, :integer, :limit => 11
t.column :weight, :integer, :limit => 11
t.column :timeoutrestart, :boolean
end

#Asterisk voicemail extended table
create_table "voicemailboxes", :force => true do |t|
t.column :customer_id, :string, :limit => 11, :null => false
t.column :context, :string, :limit => 50, :default => '0'
t.column :mailbox, :string, :limit => 11, :null => false
t.column :password, :integer, :limit => 5, :default => '0'
t.column :fullname, :string, :limit => 150, :null => false
t.column :email, :string, :limit => 50, :null => false
t.column :pager, :string, :limit => 50, :default => ''
t.column :tz, :string, :limit => 10, :default => 'central'
t.column :attach, :string, :limit => 4, :default => 'yes'
t.column :saycid, :string, :limit => 4, :default => 'yes'
t.column :dialout, :string, :limit => 10, :default => ''
t.column :callback, :string, :limit => 10, :default => ''
t.column :review, :string, :limit => 4, :default => 'no'
t.column :operator, :string, :limit => 4, :default => 'no'
t.column :envelope, :string, :limit => 4, :default => 'no'
t.column :sayduration, :string, :limit => 4, :default => 'no'
t.column :saydurationm, :integer, :limit => 4, :default => 1
t.column :sendvoicemail, :string, :limit => 4, :default => 'no'
t.column :delete, :string, :limit => 4, :default => 'no'
t.column :nextaftercmd, :integer, :limit => 4, :default => 'yes'
t.column :forcename, :integer, :limit => 4, :default => 'no'
t.column :forcegreetings, :integer, :limit => 4, :default => 'no'
t.column :hidefromdir, :string, :limit => 4, :default => 'yes'
t.column :stamp, :timestamp
end

#Asterisk voicemail extended table
create_table "voicemailmessages", :force => true do |t|
t.column :msgnum, :integer, :limit => 11, :default => 0
t.column :dir, :string, :limit => 80, :default => ''
t.column :context, :string, :limit => 80, :default => ''
t.column :macrocontext, :string, :limit => 80, :default => ''
t.column :callerid, :string, :limit => 40, :default => ''
t.column :origtime, :string, :limit => 40, :default => ''
t.column :duration, :string, :limit => 20, :default => ''
t.column :mailboxuser, :string, :limit => 80, :default => ''
t.column :mailboxcontext, :string, :limit => 80, :default => ''
t.column :recording, :longblob
end

end