17

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?

6
  • 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, 2013 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 Aug 25, 2013 at 19:06
  • Hello, you can try exec alsamixer from a terminal and press F6 for select another sound card. :)
    – slackmart
    Aug 25, 2013 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. Aug 25, 2013 at 21:21
  • 4
    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, 2013 at 21:27

4 Answers 4

4

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%
8
  • 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? Aug 27, 2013 at 11:16
  • 14
    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, 2014 at 19:18
  • 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. Jul 20, 2015 at 15:49
  • 2
    Pitty this has been selected as answer - the question is exactly what I'm looking for: how to temporarily change the card used for output. However, as @oneself already noted, this answer does not actually explain how to do that. Asking a new question with almost the same title is now likely to get closed as duplicate.
    – domsson
    Apr 3, 2018 at 16:50
  • 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, 2018 at 8:56
0

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

1
  • 1
    It doesn't work until you restart the software that uses audio.
    – L29Ah
    Jul 22, 2020 at 12:36
0

Many sound applications can use other, non-default outputs. Even Chromium browser has command line switch to choose sound output. You can create a simple wrapper to run your sound application with desired output to avoid messing with conf every time.

0

I too was looking for this, and it does not seem that alsamixer can do this. A slightly tangential approach is to launch pavucontrol, which easily allows for this. pavucontrol can be launched from terminal and if you go to playback, you can easily switch b/w the available outputs.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .