[GLLUG] How can I find out if external audio is connected?

James Dutton james.dutton at gmail.com
Sat Jan 7 14:37:35 UTC 2023

On Mon, 26 Sept 2022 at 07:56, Dr. Axel Stammler via GLLUG <
gllug at mailman.lug.org.uk> wrote:

> Hi,
> I would like to remind myself of external amplifiers uselessly running so
> I would like to play a short sound signal once in a while if there is no
> audio playing. OTOH, the signal should obviously not be played over the
> built-in speakers. So, how can I find out (preferably using a command-line
> utility in a script) which of the ‘audio out’ connectors are actually
> connected to anything (or just have a plug in them) and if anything is
> played over these connections?
> Any remarks greatly appreciated,
I am anLinux kernel ALSA developer although I have not contributed for some
time now.
There are over a 1000 different sound chips/hardware arrangements and the
Linux kernel ALSA tries to hide that, and present a generic API that can
work with those 1000 different sound chips.
It is not at all easy to do.

Some audio chips have "jack sense" hardware in them so they can detect
whether the headphones are plugged in or not.
For example, on the Linux desktop, you might be playing sound out of the
internal speakers, but if you plug some headphones in, the sound is
diverted to the headphones, and stops coming out of the internal speakers.
At the ALSA level, one can use "aplay" with a device name that is related
to a specific output jack on the sound card, but most simple sound
cards/chips only allow one application to connect to them at a time, and
for most Linux desktops, this app is pulseaudio or pipewire etc.
So, you will probably need to use the pulseaudio or pipewire APIs to
achieve your goal. I am not involved in those projects so cannot help.
But, it is probably worth also asking this Linux audio related question on
the pulseaudio mailing list/forum, if pulseaudio is what you are using,
otherwise pipewire.
Hopefully they can help you.

Kind Regards

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20230107/98ceb693/attachment.htm>

More information about the GLLUG mailing list