Line in MOH

Hi, this week I’ve been playing with FreePBX 12.

So far so good. I have a sip trunk working, and a basic IVR.

What I want to do is use the line-in audio to provide the music on hold.

I’ve got ALSA installed and working. arecord records my audio to a file correctly (so I know that part is working).

Now comes the problem… I’ve had the music on hold successfully playing the built in wav selection, so I know that works in my ivr… But I can’t make it use the line-in.

I’ve followed several on-line “how tos”, which all involve hacking at the musiconhold.conf, but nothing works. All I get is silence. My bash script for streaming the audio with arecord doesn’t get called when a call is put on hold… It does seem to get called twice when the machine is reboot though (which is odd).

I would love to do it all from the freePBX interface if possible.

Can anyone help?

Have you looked at Settings -> Music On Hold in FreePBX? From there, you can hit Add Streaming Category on the right, and enter your command there. Give it whatever name you want, and the value for Format will depend on what command you use. It’s ideal to get arecord to provide the same format as your lines and phones, to avoid transcoding. If you use ulaw, put that in the Format box, and try this command:

/usr/bin/arecord -q -f MU_LAW -r 8000 -c 1 -D <device>

Where, obviously, <device> stands for the device for your line-in.

Hi, thanks for the help, but unfortunately I’m still having problems :frowning:

I’ve put the 3 musiconhold .conf files back to default, and added a new streaming command in the freepbx web interface as you suggested…

I dialled in, my IVR answered me, then put me on hold as it should.

Unfortunately after a second or 2 of silence, I get the default wav music on hold supplied with freepbx.

[2015-01-20 14:57:22] VERBOSE[13392][C-00000000] pbx.c: Executing [musiconhold@app-blackhole:1] NoOp(“SIP/01xxxxxxxx-00000000”, “Blackhole Dest: Put caller on hold forever”) in new stack
[2015-01-20 14:57:22] VERBOSE[13392][C-00000000] pbx.c: Executing [musiconhold@app-blackhole:2] Answer(“SIP/01xxxxxxxx-00000000”, “”) in new stack
[2015-01-20 14:57:22] VERBOSE[13392][C-00000000] pbx.c: Executing [musiconhold@app-blackhole:3] MusicOnHold(“SIP/01xxxxxxxx-00000000”, “”) in new stack
[2015-01-20 14:57:22] VERBOSE[13392][C-00000000] res_musiconhold.c: Started music on hold, class ‘default’, on channel ‘SIP/01xxxxxxxx-00000000’

How do I tell it to use my “linein” stream and not default? I haven’t noticed anywhere where this kind of thing would be configured. I’ve just got 3 SIP trunks from 2 providers configured, no extensions (I did try to get a SIP soft phone to work, but gave up as it wouldn’t work, and I didn’t actually need an extension anyway).

Also, not sure if it’s related, but it seem “suspicious”, my logs are now filling up with:

[2015-01-20 14:57:22] WARNING[2271] res_musiconhold.c: poll() failed: Interrupted system call
[2015-01-20 14:57:22] WARNING[2271] res_musiconhold.c: poll() failed: Interrupted system call
[2015-01-20 14:57:22] WARNING[2271] res_musiconhold.c: poll() failed: Interrupted system call
[2015-01-20 14:57:22] WARNING[2271] res_musiconhold.c: poll() failed: Interrupted system call
[2015-01-20 14:57:22] WARNING[2271] res_musiconhold.c: poll() failed: Interrupted system call

They actually start with asterisk, even before anything has been put on hold.

Which is worrying!

Oooh, found how to set the MOH source… Inbound route…

Okay, now have:
[2015-01-20 15:09:09] VERBOSE[32027][C-00000001] res_musiconhold.c: Started music on hold, class ‘LineIn’, on channel ‘SIP/01xxxxx-00000001’

Unfortunately silence on the call still, and logs still filling with “failed: Interrupted system call”

It seems to be the MU_LAW format… It doesn’t like that at the command line either.

I’ve tried just leaving it as default format in the arecord statement, silence on the call, but no logs filling up any more.
I tried
/usr/bin/arecord -q -c 1 -r 8000 –buffer-size=2048 -f S16_LE -t raw

Too… Still no luck. What format is it expecting?

I don’t think the Interrupted system call warnings are anything to worry about. That indicates that it received a signal during the poll(), which seems normal to me.

Asterisk will be expecting the format that you specify when you create the Streaming Category in FreePBX. If blank, it should default to “slin”, which is what “-f S16_LE” gives.

According to this article from 2007, you don’t want “-t raw”. He uses this command:

/usr/bin/arecord -q --buffer-size=2048 -f S16_LE

He also does it via a bash script, but I think that’s unnecessary, since his script only has one command, and you can enter that command directly.

If this doesn’t work, you might want to read the rest of the article, in case there’s other setup you need to do with ALSA.

Thank you CmdrWalrus, I won!

Got it working eventually… 1st issue was alsamixer settings not preserved over reboot, fixed that… Then I had a permissions issue with asterisk executing my command… But now it works! Yay!

I’m current using /usr/bin/arecord -q -c 1 -r 8000 -f MU_LAW -t raw
And format of ulaw

I tried no format and S16_LE and it didn’t seem to make any difference. I’m fiddling about trying to improve sound quality, but I suspect I’m going to need to introduce some filtering on the inbound audio to drop all the high and low frequencies to get the most out of the low sample rate.

One last thing… Blimee it doesn’t take long for the chancers to start scanning your system and attempting to trombone through your system to ring international does it! I wasn’t daft enough to leave any outbound routing configured, so nobody gets out of my box, but now I’ve added a load of inbound routing rules for DID starting with 00! and 900! to just drop them.

I’m hearing some drop outs on the audio on the phone, but if I use the command line to create a file with exactly the same parameters, then pull that across to my desktop, it sounds fine (and that’s while the other arecord is still running under asterisk).

Does asterisk have any settings in it I can tweak as I think it’s doing some conversion itself and running out of data.

If the phones are using ulaw, Asterisk won’t transcode it. I wonder if it’s a buffering issue. Try giving arecord a larger --buffer-size.

You could also give sox a try, especially if you want to modify the audio with effects prior to resampling. The rec command can grab the audio from the sound card and send it to stdout for asterisk:

/usr/bin/rec -c 1 -r 8000 -e mu-law - resample

I know this thread is a little old, but…
Can you please make a full tutorial for this?
Including installing and configuring alsa?

Thanks

This does work for me! However the sound that I hear as Music On Hold is being played back far too slowly. How can I fix that?

This sounds like a stereo file being downchanneled to Mono, but not by combining the audio, but by playing each channel in series.

I ran into this 10+ years ago with some call recordings that sounded like a sloth had recorded them.

1 Like