Mopidy Self Hosted Audio Server
Published on Sep 08, 2024 by doombaby.
Audio Sink
Configure Mopidy’s audio output settings. Here is how to configure an audio router using a local Pulse sink, Pulse TCP sink, Snapcast server, Icecast server, and UDP multicast stream.
[audio]
output = tee name=t
t. ! queue ! audioconvert ! audioresample ! pulsesink device=pi4 server=127.0.0.1
t. ! queue leaky=downstream ! audioresample ! audioconvert ! audio/x-raw,rate=48000,channels=2,format=S16LE ! wavenc ! filesink location=/run/mopidy/snapfifo sync=false
t. ! queue leaky=downstream ! audioconvert ! audioresample ! pulsesink server=10.0.10.20:4656 async=false sync=false
t. ! queue leaky=downstream ! audioresample ! audioconvert ! vorbisenc ! oggmux ! shout2send async=false mount=mopidy.ogg ip=127.0.0.1 port=8000 password=secret
t. ! queue leaky=downstream ! audioconvert ! audioresample ! audio/x-raw,channels=2,rate=48000 ! rtpL16pay ! udpsink host=239.1.1.1 port=5004 auto-multicast=true ttl-mc=64 blocksize=8192 async=false sync=false
Pusle Audio Server (Receiver)
Create an audio sink server on the device that will be receiving audio.
load-module module-native-protocol-tcp port=4656 listen=10.0.10.20
Pulse Audio Client (Sender)
Create an audio sink tunnel on the Mopidy server destined to the audio sink server.
load-module module-tunnel-sink server=tcp:10.0.10.20:4656
Multicast (Receiver)
The muticast stream address 239.1.1.1 or any other address in the 239.0.0.0/8 subnet and port combination can be used to efficiently stream audio to multiple receivers. I find gstreamer works reliably, and the paramaters can be tuned to synchronize audio with other receivers.
MacOS Multicast Audio Receiver:
gst-launch-1.0 -v udpsrc address=239.1.1.1 port=5004 auto-multicast=true buffer-size=524288 \ caps="application/x-rtp,media=(string)audio,clock-rate=(int)48000,encoding-name=(string)L16,channels=(int)2,payload=(int)96" ! \ rtpjitterbuffer latency=904 mode=slave ! \ rtpL16depay ! \ audioconvert ! \ audioresample ! \ osxaudiosink