Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

To switch to HDMI audio output (of monitor) and back to normal audio output from system audio jack (for headphones, as my monitor doesn't have audio out), I find myself opening up sound preferences and selecting the right channel everytime. Is there any way I can create a toggle button in the panel or assign some shortcut key to toggle since I do the switching so often.

:aplay -l 
**** List of PLAYBACK Hardware Devices ****
card 0: Intel [HDA Intel], device 0: STAC92xx Analog [STAC92xx Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 3: HDMI 0 [HDMI 0]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 7: STAC92xx Digital [STAC92xx Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

enter image description here

share|improve this question
1  
+1 It would be awesome if I could switch to the correct HDMI display output mode and sound mode in one keypress. – Kit Menke Nov 30 '11 at 2:10

5 Answers

With pulseaudio we are able to select the output sink from the command line:

pacmd set-default-sink "SINKNAME"

This command can be used in a launcher, script or even assigned to a keyboard shortcut for fast switching between different sinks. Please replace "SINKNAME" by the name or number of your desired sink. A list of known sinks with their associated numbers and names is given by the command:

pacmd list-sinks

Note: Changing the output sink through the command line interface can only take effect if stream target device reading is disabled. This can be done by editing the corresponing line in /etc/pulse/default.pa to:

load-module module-stream-restore restore_device=false

Alternatively we could run pulseaudio to simultaneously output sound to the internal audio device, and to the hdmi-device by running paprefs Install paprefs with the option to add a virtual output device:

paprefs

share|improve this answer
1  
pacmd set-default-sink "alsa_output.pci-0000_00_1b.0.analog-stereo" and pacmd set-default-sink "alsa_output.pci-0000_00_1b.0.hdmi-stereo" works only after selecting the corresponding profile in Sound Preferences. If I am having HDMI set and I run the pacmd command for analog stereo, I'm getting the eror Sink alsa_output.pci-0000_00_1b.0.analog-stereo does not exist. But if I manually select the profile from Sound Preferences GUI and run the same command, I am not getting the error. So it is not helping to switch. – iJeeves May 10 '11 at 21:39
@iJeeves: see edit for update. – Takkat May 21 '11 at 21:49

I've been trying to find a solution to this problem as well. As of Ubuntu 11.04 this does not seem to be possible directly, I only found this guide to add both HDMI and Analog as separate outputs, so pacmd shows 3 sinks now. Then it is possible to switch between sinks using the above commands. (see also https://vaioubuntu.wordpress.com/2009/07/08/hdmi-sound-output-switcher-for-pulseaudio/) But apparently Ubuntu 11.11 will gett a PulseAudio with jack detection system. According to the website below, David Henningsson has coded a detection via udev so pulse audio automatically gets switched to the last added output, including switching between different profiles of the same soundcard (as is the case with your and my setup). (see http://voices.canonical.com/david.henningsson/2011/09/06/pulseaudio-with-jack-detection/) So I'm hoping this will work, when I try the final version next Friday.

share|improve this answer

If you are using Gnome Shell instead of Unity you can install the extension below. You'll then be able to switch from the volume short-cut in the top panel. https://extensions.gnome.org/extension/142/output-device-chooser-on-volume-menu/

share|improve this answer

Since there is only one soundcard visible in the screenshot, I think the output of this soundcard should be switched.

For example: I have a Notebook with one integrated soundcard, but it has a digital output (SPDIF) when docked.

So what I wanted to do is switch the active output or "Profile" in pulseaudio.

I found the commands that do exactly that:

pacmd set-card-profile 0 output:analog-stereo
pacmd set-card-profile 0 output:iec958-stereo+input:analog-stereo

What I did to get the correct names for my desired output-setting--here, digital output, but analog (micro) input--was:

pacmd list | grep output
share|improve this answer

I found this very annoying myself and wrote a script to toggle the output:

#!/bin/bash

CURRENT_PROFILE=$(pacmd list-cards | grep "active profile" | cut -d ' ' -f 3-)

if [ "$CURRENT_PROFILE" = "<output:hdmi-stereo+input:analog-stereo>" ] ; then
        pacmd set-card-profile 0 "output:analog-stereo+input:analog-stereo"
else 
        pacmd set-card-profile 0 "output:hdmi-stereo+input:analog-stereo"        
fi

and then bound an unused key on my keyboard to execute it (see How to bind custom commands to keyboard shortcuts?)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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