[pulseaudio-discuss] Pulseaudio, how to change between two connected microphones from command line?

Tanu Kaskinen tanuk at iki.fi
Sun Nov 5 10:23:39 UTC 2017

On Sat, 2017-11-04 at 05:32 -0600, inssrich at gmail.com wrote:
> Looking to accomplish the following:
> *        Change default microphone from analog mic to logitech 920C Webcam
> Mic (or back the other way) from the command line.

You seem to already know how to do this (i.e. the "set-default-source"
command of pacmd or pactl).

> *        would like to be able to do this using either/or/both the vendor
> ID, product id rather than the ugly long complicated device name. My
> scripting skills are rudimentary so this is lost on me.

This is not currently supported. You can make a script that does this,
but strictly speaking that's not supported either, because your script
would probably read the output of "pactl list sources" or something
like that, and the output format of that command is not guaranteed to
stay the same (in practice changes are unlikely, however).

> *        If that does not work, reset the USB connection to the camera so
> that it is rediscovered.
> Background
> I have a linux kiosk system that boots fresh every time and is configured
> from a config file on a web server. Currently I have two microphones
> connected to the kiosk; an analog mic into the microphone port and a
> logitech 920C with internal mic. Generally the internal mic comes up as the
> default. I can pass in commands from the config file and I would like the
> ability to choose which microphone is active after boot using this method.
> the system recognizes both microphones but the logitech does not seem to
> pass any sound into the system even after manipulating it in pavucontrol.
> The only way I've been able to make it work after a fresh boot is to
> disconnect it physically and reconnect it, at which point it functions as
> expected.
> What I've tried
> I've tried a number of methods to try and change the default microphone from
> analog to the logitech. The below code has worked in changing the default
> device but it made no change in the function of the microphone. Is this
> possibly because the Logitech shows up with it's own sound card?

No, showing up with its own sound card is not a reason to not work.

> $ pacmd "set-default-source device-name-of-logitech"
> I can mute and unmute and change volume of the source with the below code
> but it has no effect on function
> $ pactl set-source-mute 0 1
> $ pactl set-source-volume 0 50%
> I've also tried to reset the usb device using the below code. When doing so
> the logitech will dissapear from pavucontrol and then reappear but still
> without any functional results to make the microphone send audio
> sudo sh -c "echo 0 > /sys/bus/usb/devices/1-4.6/authorized"
> sudo sh -c "echo 1 > /sys/bus/usb/devices/1-4.6/authorized"

I don't know what those commands do, but if they make the logitech card
disappear and appear again in pavucontrol, then that probably resets
the card as well as any of my suggestions would have done.

FWIW, I would have suggested disabling module-udev-detect and loading
module-alsa-card manually, or switching the card profile to "off" and

> It seems like the only thing that works successfully and repeatedly is to
> physically disconnect/reconnect the camera from the computer. It's a bit of
> a hack but if I could reproduce that action from the command line I may be
> able to get it to work, though not very elegantly.

I don't know how to simulate physical unplugging, if it's even

I presume the webcam mic doesn't work even when using alsa directly? In
that case it would be better to report the problem to the alsa

> Also, it would be great to be able to send these commands by referencing the
> vendorID and productID as I'm not always certain of what index the devices
> will have if the physical connections are slightly different from system to
> system. As mentioned before my command line scripting skills are pitiful so
> any help in doing this would be appreciated.

You can use the card/source name instead of the index. The name
shouldn't change.

"pactl list cards | grep Name:" or "pactl list sources | grep Name:"
will print the names of all cards/sources.



More information about the pulseaudio-discuss mailing list