
PulseAudio, a sound server that’s widely used on Linux and Unix systems, provides a host of features that allow users to control the audio output of their systems. One such feature is the ability to change the audio sink (output device) during playback. This article will guide you through the process of changing the PulseAudio sink during playback using the pacmd set-default-sink
command.
To change the PulseAudio sink during playback using the pacmd set-default-sink
command, you need to first ensure that the necessary modules are loaded in your PulseAudio server configuration. Then, create a new tunnel sink using the pacmd load-module
command and set it as the default sink with the pacmd set-default-sink
command. Finally, move the active audio stream to the new sink using the pacmd move-sink-input
command.
Understanding PulseAudio Sinks
Before we delve into the steps, it’s important to understand what a PulseAudio sink is. A sink in PulseAudio is a device or software that audio data can be sent to. This could be your speakers, headphones, or a virtual device.
Setting Up Your PulseAudio Server Configuration
Firstly, you need to ensure that the necessary modules are loaded in your PulseAudio server configuration. Open the /etc/pulse/default.pa
file and make sure the following lines are present:
load-module module-esound-protocol-tcp auth-anonymous=1
load-module module-native-protocol-tcp auth-anonymous=1
load-module module-zeroconf-publish
These modules enable the PulseAudio server to communicate over TCP and publish its presence over the network.
Creating a New Tunnel Sink
Next, on the source side, you’ll need to create a new tunnel sink using the pacmd load-module
command. The server
parameter is used to specify the IP address of the PulseAudio server. For example:
pacmd load-module module-tunnel-sink server=192.168.1.105
Setting the Default Sink
Once the tunnel sink is created, you can set it as the default sink using the pacmd set-default-sink
command. The parameter here is the index of the sink. For example:
pacmd set-default-sink 1
The index number may vary depending on the number of sinks available. You can use the pacmd list-sinks
command to view the available sinks and their corresponding index numbers.
Moving the Active Audio Stream
Changing the default sink while there is an active stream playing to the current sink may not have an immediate effect. To apply the sink switch immediately during playback, you may need to move the active audio stream to the new sink. This can be done using the pacmd move-sink-input
command:
pacmd move-sink-input <input_index> <new_sink_index>
Replace <input_index>
with the index of the input stream (you can use the pacmd list-sink-inputs
command to find the index) and <new_sink_index>
with the index of the new sink.
Please note that the input stream index may change every time you stop and restart the media player. Therefore, you may need to find out the current stream index before moving it to the new sink.
Conclusion
Switching output devices using GUI tools like “gnome-volume-control” or “gnome-control-center sound” applies the changes immediately because they handle the necessary steps behind the scenes. However, when using command-line tools like pacmd
, you may need to manually move the active stream to the new sink for immediate effect.
In summary, to switch the PulseAudio sink with “pacmd set-default-sink” during playback, you can create a tunnel sink, set it as the default sink, and move the active stream to the new sink using the pacmd
commands. This gives you greater control over your audio output, allowing you to tailor your audio experience to your needs.
For more information on PulseAudio and its features, you can visit the official PulseAudio documentation.
To find the index of the input stream, you can use the pacmd list-sink-inputs
command. This will display a list of all the currently active input streams along with their corresponding index numbers.
Yes, you can change the PulseAudio sink while playing audio from multiple applications. When you change the default sink using the pacmd set-default-sink
command, it will affect all the applications using the default sink. However, you may still need to move the active audio streams from each application to the new sink using the pacmd move-sink-input
command for immediate effect.