Is there a way to switch sound output between speakers and headphones without physically unplugging any on a Realtek built-in audio?

I highly doubt that ALSA is where you want to fiddle with this. It may be possible to do it that way, but it’s likely that it’ll mess something up for PulseAudio, or that PulseAudio will mess you up at some point in the future. (Though I guess that was more of a danger when it was in active development, now it seems like it’s in a holding pattern.)

@jbs4115 beat me to the pavucontrol suggestion, as that would’ve been my first instinct as well. At the risk of belaboring that point, did you check all of the tabs?

For example, my USB audio device (a literally $10 jobbie I got from Newegg) doesn’t do any kind of fancy auto-switching, but it does have a bunch of different output configurations because it’s one of those units with a combo analog/digital headphone jack, where there’s an LED at the bottom of the port so you can stick a specially-shaped optical cable in there and use SP/DIF. As a result, it has quite a few different configurations.

On the “Output Devices” tab, there’s a Port selector, but just like yours it only ever shows one option:

But that’s because what option is shown there is controlled in the Configuration tab:

So, my first suggestion is definitely to double-check the Configuration tab, and make sure there’s nothing there that will help you.

If there really isn’t, then and only then I’d try going the alsa route:

# Find the card# of the device
$ aplay -l
# Load the mixer controls for the card
$ alsamixer -c $CARD_NUM

Left and right arrow keys move between controls. Up and down to change levels or select between options. Hitting M toggles on/off state. Type Esc to quit — don’t use Q, as that’ll raise the left channel level of the control you’re on by one step. (If you do accidentally change something, B to Balance the levels is good enough, PulseAudio ignores the levels of the controls anyway, it only cares whether they’re muted or not.

The control you’d be looking for is very likely a simple on/off “switch” where white-on-green “OO” means “on” / blue-on-background “MM” means “muted”, or it’s a selector between several fixed options. You could also install the qasmixer package from the repos for an excessively-graphical, but more user-friendly, interface to the same controls.

If all that fails, then looking for an option in the relevant snd_foo kernel module is worth a look, I suppose — but I’m pretty sure anything of that sort that’s remotely relevant got eliminated from the drivers for all current hardware long ago.

2 Likes