Ever wondered how to stream music to the VoIP devices without interruption, channel or bridge hangup? For this solution, the newest version of Asterisk 13 and it’s REST Interface (Asterisk REST Interface) was used. This will work with Asterisk 12 too, since it is equipped with ARI. The application is written in Python.
To make it more interesting, Spotify offers first 30 seconds as preview, therefore it is possible to download the partial song and stream it to the caller.
Quick reminder about differences between AGI and ARI:
– AGI is synchronous.
– AGI allows remotely execute dialplan applications.
– AGI waits for response or action in the channel.
– limited or difficult control of endpoints, channels, bridges and states.
– ARI is asynchronous.
– ARI allows to build custom application controlling events, bridges, endpoints, channels and states through REST interface.
– ARI allows to build custom applications instead of routing channel to the built-in application (AGI).
How to stream music from Spotify to Asterisk?
- I created a simple ARI application which connects to Asterisk REST interface via web sockets, reads responses and sends requests.
- When call enters the Stasis inside the dialplan, this event is captured.
- This new channel is added to the holding bridge.
- Let user to specify which band he wants to listen to via DTMF or let him to listen to the default band of my choice (Dire Straits top 3 songs)
- Songs are downloaded (or cached for faster access, but it is a matter of seconds if we want to stream only top 3 songs)
- Songs are played to the caller, basically to any device (mobile phone, landline, softphone, VoIP phone, WebRTC, trunk…)
- Caller can then decide to play more songs, repeat or hang up using the DTMF.
Simple diagram depicting this scenario:
The demo is available here.
Please contact Asterisk Consulting for further options in Asterisk VoIP streaming.