Skip to content

Instantly share code, notes, and snippets.

@ChriRas
Last active Jun 28, 2022
Embed
What would you like to do?
Set up default audio device on Ubuntu 20.04 LTS

Problem

I have a notebook connected to a port replicator. I want to use the build-in speakers and microfone and not the external ones. If I boot my notebook in my port replicator Ubuntu changes the devices to external.

Solution

  1. Find your internal speaker
pactl list short sinks

0	alsa_output.usb-Generic_USB_Audio_201405280001-00.analog-stereo	module-alsa-card.c	s16le 2ch 44100Hz	SUSPENDED
1	alsa_output.pci-0000_00_1f.3.analog-stereo	module-alsa-card.c	s16le 2ch 44100Hz	SUSPENDED
  1. Set your internal speaker as default pactl set-default-sink <DEVICE> e.g. pactl set-default-sink alsa_output.pci-0000_00_1f.3.analog-stereo

  2. Add to "Startup Applications" ("Startprogramme" in German)

  • Open the application "Startup Applications" (Should be preinstalled on Ubuntu)
  • Click on "Add"
  • Give your startup item a name
  • Copy your command from above into the command field.
  • Click on "Save".
  1. Find your internal microfone
pactl list short sources

0	alsa_output.usb-Generic_USB_Audio_201405280001-00.analog-stereo.monitormodule-alsa-card.c	s16le 2ch 44100Hz	SUSPENDED
1	alsa_input.usb-Generic_USB_Audio_201405280001-00.iec958-stereo	module-alsa-card.c	s16le 2ch 44100Hz	RUNNING
2	alsa_output.pci-0000_00_1f.3.analog-stereo.monitor	module-alsa-card.c	s16le 2ch 48000Hz	SUSPENDED
3	alsa_input.pci-0000_00_1f.3.analog-stereo	module-alsa-card.c	s16le 2ch 44100Hz	SUSPENDED
  1. Set your internal speaker as default pactl set-default-source <DEVICE> e.g. pactl set-default-source alsa_input.pci-0000_00_1f.3.analog-stereo

  2. Repeat step 3.

@cedric80
Copy link

cedric80 commented Feb 12, 2021

Works perfect! Thanks for nice and easy solution.

@jayyantonucci
Copy link

jayyantonucci commented Mar 22, 2021

+1

@seaniedan
Copy link

seaniedan commented Apr 27, 2021

yay, this worked! Great solution. The general advice was to edit the defaults with
sudo nano /etc/pulse/default.pa
uncommenting the line at the bottom to read something like
set-default-sink output 1 #where 1 is the output you want from 'pactl list short sinks' as above
..however this didn't work for me. Your elegant solution does, thank you!

@blackforestcode
Copy link

blackforestcode commented Aug 22, 2021

Great, thanks! 👍

@Jobin-S
Copy link

Jobin-S commented Nov 5, 2021

thank you, bro. Its worked perfectly

@OptimBro
Copy link

OptimBro commented Nov 19, 2021

Elegant solution, btw little typo in
"Set your internal speaker as default pactl set-default-source e.g. ppactl set-default-source alsa_input.pci-0000_00_1f.3.analog-stereo"

Its pactl not "ppactl" (save some milliseconds for copy pasters 🤣)

anyways, thanks.

@Jobin-S
Copy link

Jobin-S commented Nov 20, 2021

Elegant solution, btw little typo in "Set your internal speaker as default pactl set-default-source e.g. ppactl set-default-source alsa_input.pci-0000_00_1f.3.analog-stereo"

Its pactl not "ppactl" (save some milliseconds for copy pasters rofl)

anyways, thanks.

😆

@ChriRas
Copy link
Author

ChriRas commented Nov 22, 2021

Elegant solution, btw little typo in "Set your internal speaker as default pactl set-default-source e.g. ppactl set-default-source alsa_input.pci-0000_00_1f.3.analog-stereo"
Its pactl not "ppactl" (save some milliseconds for copy pasters rofl)
anyways, thanks.

😆

fixed! Thanks for the hint.

@comxd
Copy link

comxd commented Nov 22, 2021

yay, this worked! Great solution. The general advice was to edit the defaults with sudo nano /etc/pulse/default.pa uncommenting the line at the bottom to read something like set-default-sink output 1 #where 1 is the output you want from 'pactl list short sinks' as above ..however this didn't work for me. Your elegant solution does, thank you!

This is the best way, a native solution without needed to create a startup script. The only thing about that: you need to replace the input and output keywords by your device ID.

Edit /etc/pulse/default.pa:

### Make some devices default
set-default-sink 1
set-default-source 3

Then restart pulseaudio: pulseaudio -k.

To identify your output (speaker) device ID : pactl list short sinks (in my case: 1)
To identity your input (microphone) device ID: pactl list short sources (in my case: 3)

