Automatically Receive Call to Play Audio Livestream (MOH)?

I am completely new to Asterisk, but so far, I have managed to install it on my Odroid HC2 (odroidxu4) and edit sip.conf to register my SIP provider.

I need help implementing this, and I’m not sure where to start. Here is what I’m trying to do:

My church is doing a live stream (audio/video) with OBS, which is eventually pushed to an nginx rtmp server that I set up, which pushes the rtmp stream to the streaming platform(s) of my choice. Additionally, with the nginx server, I have the audio pushed to an Icecast server that I created, and an m3u from that.

I want to use this “internet radio station” that I created with Icecast of the church service livestream audio, and implement it in Asterisk so that when someone calls a specific phone number (from my SIP provider), my PBX automatically picks up and they can listen to the service (utilizing MOH, music on hold?). Ideally, I would like more than one person to listen in.

I’m pretty sure all this is possible, but I’m just wondering how to go about this? In case anybody is wondering why I would go through all this trouble, there are some people in my province in rural areas who do not have high speed internet, or do not understand computers/smart phones. So I’m trying to create a “listen line.”

One additional question. Is there some way to make it automated so that if Asterisk does not detect a MOH stream, that it plays a prerecorded message instead telling the person to call back when the stream has begun?

Firstly, any new installation should use chan_pjsip, rather than chan_sip, unless there is as specific contraindication.

Although I haven’t done it myself the music on hold facility allows for streaming sources, and that might be the easiest way to achieve it.

AGI also allows arbitrary media to be sent down a channel.

You could use a conference, i.e. make the audio feed a permanent member of the conference and add the callers in a muted state.

I have no idea what this means.

So here is what I have done so far, with the help of another use who was did something similar, and that user created a script and shared it with me. I created a new file in usr/local/bin and named it streamurl.sh:

#!/bin/sh

# change to yes enable debugging output
DEBUG=no

VLC=/usr/bin/vlc

if [ "$DEBUG" = "yes" ] ; then
        VLC="$VLC -vvv --file-logging --logfile /tmp/vlc.log"
else
        su -c "cvlc  "$1" --play-and-exit --network-caching=100 --no-video --sout '#transcode{acodec=s16l,channels=1,samplerate=8000,afilter=mono}:file {mux=dummy,dst=-}'"  www-data
        su -c "cvlc  "/var/lib/asterisk/sounds/1_RLN.wav" --play-and-exit --network-caching=100 --no-video --sout '#transcode{acodec=s16l,channels=1,samplerate=8000,afilter=mono}:file {mux=dummy,dst=-}'" www-data

fi

sleep 10

Then I made it executable with chmod a+x. Then in /var/lib/asterisk/sounds I placed a .wav file and named it pleasecallback.wav. In musiconhold.conf, I have (stream.mp3 is my icecast stream):

[general]

[default]
mode=files
directory=moh

[ulawstream]
mode=custom
application=/usr/local/bin/pleasecallback.sh http://0.0.0.0:8000/stream.mp3
format=ulaw

In sip.conf, I have:

[general]
context=public
allowoverlap=no
udpbindaddr=0.0.0.0
tcpenable=no
tcpbindaddr=0.0.0.0
transport=udp
srvlookup=yes

register => 15555555555:password@voip.freephoneline.ca/15555555555

[freephoneline]
context=from-trunk
host=voip.freephoneline.ca
username=15555555555
secret=password
type=friend
insecure=port,invite
dtmfmode=auto
disallow=all
allow=ulaw
fromdomain=freephoneline.ca
secret=[password]
type=user
context=from-trunk
insecure=port,invite
fromdomain=freephoneline.ca

[basic-options](!)
    dtmfmode=rfc2833
    context=from-office
    type=friend

[natted-phone](!,basic-options)
    directmedia=no
    host=dynamic

[public-phone](!,basic-options)
    directmedia=yes

[my-codecs](!)
    disallow=all

In extensions.conf, I have:

[from-trunk]
exten => _X.,1,Set(CALLERID(num)=SIP-ID)
exten => _X.,2,Answer()
exten => _X.,3,Wait(1)
exten => _X.,4,MusicOnHold(ulawstream)
exten => _X.,5,Hangup()
exten => _X.,6,NoOp()

But when I call my sip’s phone # from outside, This is what I get:

Executing [15555555555@from-trunk:1] Set("SIP/freephoneline-00000006", "CALLERID(num)=SIP-ID") in new stack
    -- Executing [15555555555@from-trunk:2] Answer("SIP/freephoneline-00000006", "") in new stack
    -- Executing [15555555555@from-trunk:3] Wait("SIP/freephoneline-00000006", "1") in new stack
    -- Executing [15555555555@from-trunk:4] MusicOnHold("SIP/freephoneline-00000006", "ulawstream") in new stack
    -- Started music on hold, class 'ulawstream', on channel 'SIP/freephoneline-00000006'
    -- Stopped music on hold on SIP/freephoneline-00000006
  == Spawn extension (from-trunk, 15555555555, 4) exited non-zero on 'SIP/freephoneline-00000006'

I don’t hear anything, whether I have a mountpoint (stream) going in icecast or not. If I’m not playing a stream, I don’t hear my .wav message. If I am playing a stream, I don’t hear that. I apologize if the answer is obvious. I am just piecing this together with the help of another user and I haven’t gotten any feedback on my dialplan yet (I don’t know how to write a dialplan in extensions.conf). So a lot of this is guessing and Googling.

Not very updated, but to get you an idea.

It means that you are using code that is no longer effectively supported, but you don’t know enough about Asterisk to know if there is an overriding need to do so.

Modules beginning chan_ implement signalling protocols. chan_sip is the old way of implementing SIP in Asterisk, and is associated with dial strings starting SIP/ and the configuration file sip.conf. It is no longer maintained by the paid Asterisk developers.

chan_pjsip, is the modern replacement and is associated with the dial string prefix PJSIP/.

The latter is generally more capable, but there are some special cases where the old one may still have an advantage.

Unless you are taking on a very old system, which is making extensive use of the former, or you know that one of the exceptional cases that cannot be handled by the latter, you should be using the latter, but you are currently using the former.

So should I copy and paste everything that is in sip.conf into pjsip.conf? And then restore sip.conf to what it was (default), and then change extensions.conf so the first line says exten => _X.,1,Set(CALLERID(num)=PJSIP-ID)? Will that make me hear something when I call?

Thanks! So then would the simplest solution be to update my streamurl.sh file? This is what I have, and it uses VLC. I did not create this:

#!/bin/sh

# change to yes enable debugging output
DEBUG=no

VLC=/usr/bin/vlc

if [ "$DEBUG" = "yes" ] ; then
        VLC="$VLC -vvv --file-logging --logfile /tmp/vlc.log"
else
        su -c "cvlc  "$1" --play-and-exit --network-caching=100 --no-video --sout '#transcode{acodec=s16l,channels=1,samplerate=8000,afilter=mono}:file {mux=dummy,dst=-}'"  www-data
        su -c "cvlc  "/var/lib/asterisk/sounds/pleasecallback.wav" --play-and-exit --network-caching=100 --no-video --sout '#transcode{acodec=s16l,channels=1,samplerate=8000,afilter=mono}:file {mux=dummy,dst=-}'" www-data

fi

sleep 10

I’m not sure how to change this to be mpg123, as there is one spot that says “cvlc,” and I don’t know what the equivalent would be for mpg123 (or what cvlc means). Another option would be for me to change the streaming file to something else. Do you know what the compatible formats would be to use vlc?

Also, this is my musiconhold.conf file:

[ulawstream]
mode=custom
application=/usr/local/bin/streamurl.sh rtmp://url.to.your.stream
format=ulaw

rtmp://url.to.your.stream is changed to my Icecast mp3 stream link. I don’t know how to create an rtmp stream. But maybe I could do another format from mp3, I don’t know.

No, chan_sip and chan_pjsip configurations are not compatible. chan_pjsip follows modular approach. This is what you should look into
https://wiki.asterisk.org/wiki/display/AST/Migrating+from+chan_sip+to+res_pjsip
https://wiki.asterisk.org/wiki/display/AST/PJSIP-pjproject

This does nothing but sets PJSIP-ID as callerid on the call. I don’t why you need this.

I don’t know why I need this either. I was copying and pasting different codes for extensions.conf trying to get my asterisk server to pick up the call.

I found these instructions and it works perfectly! I made sure that I first installed mplayer (apt install mplayer), and then when I created the moh.sh file, I made sure I typed chmod a+x moh.sh to make it executable. When I call, I hear whatever stream I put in there (whether Shoutcast, or my Icecast stream, which is local.

I don’t know enough about bash scripts. How would I change it so that when there is no stream detected from the url, that it defaults to /var/lib/asterisk/sounds/pleasecallback.wav? pleasecallback.wav is a wav file where I tell the person calling in to call back later when there is a live stream.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.