PulseAudio pacmd
is not capable of switching the default sinks while there is an actively playing stream to the sink input. However there is a way to still achieve this.
Changing default sink from command line
First we need to determine the index number of the sinks we want to switch. This can be done by calling:
pacmd list-sinks
Depending on our system this will give you a more or less lengthy list of sinks and properties that are at present accessible:
>>> 2 sink(s) available.
* index: 0
name: <alsa_output.pci-0000_01_00.1.hdmi-stereo-extra1>
driver: <module-alsa-card.c>
:
:
index: 1
name: <alsa_output.pci-0000_00_14.2.analog-stereo>
driver: <module-alsa-card.c>
The index
or the name
given here is what we need for adressing the sink by command line. The present default sink is marked with an asterix (here 0
).
To be able to switch the default sinks from command line we may need to disable stream target device restore by editing the corresponing line in /etc/pulse/default.pa
to:
load-module module-stream-restore restore_device=false
To change the default output sink to sink 1
we then run
pacmd set-default-sink 1
Sucess can be visualized by opening the Sound Settings menu.
Moving a stream to another sink
Changing the default sink while we have an active input stream playing to a given sink has no effect. This should rather be done by moving this input to another sink.
pacmd list-sink-inputs
will tell us the index of the input stream
>>> 1 sink input(s) available.
index: 5
driver: <protocol-native.c>
We now know that we want to move the input stream 5
to sink 1
by calling
pacmd move-sink-input 5 1
or back to sink 0
if we like. This will be done immediately without the need of stopping playback.
Changing default sink while playing
Of course we can combine those two commands to immediately switch default sinks during playback e.g. with
pacmd set-default-sink 1 & pacmd move-sink-input 5 1
A drawback of this method is that the input stream index changes every time we stop and restart the music player. So we always have to find out the current stream index before we can switch using the commmand line.
I had the same problem. I'm not an expert but this is what worked for me.
For what I've understood the problem is that pulse is loading by default the hdmi profile of the sound card. That means that even if you set the default sink as alsa_output.pci-0000_00_1b.0.analog-stereo when pulse try to use that sink it can't find it.
The solution I've found is to manually configure pulse to make it load the desired profile when it starts. To achieve this you have to edit /etc/pulse/default.pa and at the end of the file add this three lines
set-card-profile alsa_card.pci-0000_00_1b.0 output:analog-stereo
set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo
set-default-source alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
the first line set the desired card profile. In my case was output:analog-stereo, you can have a complete list of profile running :
pactl list cards
the second and third line sets the default output and input respectively.
Another thing you can do is add a configuration for alsa to use pulse. Look in your home directory for the .asoundrc file, if the file does not exists create it and write this inside:
pcm.pulse {
type pulse
}
ctl.pulse {
type pulse
}
pcm.!default {
type pulse
}
ctl.!default {
type pulse
}
then reboot.
Now you should have the audio coming from your pc speaker by default.
Hope this help.
Best Answer
I wrote a small tool that lets you set the volume of any client that pulseaudio remembers. Please see here:
https://github.com/rhaas80/pa_volume
for the repository. You will need the libpulse-dev package installed after which a simple "make" should build the tool. Please see its README.md file for usage.