Asterisk This time as a background music broadcasting system with the possibility of emergency notification

Good afternoon, dear residents of the Asterisk hub.
I don’t know about you, but lately I’ve been extremely interested in using Asterisk not as a standard PBX.
In a previous post, Asterisk acted as a security guard in a parking lot. This time, Asterisk in my configuration played background music in the trading pavilion and, in case of an emergency (or, if necessary, to make some kind of announcement) acted as a warning system.
Details under the cut.
A couple of weeks ago I had one interesting problem, namely, to deploy a system for playing background music, one of the functions of which should be the ability to "wedge" in playing a sound file, make an announcement, and then continue playing music from the same place.
Having quickly looked at Google the existing “boxed” solutions, I realized that this is not quite what I want. I was offered either professional warning systems (for example, for stadiums), or analog devices, of course, reliable, but absolutely not customizable.
Also, existing SIP alert devices were reviewed. Here it’s more interesting: they are registered on Asterisk as extensions, they can broadcast multicast, they can prioritize different sound streams. In Russia, you can find IP-SIP speakers Cyberdata , which were considered in great detail grigly in this topic. The speakers got a new firmware, the interface was a little refreshed. Having the opportunity to "play around" with this device, it was a sin not to use it :)
So let's get started.
Of course, we will not describe the installation of Asterisk: the network is full of high-quality manuals. The only thing I will add: I have already done docker-compose with asterisk, mysql, php-apache, cdr-viewer for a long time, which makes the asterisk deployment almost instant. I plan to describe this in the next topic).
Create a couple of extensions on Asterisk (by default /etc/asterisk/sip.conf):
Hidden text
[tmpl](!)
type = peer
host = dynamic
canreinvite=no
dtmfmode = rfc2833
insecure = invite
nat = force_rport,comedia
call-limit=2
qualify = yes
context = from-internal
disallow=all
allow=alaw
allow=ulaw
directmedia=no
[780](tmpl)
defaultuser=780
secret=780
callerid="Dispatcher" <780>
[790](tmpl)
defaultuser=790
secret=790
callerid="Speaker1" <790>
[800](tmpl)
defaultuser=800
secret=800
callerid="Speaker2" <800>
We write the simplest Asterisk dialplan for tests (by default /etc/asterisk/extensions.conf):
Hidden text
exten => _XXX,1,NoOp(Testing calls to speakers. Dialing ${EXTEN} from ${CALLERID})
same => n,Page(SIP/${EXTEN},qA(hello-world))
same => n,Hangup()
Go to the speaker setup.
We find it in our local network (by default, the device is configured for dhcp):

Configure sip extension (to enter the speaker, the username / password is admin / admin by default):

The only inconvenience is that after each operation the speaker must be sent to reboot, which it takes a whole minute.
And set up the multicast:

Pay attention to the inscription: “SIP calls are considered priority 4.5. Priority 9 is the highest and 0 is the lowest. »In order for multicast broadcasting to be interrupted when calling the speaker, the multicast settings must have priority 4 or lower.
Now set up multicast broadcasting on the asterisk server. I used the ffmpeg utility.
Install:
sudo apt-get install ffmpeg
We start broadcasting (I took a playlist from vocaltrance.fm (not advertising), of course, you can choose any):
ffmpeg -re -i 176.9.36.203 : 8000 / vocaltrance_128 -filter_complex 'aresample = 8000, asetnsamples = n = 160' -acodec pcm_alaw -ac 1 -vn -f rtp udp: //236.0.0.1: 2000? buffer_size = 10000000? fifo_size = 1,000,000
And listen :)
In addition to the obvious advantages, this implementation option has one big drawback, namely the price, which for this speaker is about $ 400 apiece.
To lower the cost of the system, I decided to use ordinary speakers (I had on hand
like these ones
and raspberry pi . (The cost of the speaker and raspberry was ~ $ 50). 
So let's get started.
Install the raspbx distribution on raspberry , which is a ready-made freepbx image for the ARM architecture. (For installation, you will need a flash drive of sizes from 4Gb.)
Installation is trivial: download, take a suitable flash drive, unmount the partition, write the image via dd:
sudo dd if=path_of_your_image.img of=/dev/diskn bs=1M

We find the login / password on the network for ssh root / raspberry, for the web - admin / admin.
We create a trunk to our "head" Asterisk:
[rasp]
type=peer
host=192.168.1.254 ;;ip "головного" Asterisk
qualify=yes
insecure = port,invite
directmedia=no
context=speakers
canreinvite=no
disallow=all
allow=alaw
allow=ulaw

On the “head” Asterisk we create the same trunk, we just point it to ip raspberry.
Calls to raspberry will be sent to chan_alsa (module load chan_alsa.so, if not loaded by default).
To play music, use omxplayer (sudo apt-get -y install omxplayer).
To interrupt the playback of music, we write a simple dialplan:
Hidden text
[speakers]
exten => s,1,System(killall /usr/bin/omxplayer.bin)
same => n,Wait(2)
same => n,Dial(console/sdp)
same => n,Hangup()
exten => h,1,System(omxplayer -o local rtp://@236.0.0.1:2000)
To make a call from the “main” Asterisk, add to the original
dialplan : exten => 1000.1, Dial (SIP / rasp / s, 60, Tt)
same => n, Hangup ()
And enjoy the result :)
Conclusion
As a result, we have a fully working Asterisk-controlled background music notification / broadcast system with several terminal options. Use cases for other devices are welcome in the comments. Thanks for attention.
Russian version: Asterisk. This time as a system of broadcasting background music with the possibility of emergency notification .