This will walk you through, step-by-step, how to enable your sound card's line-in or mic-in to be used for music-on-hold. Please make sure you have proper permission to re-broadcast the audio you use.
On my system, arecord uses one process, no CPU and only 0.1% memory, doesn't matter how many callers are on hold, so if your server is tight on resources, this may help free up a little bit.
Credit for the initial instructions goes to cress in thread: http://trixbox.org/forums/trixbox-forums/help/music-hold-line-sou...
1. nano -w /etc/asterisk/musiconhold_addtional.conf
You will mostlikley already have a [default] cateogry. Rename [default] to [default2] then Add the following into musiconhold.conf:
[default]
mode=custom
directory=/var/lib/asterisk/mohmp3
application=/var/lib/tb-playlinein
2. There are only WAV files in /var/lib/asterisk/mohmp3 We need there to be an mp3 in there.
Using whatever method you wish, I use webmin, upload an MP3 file to the above directory. Make sure the filename doesn't include spaces or special characters. I named mine mp3.mp3
3. Now we need to create a simple script for MOH to run when called. Create a script file /var/lib/tb-playlinein using nano:
nano -w /var/lib/tb-playlinein
copy following 2 lines of code and paste it in nano:
#!/bin/bash
/usr/bin/arecord -q -c 1 -r 8000 --buffer-size=2048 -f S16_LE -t raw
now save your changes (control-x) confirm by pushing Y and enter to save and quit.
4. Now set ownership and make it executable:
cd /var/lib
chown asterisk:asterisk tb-playlinein
chmod 777 tb-playlinein
5. Now we need to allow asterisk to have access to the sound device/files. We will need to create a group called audio and give root and asterisk access to it.
groupadd -g 525 audio
usermod -G audio root
usermod -G audio asterisk
6. In order for asterisk to use the card we will need to add a couple of lines in the amportal startup script. When your TB boots up it will set the appropriate permissions allowing MOH to access the card and play the line in souce. Use nano and add 2 lines of code to accomplish this:
nano -w /usr/sbin/amportal
Add the following two lines to the top of the file after #/bin/bash but make sure NOT to delete any existing commands above or below:
chown -R root:audio /dev/snd
chmod -R a+rwX /dev/snd
now save your changes (control-x) , confirm by pushing Y, and enter to save and quit.
7. Permanently set permissions on the audio device, since they reset at boot:
nano -w /etc/security/console.perms.d/50-default.perms
Find the section entitled "# audio devices"
Change this line:
<console> 0600 <sound> 0600 root
to:
<console> 0777 <sound> 0777 root
Thanks to KodaK for this one.
8. Reboot your pc. This will load the startup script and set the right permissions to access your sound card.
9. You can then plug into the line-in port or the mic port your FM-tuner or external audio player. Then you need to configure your mixer to turn on any line in and capturing or any mic or mic capture. to do this launch the following command:
alsamixer
Play with the adjustments to find the appropriate level. Push the M key to unmute any mic/line-in and capture channels and space key to activate!
10. Test! If you need to, create a new miscellaneous application. Name it Music On Hold, give it a feature code not already in use, select Terminate Call (Put caller on hold forever). Save it and reload the config. Dial the feature code from any extension.
If you don't hear the music, you either didn't set the mixer properly, or you might have an Intel HD/Realtek ALC888 sound card, in which case, you need to modify another file.
11. Edit the ALSA config file for the sound card:
nano -w /etc/alsa/cards/HDA-Intel.conf
Change:
capture.pcm {
type plug
slave.pcm {
@func concat
strings [ "dsnoop:" $CARD ]
}
to
capture.pcm {
type plug
slave.pcm {
@func concat
strings [ "hw:" $CARD ]
}
Reboot and test again. It should now be working. If not, check you audio settings in the alsamixer again.