Streaming music from Spotify to Asterisk VoIP

Streaming music from Spotify to Asterisk VoIP

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 usedThis 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:
– 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
– 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).

https://wiki.asterisk.org/wiki/pages/viewpage.action?pageId=29395573

source: https://wiki.asterisk.org/wiki/pages/viewpage.action?pageId=29395573

How to stream music from Spotify to Asterisk?

  1. I created a simple ARI application which connects to Asterisk REST interface via web sockets, reads responses and sends requests.
  2. When call enters the Stasis inside the dialplan, this event is captured.
  3. This new channel is added to the holding bridge.
  4. 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)
  5. Songs are downloaded (or cached for faster access, but it is a matter of seconds if we want to stream only top 3 songs)
  6. Songs are played to the caller, basically to any device (mobile phone, landline, softphone, VoIP phone, WebRTC, trunk…)
  7. Caller can then decide to play more songs, repeat or hang up using the DTMF.

Simple diagram depicting this scenario:

Asterisk Spotify Streaming

Asterisk REST & Spotify streaming

 

The demo is available here.

Please contact Asterisk Consulting for further options in Asterisk VoIP streaming.

Brussels (BE) Prague (CZ) tech@asterisk.consulting
VirtualPBX: The Complete Business Phone Solution

Leave a Reply