From Gentoo Wiki
(Redirected from User:Cb1/drafts/Snapcast)
Jump to:navigation Jump to:search

Snapcast (Synchronous audio player) plays audio streams time synchronized on multiple devices over network using a server and a client component. The server picks up an audio stream from a fifo pipe, thus it can be combined with any audio source that is able to write to a pipe. The Snapserver is able to handle multiple streams at once. The assignment of clients to streams and their volume is controlled via a JSON-API.


USE flags

USE flags for media-sound/snapcast Synchronous multi-room audio player

client Build and install Snapcast client component
expat Enable the use of dev-libs/expat for XML parsing
flac Add support for FLAC: Free Lossless Audio Codec
opus Enable Opus audio codec support
server Build and install Snapcast server component
tremor Build with TREMOR version of vorbis
vorbis Add support for the OggVorbis audio codec
zeroconf Support for DNS Service Discovery (DNS-SD)


root #emerge --ask media-sound/snapcast

Basic Configuration


The Snapcast server should run as its own user:group e.g. snapserver:snapserver (default created during emerge).

A sample config that makes snapserver pick up an audio stream from the named pipe /tmp/snapfifo looks like this:

FILE /etc/conf.d/snapserver
SNAPSERVER_USER="--user snapserver:snapserver"
SNAPSERVER_OPTS="-d -s pipe:///tmp/snapfifo?name=default"

To start snapserver now run:

root #rc-service snapserver start

To start snapserver at boot time run:

root #rc-update add snapserver default

For all snapserver options please see man snapserver.


The basic configuration for the client looks like this:

FILE /etc/conf.d/snapclient
SNAPCLIENT_USER="--user snapclient:audio"

This will run snapclient as daemon using the default sound card. It will try to find servers on the network using Avahi, if avahi-daemon is installed and running.

To start snapclient now run:

root #rc-service snapclient start

To start snapclient at boot time run:

root #rc-update add snapclient default

Desktop environment/selecting sound card

To make use of PulseAudio/use snapclient in your desktop environment (to be able to use snapclient alongside with other audio sources, control its volume, etc.) you would start it as your desktop user instead of letting the init system control it.

To get a list of sound cards, and select the right one, run:

user $snapclient -l

0: null Discard all samples (playback) or generate zero samples (capture)

1: pulse PulseAudio Sound Server


To use PulseAudio for example, use 1 with the -s command line option:

user $snapclient -s 1

Snapclient should now appear in your list of audio playing applications of PulseAudio.

Audio source

To make some testing noise, random bytes can be shoved into the snapservers pipe:

root #cat /dev/urandom > /tmp/snapfifo

Snapcast can basically be used with anything that is able to write PCM audio to a fifo.

MPlayer example

To make MPlayer play something over Snapcast use:

root #mplayer <input> -novideo -channels 2 -srate 48000 -af format=s16le -ao pcm:file=/tmp/snapfifo

MPD example

To hear music with MPD over Snapcast create a new audio_output in the mpd.conf using the fifo module:

audio_output {
    type            "fifo"
    name            "Snapcast"
    path            "/tmp/snapfifo"
    format          "48000:16:2"
    mixer_type      "software"

The sample rate setting is the default one used by Snapcast. Different sample rates can be used but must be set in the snapserver config file first.

Multiple input streams

Snapcast is able to handle multiple input streams per server instance. The server also assigns the clients dynamically to streams.

Each stream is added with another -s option and its own fifo to the snapserver config.

FILE /etc/conf.d/snapserver
SNAPSERVER_OPTS="-d -s pipe:///tmp/snap_kitchen?name=Kitchen -s pipe:///tmp/snap_livingroom?name=Livingroom"

Controlling Snapcast

Assignment of streams to clients as well as volume, name, and latency of each client is controlled over a JSON-API provided by snapserver. The API documentation can be found on GitHub.

There are some (GUI-) implementations using that API, like


The developer of Snapcast also made an Android app, Snapdroid.

It can connect clients to streams, set volumes, etc. Moreover it implements a Snapcast client on Android, making it possible to play a Snapcast stream on an Android device.