Broadcasting desktop audio as (local) internet radio
I recently used Icecast and GStreamer to stream music playing on my Linux desktop to an old internet radio that does not have Bluetooth. In case someone finds themselves in a similar situation, here are the commands:
Icecast installation & configuration
On ArchLinux, simply sudo pacman -S icecast
. Then, change the configuration file /etc/icecast.xml
:
- Change the passwords to make sure no-one else can stream on your server (you can search and replace the string “hackme”, as that is the default password)
- Adapt the
<bind-address>
so that the station is only accessible from your local network. Set this to your local IP, usually something that starts with “192.168.”
Finally, you can start the server with systemd: systemctl start icecast
GStreamer setup
Find out the Pipewire monitor of your output with pactl list sources
. Look for a device with the description “Monitor for …”. Then, take note of its name and replace it in the gstreamer command below.
You’ll need gst-plugins-good
for the MP3 encoder and shoutcast plugin. To start streaming, use gst-launch. Replace the pulseaudio device, IP address and password below with the values you configured earlier.
gst-launch-1.0 \
pulsesrc device=alsa_output.pci-0000_00_1f.3.analog-stereo.monitor \
! audioconvert \
! lamemp3enc \
! shout2send mount=/stream.mp3 port=8000 \
username=source password=hackme \
ip=192.168.X.Y
Conclusion
If everything worked, you know should be able to hear whatever is playing on your desktop under the stream http://192.168.X.Y/stream.mp3.m3u
. There are two things you should keep in mind:
- There is going to be around 10 seconds of delay on the receiver, because most internet radios have buffers optimized for stable playback and not real-time streaming.
- Anyone who can reach the IP you configured can listen to your audio. So if you don’t trust your network or do not under any circumstances want to leak what’s playing on your device, better look for other solutions.
Comments
To add a comment, write an email with this link.