I want to do a simplest thing possible in ALSA: to have USB-headphones produce sound instead of internal speaker of my tablet. I don't want to change config files such as asound.rc or alsa.conf or asound.conf and permanently set headphones as default output device by changing the order of devices, I want a temporary effect, just until I unplug the headphones. Strangely, I can't google the answer. Is alsamixer capable of doing that (seems like no)?

In Gnome you can easily select current output device with PulseAudio, either in its GUI or CLI interface, but PulseAudio itself works on top of ALSA! So I also wonder, how it forces ALSA to change the output device?

  • alsamixer does have a "Select sound card" option in the interface, although I don't know if that also actually sets the output device. – goldilocks Aug 25 '13 at 14:47
  • 1
    no, unfortunately it just displays the parameters of this sound card and allows to tweak them, but doesn't redirect output to it – Boris Burkov Aug 25 '13 at 19:06
  • Hello, you can try exec alsamixer from a terminal and press F6 for select another sound card. :) – slackmart Aug 25 '13 at 21:02
  • @sgmart Hi, sgmart, i did exactly that, but it doesn't transfer sound to that device, it just selects that device for tuning its parameters, not streams output to it. – Boris Burkov Aug 25 '13 at 21:21
  • 3
    The alsamixer utility has some controls: Master, PCI, and so on. Check if there is a MM label (MM = mute), so use the M key from your keyboard to enable the sound. – slackmart Aug 25 '13 at 21:27

If the USB device is listed as a sound card in the system, you may want to check man amixer and use the unmute parameter.

amixer -c 1 set Master playback 100% unmute

Check also the other channels (PCM etc.). The examples from the manual are:

   amixer -c 1 sset Line,0 80%,40% unmute cap
          will set the second soundcard's left line input volume to 80% and right line
          input to 40%, unmute it, and select it as a source for capture (recording).

   amixer -c 1 -- sset Master playback -20dB
          will set the master volume of the second card to -20dB.  If the  master  has
          multiple channels, all channels are set to the same value.

   amixer -c 1 set PCM 2dB+
          will  increase  the PCM volume of the second card with 2dB.  When both play‐
          back and capture volumes exist, this is applied to both volumes.

   amixer -c 2 cset iface=MIXER,name='Line Playback Volume",index=1 40%
          will set the third soundcard's second line playback volume(s) to 40%

   amixer -c 2 cset numid=34 40%
          will set the 34th soundcard element to 40%
  • Thanks, Jari, it works. I've been reading the manuals on ALSA and have a question: are the devices listed by amixer and alsamixer actually not hardware devices, but ALSA devices, created by alsa plugins in /usr/share/alsa/alsa.conf and friends? I do mostly understand the syntax of those plugins, but can't find the definitions of the very fundamental keywords, such as "pcm" or "ctl" or "type". I failed to find any list of keywords in the doxygen documentation: alsa-project.org/alsa-doc/alsa-lib, alsa-project.org/alsa-doc/alsa-lib/conf.html. Do you know of any source of info about them? – Boris Burkov Aug 27 '13 at 11:16
  • 8
    This doesn't really solve the original question. You can set the parameters, but it does not change the card through which audio is outputed. – oneself Nov 14 '14 at 19:18
  • I agree with @oneself. This doesn't change the output device on-the-fly/temporarily. – Victor Jan 24 '15 at 1:22
  • 2
    If this actually answers the original question, a full example is needed. How does this do anything that alsamixer can't do? Clearly, alsamixer can't switch to output through a different sound card. Or, in my case, I also wanted to output through the same sound card but HDMI instead of speakers/headphone. Pulseaudio does these things, but how? Examples from start to finish are needed to make this a good answer. – Colin Keenan Jul 20 '15 at 15:49
  • 1
    @domsson just link back to this one and explain that the answer didn't solve your issue. That should ensure it isn't closed as a dupe. – terdon May 15 '18 at 8:56

IIUC you can update .asoundrc or /etc/asound.conf dynamically. So it should be possible to have two files headphones.conf and front.conf which set your default devices to the appropriate hw:channel,device numbers and then switch them on an "ACPI jack/headphone HEADPHONE plug" event. I'm about to try this, using "ln" to link /etc/asound.conf to one of /etc/sounds/{headphones,front}.conf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.