KDE 5 - How to easily switch between audio outputs?

36,877

Solution 1

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. 2 profiles in the mixer

Now you should see both profile in the mixed and so you'll be able to switch easy:

HDMI is always shown in the mixer now
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

enter image description here

Solution 2

As KDE 5 seems to be just frontend for PulseAudio, you can use direct access to PulseAudio with pactl command.

You will have to experiment a little bit to find a correct settings for you exact setup, but I would recommend excellent Arch Linux wiki on Pulse Audio, the Pulse Audio Configuration and Examples.

After figuring the correct commands, create a small shell scripts and create entry for those in ~/.local/share/applications/ (assuming that KDE 5 uses free desktop specification to create launcher for applications -- I am not really sure as I never used KDE).

Solution 3

I searched everywhere ... I did not find ... I made a script in python, use it)

import os
speakers = []
st = 0
au = os.popen("pacmd list-sinks")
audiotm = au.read()
audio = list(audiotm.split())
indices = [i for i, x in enumerate(audio) if x == "name:"]
for num in range(len(indices)):
    speakers.append(audio[indices[num]+1])
for num in range(len(speakers)):
    speakers[num] = speakers[num][1:len(speakers[num])-1]
dir = os.path.abspath(__file__)
dir = dir[:-5]
try: f = open(dir + "lststate.txt","r");st = int(f.read()) ;f.close();
except:f = open(dir + "lststate.txt","w");f.write(str(st)); f.close();
if st == len(speakers): st = 0;
OUT = speakers[st]
st += 1
f = open(dir + "lststate.txt","w");f.write(str(st)); f.close();
z = os.popen("pactl list short sink-inputs")
OUTID = z.read().split()
x = os.popen("pacmd set-default-sink " + OUT)
for num in range(0,len(OUTID),7):
    y = os.popen("pactl move-sink-input " + OUTID[num] + " " + OUT)
exit()
Share:
36,877

Related videos on Youtube

syss
Author by

syss

Updated on September 18, 2022

Comments

  • syss
    syss over 1 year

    I currently have KDE 5 Plasma installed which I like a lot.

    However, it is not possible to easily switch between Audio outputs from One Soundcard (SPDIF and analog) like it was possible in Unity.

    Is there a way to accomplish this without going to this menu here:

    enter image description here

    I need like one setting for each

    1. Digital Stereo + Analog Stereo Input
    2. Analog Audio Stero + Analog Stereo Input

    I want to change them here:

    enter image description here

    Is it possible?

    • user.dz
      user.dz about 8 years
      Could you try this answer , it is for KDE4
    • Michael
      Michael about 8 years
      It seems that this user-interface aspect is being redesigned at the moment. There is a blog post that is describing the problem, proposing a solution, and requesting feedback. Do check it out here: davidrosca.blogspot.ca/2016/04/…
    • Yannick Schneider
      Yannick Schneider over 6 years
      Finally I found a good solution see my answer, please remember to accepted it .