Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick tutorial on how to play sound from your computer to a Sonos device

Quick tutorial on how to play sound from your computer to a Sonos device

Introduction

Assumptions

192.168.1.111 IP of your Sonos Device
192.168.1.128 IP of your computer

Configuration

PulseAudio

Append to /etc/pulse/default.pa:

load-module module-null-sink sink_name=rtp channels=2 rate=44100 
load-module module-rtp-send source=rtp.monitor destination=127.0.0.1 port=46998 loop=1
set-default-sink rtp

Restart PulseAudio with pulseaudio -k (if pulseaudio doesn't turn itself on start it with pulseaudio -D)

Streaming

Select one of these two methods. Try them and see which one performs better

Method 1

VLC (cvlc)

cvlc --live-caching 800 "rtp://@127.0.0.1:46998" --sout "#transcode{vcodec=none,acodec=mp3,ab=256,channels=2,samplerate=44100}:http{dst=:8554/audio.mp3}"

Then play with URI http://192.168.1.122:8554/audio.mp3.

Method 2

ffmpeg + cvlc (New method, works better in my case)

ffmpeg -i 'rtp://127.0.0.1:46998' -q:a 0 -map a -f mp3 pipe:1 | cvlc -vvv - --live-caching 500 --sout '#standard{access=http,mux=mp3,dst=0.0.0.0:8554}'

Then play with URI x-rincon-mp3radio://192.168.1.128:8554/.

Firewall Rules

iptables

sudo iptables -I INPUT -p tcp --dport 8554 -j ACCEPT

Media playing

SoCo

.play_uri(URI) argument must be either http://192.168.1.122:8554/audio.mp3 or x-rincon-mp3radio://192.168.1.128:8554/ - depending on which method you chose above.

from soco import SoCo
my_zone = SoCo('192.168.1.111')
my_zone.play_uri('http://192.168.1.128:8554/audio.mp3')

Enjoy 🎵

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment