Upgrade 3CX to v18 and get it hosted free!

Asterisk mpg123 faking it

Author image

How to replace MPG123 with SOX for musiconhold

Note: Asterisk 1.2 has solved the “mpg123 issue” and comes with a cleaner solution, so what is described below essentially is only of interest for Asterisk 1.0.x users.

As an alternative to using mpg123 you can use sox to convert a wav file into the right format for asterisk and use cat to “play” the file

Example with converted files if you do not want to install mpg123 or sox
Note: If the rawplayer method is not playing back any music, try adding “.mp3” to the end of the .raw filenames.

sox -V moh.wav -r 8000 -c 1 -w moh.raw

You could use audacity (open the mp3 then File -> Export as WAV…) or xmms to convert the mp3 to wav

  • Option 1: Hacking mpg123 and playing a single file

Then make a file called /usr/local/bin/mpg123 with the following contents

#!/bin/sh

while [ 1 ]; do cat /path/to/moh.raw || exit; done

I think you need to uncomment the default line in the sample Asterisk config musiconhold.conf for Asterisk to try and launch mpg123

  • Option 2: Use custom mode in musiconhold.conf and use rawplayer script

The musiconhold configuration includes a “custom” mode that lets you specify the program to run in order to play your (faked) mp3’s. We can use this to run our own “rawplayer” instead of mpg123.
Put something like this in musiconhold.conf:

[classes]

default => custom:/var/lib/asterisk/mohmp3/default,/usr/bin/rawplayer

classic => custom:/var/lib/asterisk/mohmp3/classic,/usr/bin/rawplayer

Then make an executable file /usr/bin/rawplayer like this:

#!/bin/sh

for name in $@; do

cat $name ;

done

And finally convert your mp3 files to raw as stated above an place them in subdirectories default an classic under /var/lib/asterisk/mohmp3 and (VERY IMPORTANT!) rename them from *.raw to *.mp3 (as Asterisk expect they are named that way):

# cd /var/lib/asterisk/mohmp3/default

# rename .raw .mp3 *.raw

Now restart Asterisk and you have your “default” and “classic” music available with less cpu load.

See Also


Asterisk | Tips & Tricks | FAQ


Article Reviews

Write a Review

Your email address will not be published. Required fields are marked *

Required Field. Minimum 5 characters.

Required Field. Minimum 5 characters, maximum 50.

Required field.There is an error with this field.

Required Field.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

There are no reviews for this article. Be the first one to write a review.

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.