Use mpg321 and sox to emulate mpg123

Comment on Asterisk mpg123 faking it
tries
Joined: Mon 14 of Mar, 2005

Use mpg321 and sox to emulate mpg123

Posted:Mon 14 of Mar, 2005 (21:22 UTC)
The mpg321 package is not cabable of producing the proper raw stream format required by Asterisk. Mpg321 simply ignores unknown commandline switches and produces a raw stream with the same sample rate and chanels as the input file (e.g. 44100, stereo). Asterisk needs a single channel (mono) raw stream with 8000Hz sample rate.
As I did not want to start installing another mp3 player software on that box, I made s small wrapper script to combine (the existing) mpg321 and sox to generate the proper output format:

/usr/local/bin/asterisk_play.sh:
  1. !/bin/sh
mpg321 -q -s -z --wav - $* | sox -t wav - -t raw -c1 -r8000 -w2 - 2>/dev/null;

My musiconhold.conf looks:
;
; Music on hold class definitions
;
[classes]]
default => custom:/home/hb9xar/asterisk/var/lib/asterisk/mohmp3,/usr/local/bin/asterisk_play.sh
loud => mp3
/home/hb9xar/asterisk/var/lib/asterisk/mohmp3
random => quietmp3
/home/hb9xar/asterisk/var/lib/asterisk/mohmp3,-z

That's it.