I have a digital headphone set and an analog pair of speakers. Is there a way for me to switch between them in the terminal in Ubuntu? I ask that because I would like to create a keyboard shortcut for this switch to make it simpler than having the tedious task of going to the audio settings using the mouse.
Ubuntu – How to choose the audio output device using the terminal
command lineoutputsound
Related Solutions
We have the optional application paprefs that allows to install a virtual output device to pulseaudio. This enables simultaneous output to all attached sound cards/devices:
The additionally created audio output device for simultaneous output may be selected in the "Output" tab from pulseaudio sound preferences menu:
From the command line we can also load the device for simultaneous output without having to run paprefs by
pacmd load-module module-combine-sink
# pacmd load-module module-combine # for PulseAudio < 1.0
Put this line (without pacmd) in your /etc/pulse/default.pa
to load this device at startup.
Thanks to this answer I finally found a solution, see the below instruction
Show always HDMI output in the mixed We will create a new profile that link both profiles "Analog audio" and "HDMI audio".
From my understanding this file
/usr/share/pulseaudio/alsa-mixer/profile-sets/default.conf
list all mapping profiles between Alsa and Pulseaudio.
1.
Find the mapping that are related to your Analog profile
and HDMI profile
definition.
(description: should match the Device Profiles shown in Audio Volume Kde setting module )
For me are the following:
[Mapping analog-stereo]
device-strings = front:%f
channel-map = left,right
paths-output = analog-output analog-output-lineout analog-output-speaker analog-output-headphones analog-output-headphones-2
paths-input = analog-input-front-mic analog-input-rear-mic analog-input-internal-mic analog-input-dock-mic analog-input analog-input-mic analog-input-linein analog-input-aux analog-input-video analog-input-tvtuner analog-input-fm analog-input-mic-line analog-input-headphone-mic analog-input-headset-mic
priority = 10
[Mapping hdmi-stereo-extra1]
description = Digital Stereo (HDMI 2)
device-strings = hdmi:%f,1
paths-output = hdmi-output-1
channel-map = left,right
priority = 2
direction = output
2.
On the base of the above Mapping definition I have created the following new profile that group both the above ones:
[Profile output:analog-stereo+output:hdmi-stereo-extra1]
description = All
output-mappings = analog-stereo hdmi-stereo-extra1
input-mappings = analog-stereo
3.
Restart pulse audio with this command:
pulseaudio --kill; sleep 1; pulseaudio --start
4.
Go to KDE phonon settings > Audio Hardware setup and select the new profile.
Now you should see both profile in the mixed and so you'll be able to switch easy:
I would suggest to use this plasmoid mixer: https://store.kde.org/p/1100894/
(extra step) Force both output enabled
If you don't mind having both computer speaker and TV output audio in the same time ( so basically you don't have to switch the audio output ever ).
You can select the below setting and then you'll have a new entry in the mixer
Best Answer
Sure, you could use the "pactl" and "pacmd" command.
An example for a pair of external USB speaker + internal speakers, with music playing.
The first one with index 0 is the internal speak, music is running on this sink. Another one with index 1 is the external USB speaker.
If you're not palying anything during the switch, you could stop here.
(Note, to make sure it really works, it would be better to do this with something playing, and move the stream as follows.)
If you're playing something you will notice that the music still running on the old device, you have to move it to the desired device:
Voilà! You could compose a script base on these.
Reference: How to change pulseaudio sink with “pacmd set-default-sink” during playback?