@LucasMatuszewski
Copy link

LucasMatuszewski commented Dec 28, 2021

@seaniedan - setting default output sink in /etc/pulse/default.pa is more elegant, since this file runs on each system boot anyway.
To make it work you have to restart pulseaudio .configs by deleting pulse directory: rm -r ~/.config/pulse
I've found this solution here: https://askubuntu.com/a/1038492

Probably pulseaudio -k command mentioned by @comxd do the same ;)

But it's safer to set sink by name instead of its number (which can change), in my example:
set-default-sink alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp__sink

I also had a problem that my Mic's build-in minijack output was set each time I have plugged my Mic into the USB port. To solve it you can also comment this lines in /etc/pulse/default.pa file:

#.ifexists module-switch-on-connect.so
#load-module module-switch-on-connect
#.endif

@GhastlyOne
Copy link

GhastlyOne commented Mar 9, 2022

Danke! was just what I needed!

@Trikenstein
Copy link

Trikenstein commented May 22, 2022

Edit etc/pulse/default.pa is the better solution. However, the comments above seem not working in my case Ubuntu 20.04.4 (desktop with sound card + web cam + USB headset) because:

  • The numerical ID of sinks & sources change at each reboot. So hard-coding an ID is inaccurate
  • set-default-... alone is not enough, I end up with two devices enabled. The one pre-selected by PulseAudio (which I don't know based on which criteria) and the one I set by set-default-...

The working solution for me is:

  1. Get the current default devices selected by PulseAudio (those having RUNNING as status)
echo '\nSINKS (output)' && pactl list short sinks && echo '\nSOURCES (input)' && pactl list short sources

SINKS (output)
0       alsa_output.pci-0000_04_00.1.hdmi-stereo        module-alsa-card.c      s16le 2ch 48000Hz       SUSPENDED
1       alsa_output.usb-Logitech_Logitech_B530_USB_Headset-00.analog-stereo     module-alsa-card.c      s16le 2ch 48000Hz       RUNNING
2       alsa_output.pci-0000_00_1b.0.analog-stereo      module-alsa-card.c      s16le 2ch 48000Hz       SUSPENDED

SOURCES (input)
0       alsa_output.pci-0000_04_00.1.hdmi-stereo.monitor        module-alsa-card.c      s16le 2ch 48000Hz       SUSPENDED
1       alsa_output.usb-Logitech_Logitech_B530_USB_Headset-00.analog-stereo.monitor     module-alsa-card.c      s16le 2ch 48000Hz       SUSPENDED
2       alsa_input.usb-Logitech_Logitech_B530_USB_Headset-00.mono-fallback      module-alsa-card.c      s16le 1ch 48000Hz       SUSPENDED
3       alsa_input.usb-HK_5M_EKACOM-K20E_200901010001-02.analog-stereo  module-alsa-card.c      s16le 2ch 48000Hz       RUNNING
4       alsa_output.pci-0000_00_1b.0.analog-stereo.monitor      module-alsa-card.c      s16le 2ch 48000Hz       IDLE
  1. Edit /etc/pulse/default.pa explicitly suspend the devices selected by PulseAudio and set-default the one you want
# CHANGE
#set-default-sink output
#set-default-source input

# TO
suspend-sink alsa_output.usb-Logitech_Logitech_B530_USB_Headset-00.analog-stereo true
set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo
suspend-source alsa_input.usb-HK_5M_EKACOM-K20E_200901010001-02.analog-stereo true
set-default-source alsa_input.usb-Logitech_Logitech_B530_USB_Headset-00.mono-fallback
  1. Reboot. Maybe pulseaudio --kill && pulseaudio --start would be enough but in my case I tested the real use-case with a reboot.

Reference: Ubuntu manual - pactl

@AndriyKalashnykov
Copy link

AndriyKalashnykov commented Jun 4, 2022

(Ubuntu 22.04 LTS) doing the same when logging into Ubuntu Desktop did it for me:

vi ~/.config/autostart/my_script.desktop

[Desktop Entry]
Type=Application
Name=My Script
Exec=/home/<path-to-your-script>/install-sound.sh
Icon=system-run
X-GNOME-Autostart-enabled=true

vi /home/<path-to-your-script>/install-sound.sh

#!/bin/bash

# get list of available available audio output devices (sinks)
# pactl list short sinks
# set default output device to HDMI/DisplayPort LG monitor

pactl set-default-sink alsa_output.pci-0000_01_00.1.hdmi-stereo

# get list of available available audio input devices (sources):
#pactl list short sources
# set default audio input to USB BRIO web camera

pactl set-default-source alsa_input.usb-046d_Logitech_BRIO_301280B8-02.analog-stereo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment