userdoc:tt_external_moh_source

External Music on Hold Source

The default Music on Hold (MoH) sound files included with the Asterisk project are adequate for many situations. Custom MoH sound files may be easily added as well.

Alternatively, this topic describes how an external analog audio source may be used as a MoH source for any number of listeners.

Note -> Be certain any external audio source may be freely, legally “re-broadcast” to music on hold listeners.

USB Sound Adapter (driverless) which provides a “Microphone” input, typically in the $20-40 (USD) range.

Old iMic

Tested USB Sound Adapter's data via “lsusb”:

ID 077d:07af Griffin Technology iMic (Old original iMic)
ID 077d:0420 Griffin Technology (Old original iMic)
ID 10f5:0211 Turtle Beach (Turtle Beach Audio Advantage Amigo II)
ID 0d8c:0102 C-Media Electronics, Inc. CM106 Like Sound Device (Sabrent USB-SND8)

Edit the “/etc/rc.modules” file and add the following lines to the end:

snd-usb-audio
snd-pcm-oss

The device /dev/dsp should automatically appear when the USB Sound Adapter is plugged in and the above kernel modules are loaded.

Question -> If my board supports Audio Line-In, can (should) I use it ? Short answer, No. Long answer…

  • AstLinux does not include the ALSA sound libraries and utilities required to unmute the Line-In input.
  • Typically, onboard audio contains added noise from the nearby digital circuits.

Create file: /mnt/kd/bin/ast-playlinein

#!/bin/sh

# Set VOLUME variable to linearly multiply the volume by a number.
# Only define VOLUME if the external audio source's volume cannot be adjusted.
#VOLUME="2.0"

# Source Sample Rate: 48000, 44100, 16000
SRATE="16000"

# OSS sound device
CAPTURE_DEV="/dev/dsp"

if sox --version >/dev/null 2>&1; then  # SoX v14.4.1 or later
  FOPTS="-b 16"
else
  FOPTS="-w"
fi
if [ -n "$VOLUME" ]; then
  FOPTS="-v $VOLUME $FOPTS"
fi

while [ ! -e $CAPTURE_DEV ]; do
  sleep 1
done

sox -t ossdsp $FOPTS -r $SRATE -c 1 $CAPTURE_DEV -t raw -r 8000 -

Make the “/mnt/kd/bin/ast-playlinein” file executable:

chmod 755 /mnt/kd/bin/ast-playlinein

Edit the Asterisk configuration file “/etc/asterisk/musiconhold.conf” and add this context:

[stream]
mode=custom
application=/mnt/kd/bin/ast-playlinein

Reload the Asterisk MoH module:

asterisk -rx "module unload res_musiconhold.so"
asterisk -rx "module load res_musiconhold.so"

Tip -> Never edit the ast-playlinein script without first unload'ing res_musiconhold.so .

Note -> One “sox” process will always be running, regardless if there are 0, 1 or many users on hold.

You can also easily stream music over the Internet/LAN for MOH with sox. The ast-stream-mp3 script directly supports MP3 streams or MP3 streams indirectly via a .pls playlist.

Create file: /mnt/kd/bin/ast-stream-mp3

#!/bin/sh

# Set VOLUME variable to linearly multiply the volume by a number.
# Value: "0.8" is 80%, "1.2" is 120%, default is "1.0" when not defined.
VOLUME="0.8"

URL="$1"
if [ "$URL" != "${URL%.pls}" ]; then
  PLAYLIST="$(wget -q -O - $URL)"
  if [ $? -ne 0 ]; then
    sleep 10
    exit 1
  fi
  URL="$(echo "$PLAYLIST" | sed -n -r -e 's/^File[0-9]*=(.*)$/\1/p' | head -n1)"
  if [ -z "$URL" ]; then
    sleep 10
    exit 1
  fi
fi

if [ -n "$VOLUME" ]; then
  FOPTS="-v $VOLUME"
else
  FOPTS=""
fi

wget -q -O - $URL | sox -t mp3 $FOPTS - -t raw -r 8000 -c 1 -

Make the “/mnt/kd/bin/ast-stream-mp3” file executable:

chmod 755 /mnt/kd/bin/ast-stream-mp3

Edit the Asterisk configuration file “/etc/asterisk/musiconhold.conf” and add this context:

[internet-stream]
mode=custom
application=/mnt/kd/bin/ast-stream-mp3 http://wnycfm.streamguys.com:80/

Note -> The example MP3 source URL shown above is only an example, and does not imply it is legal to use for MOH in your country. Choose a MP3 source URL carefully.

Reload the Asterisk MoH module:

asterisk -rx "module unload res_musiconhold.so"
asterisk -rx "module load res_musiconhold.so"

Tip -> Never edit the ast-stream-mp3 script without first unload'ing res_musiconhold.so .

  • userdoc/tt_external_moh_source.txt
  • Last modified: 2014/02/19 06:44
  • by abelbeck