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_SINKSwill 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:
ImportErrorif no audio sinks can be imported
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
- 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
- session (
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:
Requires a system using ALSA, which includes most Linux systems, and the pyalsaaudio library.
Requires a system using OSS or with an OSS emulation, typically a Linux or BSD system. Uses the
ossaudiodevmodule from the Python standard library.