I am trying to write a bash command to switch between audio devices (not different cards). I found this AskUbuntu post about the topic, then I started going down the list below trying each output device to figure out which one is my speakers and which one is my headphones. Is there a better method?
What I tried:
pactl set-card-profile 0 output:hdmi-surround71
for each audio device, with no change from speaker to headphone output.
$ pacmd list-cards | grep output\:
output:hdmi-stereo: Digital Stereo (HDMI) Output (priority 5400, available: unknown)
output:hdmi-surround: Digital Surround 5.1 (HDMI) Output (priority 300, available: unknown)
output:hdmi-surround71: Digital Surround 7.1 (HDMI) Output (priority 300, available: unknown)
output:hdmi-stereo-extra1: Digital Stereo (HDMI 2) Output (priority 5200, available: unknown)
output:hdmi-surround71-extra1: Digital Surround 7.1 (HDMI 2) Output (priority 100, available: unknown)
output:hdmi-stereo-extra2: Digital Stereo (HDMI 3) Output (priority 5200, available: unknown)
output:hdmi-surround-extra2: Digital Surround 5.1 (HDMI 3) Output (priority 100, available: unknown)
output:hdmi-surround71-extra2: Digital Surround 7.1 (HDMI 3) Output (priority 100, available: unknown)
output:hdmi-stereo-extra3: Digital Stereo (HDMI 4) Output (priority 5200, available: unknown)
output:hdmi-surround-extra3: Digital Surround 5.1 (HDMI 4) Output (priority 100, available: unknown)
output:hdmi-surround71-extra3: Digital Surround 7.1 (HDMI 4) Output (priority 100, available: unknown)
active profile: <output:hdmi-surround71>
output:analog-stereo: Analog Stereo Output (priority 6000, available: unknown)
output:analog-stereo+input:analog-stereo: Analog Stereo Duplex (priority 6060, available: unknown)
output:analog-surround-21: Analog Surround 2.1 Output (priority 800, available: unknown)
output:analog-surround-21+input:analog-stereo: Analog Surround 2.1 Output + Analog Stereo Input (priority 860, available: unknown)
output:analog-surround-40: Analog Surround 4.0 Output (priority 700, available: unknown)
output:analog-surround-40+input:analog-stereo: Analog Surround 4.0 Output + Analog Stereo Input (priority 760, available: unknown)
output:analog-surround-41: Analog Surround 4.1 Output (priority 800, available: unknown)
output:analog-surround-41+input:analog-stereo: Analog Surround 4.1 Output + Analog Stereo Input (priority 860, available: unknown)
output:analog-surround-50: Analog Surround 5.0 Output (priority 700, available: unknown)
output:analog-surround-50+input:analog-stereo: Analog Surround 5.0 Output + Analog Stereo Input (priority 760, available: unknown)
output:analog-surround-51: Analog Surround 5.1 Output (priority 800, available: unknown)
output:analog-surround-51+input:analog-stereo: Analog Surround 5.1 Output + Analog Stereo Input (priority 860, available: unknown)
output:analog-surround-71: Analog Surround 7.1 Output (priority 700, available: unknown)
output:analog-surround-71+input:analog-stereo: Analog Surround 7.1 Output + Analog Stereo Input (priority 760, available: unknown)
output:iec958-stereo: Digital Stereo (IEC958) Output (priority 5500, available: unknown)
output:iec958-stereo+input:analog-stereo: Digital Stereo (IEC958) Output + Analog Stereo Input (priority 5560, available: unknown)
active profile: <output:analog-stereo+input:analog-stereo>
iec958-stereo-output: Digital Output (S/PDIF) (priority 0, latency offset 0 usec, available: unknown)
$ pactl set-card-profile 0 output:hdmi-surround71
my sinks:
$ pacmd list-sinks
2 sink(s) available.
* index: 10
name: <alsa_output.pci-0000_00_14.2.analog-stereo>
driver: <module-alsa-card.c>
flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
state: RUNNING
suspend cause:
priority: 9959
volume: front-left: 50462 / 77% / -6.81 dB, front-right: 50462 / 77% / -6.81 dB
balance 0.00
base volume: 65536 / 100% / 0.00 dB
volume steps: 65537
muted: no
current latency: 23.16 ms
max request: 4 KiB
max rewind: 64 KiB
monitor source: 11
sample spec: s16le 2ch 44100Hz
channel map: front-left,front-right
Stereo
used by: 1
linked by: 1
configured latency: 23.22 ms; range is 1.00 .. 371.52 ms
card: 1 <alsa_card.pci-0000_00_14.2>
module: 7
properties:
alsa.resolution_bits = "16"
device.api = "alsa"
device.class = "sound"
alsa.class = "generic"
alsa.subclass = "generic-mix"
alsa.name = "ALC892 Analog"
alsa.id = "ALC892 Analog"
alsa.subdevice = "0"
alsa.subdevice_name = "subdevice #0"
alsa.device = "0"
alsa.card = "0"
alsa.card_name = "HDA ATI SB"
alsa.long_card_name = "HDA ATI SB at 0xfe200000 irq 16"
alsa.driver_name = "snd_hda_intel"
device.bus_path = "pci-0000:00:14.2"
sysfs.path = "/devices/pci0000:00/0000:00:14.2/sound/card0"
device.bus = "pci"
device.vendor.id = "1002"
device.vendor.name = "Advanced Micro Devices, Inc. [AMD/ATI]"
device.product.id = "4383"
device.product.name = "SBx00 Azalia (Intel HDA)"
device.form_factor = "internal"
device.string = "front:0"
device.buffering.buffer_size = "65536"
device.buffering.fragment_size = "32768"
device.access_mode = "mmap+timer"
device.profile.name = "analog-stereo"
device.profile.description = "Analog Stereo"
device.description = "Built-in Audio Analog Stereo"
alsa.mixer_name = "Realtek ALC892"
alsa.components = "HDA:10ec0892,1462f640,00100302"
module-udev-detect.discovered = "1"
device.icon_name = "audio-card-pci"
ports:
analog-output-lineout: Line Out (priority 9900, latency offset 0 usec, available: no)
properties:
analog-output-headphones: Headphones (priority 9000, latency offset 0 usec, available: yes)
properties:
device.icon_name = "audio-headphones"
active port: <analog-output-headphones>
index: 14
name: <alsa_output.pci-0000_01_00.1.hdmi-stereo-extra1>
driver: <module-alsa-card.c>
flags: HARDWARE DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
state: SUSPENDED
suspend cause: IDLE
priority: 9050
volume: front-left: 65536 / 100% / 0.00 dB, front-right: 65536 / 100% / 0.00 dB
balance 0.00
base volume: 65536 / 100% / 0.00 dB
volume steps: 65537
muted: no
current latency: 0.00 ms
max request: 0 KiB
max rewind: 0 KiB
monitor source: 15
sample spec: s16le 2ch 44100Hz
channel map: front-left,front-right
Stereo
used by: 0
linked by: 0
configured latency: 0.00 ms; range is 0.50 .. 371.52 ms
card: 0 <alsa_card.pci-0000_01_00.1>
module: 6
properties:
alsa.resolution_bits = "16"
device.api = "alsa"
device.class = "sound"
alsa.class = "generic"
alsa.subclass = "generic-mix"
alsa.name = "HDMI 1"
alsa.id = "HDMI 1"
alsa.subdevice = "0"
alsa.subdevice_name = "subdevice #0"
alsa.device = "7"
alsa.card = "1"
alsa.card_name = "HDA NVidia"
alsa.long_card_name = "HDA NVidia at 0xfe080000 irq 26"
alsa.driver_name = "snd_hda_intel"
device.bus_path = "pci-0000:01:00.1"
sysfs.path = "/devices/pci0000:00/0000:00:02.0/0000:01:00.1/sound/card1"
device.bus = "pci"
device.vendor.id = "10de"
device.vendor.name = "NVIDIA Corporation"
device.product.id = "0fbb"
device.product.name = "GM204 High Definition Audio Controller"
device.string = "hdmi:1,1"
device.buffering.buffer_size = "65536"
device.buffering.fragment_size = "32768"
device.access_mode = "mmap+timer"
device.profile.name = "hdmi-stereo-extra1"
device.profile.description = "Digital Stereo (HDMI 2)"
device.description = "GM204 High Definition Audio Controller Digital Stereo (HDMI 2)"
alsa.mixer_name = "Nvidia GPU 71 HDMI/DP"
alsa.components = "HDA:10de0071,196e1131,00100100"
module-udev-detect.discovered = "1"
device.icon_name = "audio-card-pci"
ports:
hdmi-output-1: HDMI / DisplayPort 2 (priority 5800, latency offset 0 usec, available: yes)
properties:
device.icon_name = "video-display"
device.product.name = "ASUS VH238
"
active port: <hdmi-output-1>
From a comment on AskUbuntu about changing audio sinks by @Julian:
switches to the last unused output. This should be sufficient to toggle between your inputs.
I know this isn't the answer you want, but testing indicates that simply the act of plugging a pair of headphones into the headphone jack eliminates any output to the speaker jack. You can test this for yourself via the sound app as shown below. Run it, unplug your headphones and you will see this:
Use the Test sound button to confirm that you are getting output out of your speakers.
Then plug in your headphones. You will see them show up automatically highlighted as seen below:
If you now highlight The previously selected output (In my case Analog Output) And repeat the Test Sound process you will get nothing from the speakers as the act of plugging in the headphones changes the route at the hardware level. This is commonly done with a switch contact connector that looks like this internally.
As soon as you plug into the jack, the 'spring loaded' connectors in the jack are both connected to the male plug, and disconnected internally from the speakers.
In order to have any chance of doing this whatsoever you would likely have to swap out or modify the headphone jack to insure that the signal doesn't get interrupted to the speakers upon insertion. I am NOT recommending this course of action and will NOT be held responsible for any damage you manage to inflict on your system in the attempt.
Then you would have to utilize the
find
command to determine what file changed in the seconds it took you to change the output in the sound app and analyze the changes for clues as to how to duplicate them via the CLI. This part is untested and a total assumption on my part based on information at hand.Sources:
Testing
http://www.instructables.com/answers/How-do-I-make-a-headphone-jack-cancel-the-output-o/