Switching audio output from a shortcut

Hello everyone,
This could make my daily work really easier, but I didn’t find a simple way to do it.

I have 2 sound configuration: my speakers, and my headset/microphone. When I use my headset, the speakers are shut down, and when I use the speakers, the headset output is shut down.
(My headset is always plugged in, I managed to make it so the audio doesn’t automatically switch to headphones when they are plugged. So I don’t have to manually plug them every time I want to use them, I just have to switch the output. That works well).

Now, in order to switch from speakers to headphones, I have to go to the system tray with the sound icon, click on it, change the port from “line out” to “headphones”, and unmute the front microphone:


and do that back again to switch to speakers.
I would like to automate all that process with a single shortcut.

I didn’t find any application able to setup “audio profiles” and to easily switch from one port to another.
Since I can do it with a mouse, I suppose I can do it with some command lines, but I don’t know where to start. Can someone help?

You forgot to tell us with what environment you are working.

inxi -Fzx would give more info’s. Please post them as formatted text here.

For Gnome, go to extensions.gnome.org and search for “Audio output”, there is a bunch of extensions that place a little icon in the Top icon bar (you need an extension for the Top Icon bar) to appear :laughing:).

Thank you for the responses.
@ilikelinux I’m on Fedora 36 Kde Spin in that particular desktop.
@augenauf I already have a “Top Icon Bar” and I’m already able to switch audio from there, as shown in my message.

I didn’t give the environment I’m working on because I can change the environment at any time if it could make that work. So any solution is welcomed.

But I tried PavuControl, QjackCtl, qashctl, I looked for kde widgets and gnome extensions. I didn’t find any easy way to create audio “profiles” and switch from one to another in any of those programs. I can always switch using the mouse, or a long string of things, but I didn’t find a way to make a single shortcut. If there is, I missed it (I saw forums where people are buying mechanical switches instead of doing it in software because it’s easier).

If I knew how to switch audio ports in command line (switching from Line out to headphones), I’m pretty confident I could make a simple script. I believe all flavors of Fedora still use PulseAudio, so I found this: https://shallowsky.com/linux/pulseaudio-command-line.html

I’m going to dive in that hot mess and see what happens.

Fedora has replaced pulseaudio with pipewire & wireplumber in Workstation since about version 34. I am not sure about the spins but it seems likely that all switched at the same time.

@computersavvy Yeah, I figured that out while testing things.
I heard about the change sometime ago, but I didn’t know if that went through.
The audio page on the Fedora wiki doesn’t mention pipewire though: Audio - Fedora Project Wiki

But yeah, I checked, you’re 100% right:

systemctl --user status pipewire
● pipewire.service - PipeWire Multimedia Service
     Loaded: loaded (/usr/lib/systemd/user/pipewire.service; disabled; vendor preset: dis>
    Drop-In: /usr/lib/systemd/user/pipewire.service.d
     Active: active (running) since Fri 2022-09-30 16:46:07 CEST; 18min ago
TriggeredBy: ● pipewire.socket
   Main PID: 2219 (pipewire)
      Tasks: 2 (limit: 38375)
     Memory: 8.1M
        CPU: 1.848s
     CGroup: /user.slice/user-1000.slice/user@1000.service/session.slice/pipewire.service
             └─ 2219 /usr/bin/pipewire

sept. 30 16:46:07 fedora systemd[2005]: Started pipewire.service - PipeWire Multimedia Se>
sept. 30 16:46:07 fedora pipewire[2219]: mod.rt: Can't find xdg-portal: (null)
sept. 30 16:46:07 fedora pipewire[2219]: mod.rt: found session bus but no portal

So it’s going to be more difficult than I thought. It’s all in all a very good news, audio as always been some sort of fifth wheel on the linux wagon, and Pipewire may clarify and fix a lot of issues, but in the meantime there’s not a lot of documentation on the subject, and it’s mainly aimed at developers. I’ll have to dig in the man page of the pw-cli command (and boy do I love man pages).

If anyone has a tip, I’ll take it.

1 Like

maybe Using and Customizing Shortcuts
but i don’t know command to switch audio source in pipewire

Are all your sinks/sources listed when running wpctl status?

You may be able to use wpctl set-default and/or set-profile to do what you need.

For pulling the ID for set-default I use:
wpctl status | awk '/vol/&&!/*/{print substr($2, 1, length($2)-1)}'