Audio sinks

The spotify.audiosink module provides audio sink wrappers for different audio sinks like ALSA, OSS, and PortAudio.


Try to import each audio sink until one is successfully imported.

The audio_sinks parameter specificies what audio sinks to import, in the given order. If audio_sinks is not provided, the list spotify.audiosink.AUDIO_SINKS will be used.

Parameters:audio_sinks (list of two-tuples of (modulename, classname)) – audio sinks to try to import
Returns:the first audio sink that was successfully imported
Return type:class
Raise:ImportError if no audio sinks can be imported
class spotify.audiosink.BaseAudioSink(backend=None)

BaseAudioSink provides the interface which is implemented by all audio sink wrappers in the spotify.audiosink module.

The interface is a perfect match for the spotify.manager.SpotifySessionManager.music_delivery() method, making it easy to play audio data received from Spotify.

music_delivery(session, frames, frame_size, num_frames, sample_type, sample_rate, channels)

To use one of the bundled audio controllers in a Spotify client you develop, just call this method every time you get audio data from Spotify, e.g. from your implementation of spotify.manager.SpotifySessionManager.music_delivery().

  • session (spotify.Session) – the current session
  • frames (buffer) – the audio data
  • frame_size (int) – bytes per frame
  • num_frames (int) – number of frames in this delivery
  • sample_type (int) – currently this is always 0 which means 16-bit signed native endian integer samples
  • sample_rate (int) – audio sample rate, in samples per second
  • channels (int) – number of audio channels. Currently 1 or 2

number of frames consumed

Return type:



Should be called when audio output starts.

This is a hook for the audio sink to do work just before the audio starts.


Should be called when audio output stops.

This is a hook for the audio sink to do work just after the audio stops.


Should be called when audio output is paused.

This is a hook for the audio sink to do work when the audio is paused.


Implementations of the BaseAudioSink interface include:

class spotify.audiosink.alsa.AlsaSink

Requires a system using ALSA, which includes most Linux systems, and the pyalsaaudio library.

class spotify.audiosink.oss.OssSink

Requires a system using OSS or with an OSS emulation, typically a Linux or BSD system. Uses the ossaudiodev module from the Python standard library.

class spotify.audiosink.portaudio.PortAudioSink

Requires a system with the PortAudio library installed and the Python binding pyaudio. The PortAudio library is available for both Linux, Mac OS X, and Windows.

class spotify.audiosink.gstreamer.GstreamerSink

Requires a system with Gstreamer installed and the Python bindings gst-python. The Gstreamer library is available for both Linux, Mac OS X, and Windows. Though, it isn’t always trivial to install Gstreamer.