How to Enable Audio Casting in Linux

Easily share your audio with another device.

Audio Casting Featured Image

Audio casting – or audio streaming – allows audio played on one device to be played on another. It can be either live audio, files or even microphone input. Many of the tech giants have their own version of audio casting. Apple has AirPlay, and Google has Chromecast. For Linux, you are blessed with many different methods of audio casting by virtue of it being open source.

A Technical Perspective

Although different manufacturers use slightly different protocols, almost all audio casting uses peer-to-peer (P2P) networking. P2P has gathered quite the reputation for its use in torrenting, but the networking method is not so notorious.

Essentially, P2P means that both your device and the device you’re connected to share data permissions – both can receive and send data as they wish. For the purposes of audio casting, the sender will convert audio data to binary, and the receiver converts it back to audio data. Compression, bit rates and buffering also play a role in this process but are a different rabbit hole than the one we are diving into.

What You Need for Audio Casting

These are the main applications that we are using to cast audio. There are other methods that involve more installation, but these are the main ones you will use to interact with Pulseaudio.

Pulseaudio Preferences

Paprefs (pulseaudio preferences) is a great way to access all the pulseaudio modules. To implement these, it would normally require you to scout through documentation and hit the terminal, but the handy GUI makes it much easier. Install Paprefs with the following command:

sudo apt install paprefs

One of the problems with Paprefs is that it uses the default folder name for Pulseaudio. When you try to activate or install modules through it, it takes you to that default folder. This folder will not exist if Pulseaudio has been updated.

To solve this, create a symlink that points paprefs to the correct folder, like the one below.

Paprefs-image

The actual folder is “pulse-15.99.1+dfsg1.” The symlink folder is “pulse-13.99.” Paprefs will register it as such, but it points to the actual folder instead of being a new one on its own. To create a symlink, the terminal command is as follows:

sudo ln -s '/usr/lib/pulse-15.99.1+dfsg1' '/usr/lib/pulse-15.99'

Pulseaudio Volume Control

This application allows you to interact with pulseaudio sinks and monitors. Not only will this help you see whether audio is playing where you want it to, but a visual interface is always helpful when working with multiple sinks and computers.

The following terminal command will install Pavucontrol.

sudo apt install pavucontrol

How to Enable Audio Casting

As with anything in Linux, enabling audio casting in Linux can range from easy to massively painful. My testing and methodology focuses on Ubuntu, but if you’re running Arch or any other distro, the process should be similar.

RTP Audio Casting

Using RTP (Real-time Transport Protocol) is the easiest method that I found when testing. Here, we are using Pulseaudio.

  1. Navigate to the Multicast/RTP tab in Paprefs and check the “Enable Multicast/RTP receiver” and the “Enable Multicast/RTP sender” box on both devices. You can opt to enable either one, but I want to be able to send and receive from both devices, so I am enabling both.
Screenshot From 2022 09 28 20 28 02
  1. You can either choose to create a separate sink or feed audio directly from your speakers to the other device. A separate sink will allow you to control the volume and format of the audio you’re sending. You should see the audio monitor stream from the other device in the Input devices section of Pavucontrol.
  2. If you’re more of a terminal person, you can also add the following modules to the “default.pa” file in “/etc/pulse.” These do the same thing as enabling the receiver and sender in Paprefs.
load-module module-null-sink sink_name=rtp
load-module module-rtp-send source=rtp.monitor
set-default-sink rtp
load-module module-rtp-recv

You may need to alter the permissions of the default.pa file using chmod if you choose to do it manually.

Direct Connection Audio Casting

Add the following lines to the “/etc/pulse/default.pa” file on both computers. These modules are for authentication between server and client.

load-module module-esound-protocol-tcp auth-anonymous=1
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;192.168.0.0/24

Additionally, set the default-server parameter in the “/etc/pulse/client.conf” file. It can be either the IP address or hostname (PC name) of the server.

Windows to Linux Audio Casting

If you have a Windows computer and want to stream to a Linux device, Pulseaudio cannot on its own stream reliably from Linux to Windows or vice versa. Scream is one of the few alternatives that will allow you to cast audio from Windows to Linux. Note that this method has not been tested on Windows 11.

Installing it is as easy as downloading the Windows 10 application from the Github link and the Linux receiver from the repository. The following terminal commands will install the receiver and are also available at the receivers link.

# Redhat, CentOS, etc.
sudo yum install pulseaudio-libs-devel
 
# Debian, Ubuntu, etc.
sudo apt-get install libpulse-dev

If you want to forgo using Pulseaudio, Jack offers a foolproof method of streaming audio from Windows to Linux. This method involves using an ASIO bridge connecting JACK to an audio sink on the Windows computer.

Install JACK on both your Linux and Windows computer. In Windows, you can download and install from the following link. For Linux, you will need to install it from your package manager. In my case, I used apt and the following command:

sudo apt install jackd

You also need to have ASIO Bridge installed on your Windows machine. Once you’ve completed the installations, run the following commands from the Windows command line:

regsvr32 32bits\JackRouter.dll
regsvr32 64bits\JackRouter.dll

On your Linux machine, type in jack_load netmanager in the terminal or set it to automatically activate using qjackctl (Cadence and Catia are also great patchbays) using the same command. Navigate to the Options tab, tick the “Execute script after Startup” box, and add the command.

Screenshot From 2022 09 30 18 10 28

The last steps are to start JACK NetDriver on your Windows device. Alternatively, enter the jackd -R -d net in the command line, start ASIO Bridge and set the ASIO device to JackRouter. You should see the Windows hostname in qjackctl or whichever patch bay you chose. Sometimes this step requires you to restart qjackctl, so don’t fret if it doesn’t work the first time.

Frequently Asked Questions

Are there any alternative applications that I can use to cast audio on Linux?

There are many media servers and casting applications on Linux. It would be impossible to explain and run through all of them, but some of the notable ones are Mkchromecast and Soundwire.

Will enabling audio casting make my PC vulnerable to a cyberattack?

One concern when working with anything network-related is security. Although some audio casting methods can leave your computer vulnerable, it’s unlikely that there is any real danger – as long as you are working within your closed LAN network.

Can I use these methods to cast audio to my TV?

Unfortunately, without an external application like VLC or mkchromecast, you can’t send audio directly to your TV using RTP or a direct connection. However, most smart TVs will allow you to install applications and/or receive and send audio from another device.

Image credit: Noisy big megaphone on Freepik

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox