My take on this would be the following taking advantage of PulseAudio. Assuming that when you log in Ubuntu, you always have your headphones connected, then the following will make sure that when you boot to Ubuntu it will automatically set it as the default Input and Output (Assuming you want both).
On Ubuntu go to the terminal and type the following from which you will only gather the Index Number:
For your OUTPUT DEVICES:
pacmd list-sinks
- There will be a lot of information but look for the Index Numbers and the corresponding device that will be your new default Output Device.
For your INPUT DEVICES:
pacmd list-sink-inputs
OR pacmd list-samples
- There will be a lot of information but look for the Index Numbers and the corresponding device that will be your new default Input Device. Use the list-samples in case in the list-sink-inputs it does not show.
Right up to this point, on Ubuntu, with your headphones connected, you should have 2 index numbers. One for your input and output. Now we will go and edit your pulseaudio default configuration:
sudo nano /etc/pulse/default.pa
Go to the last line and simply add the following:
set-default-sink 1
- This corresponds to the Output Source after looking at the index of pacmd list-sinks
. The 1 is the index, so change it to the one you got.
set-default-source 5
- This corresponds to the Input Sources after looking at the index of pacmd list-sink-inputs
or pacmd list-samples
. The number 5 is the index, so change it to the one you got.
Save the file an reboot the computer to test. The testing involves checking if you got the correct index value, since some devices have similar names (Like NVIDIA OR INTEL Audio sources).
If everything is correctly setup, every time you boot your computer, you should see Ubuntu sets the default Input/Output to your headphone. Since you are talking about Headphones, for Noise reduction you can use my other answer to help you with that: Realtime noise-removal with PulseAudio?
NOTE: You can also use pacmd list-sources
to see all devices and also instead of using the index number, you can use the name of the assigned device, that look something like this:
alsa_input.usb-Logitech_Logitech_USB_Headset-00.analog-mono.echo-cancel
to give you an idea of what names to look for (Super long I know). Names are more accurate to use but harder to remember so you have an option here to use one or the other. The end result using a name, would be like this:
set-default-source alsa_input.usb-Logitech_Logitech_USB_Headset-00.analog-mono.echo-cancel
in the default.pa file, just to give you an idea.
For a GUI option, I recommend pavucontrol
or PulseAudio Volume Control. It offers an option to set a device as default/fallback for Input and Output devices. Using both techniques might give you what you want.
I just faced a similar problem.
I also have an HDMI monitor plugged in, so PulseAudio chose it instead of the headphones. After unplugging and plugging the headphone in the audio jack, I can only guess it gave priority back to the headphone and set it as the default.
So the issue for me is that PulseAudio is setting up the wrong profile by default due to my HDMI monitor being present. The headphones are still being detected, just not being used due to the wrong profile.
Solution: Remove any configuration files auto-generated at ~/.config/pulse
rm -r ~/.config/pulse
Then restart pulseaudio
pulseaudio --kill && pulseaudio --start
If you open pavucontrol
, it should be correctly set to a profile matching the headphones.
For example:
Then go to the Devices tab and check if Headphones (plugged in) is selected as the default device.
Best Answer
this works for me on 18.04, I had several problems and now all solved, try these steps I hope it help.
Step One (headset instead of headphone)
if you have a headset with one jack for both Mic and headphone and it's not working you need to do these :
check if your last three lines in
/etc/modprobe.d/alsa-base.conf
are similar to:You probably don't have the last two lines. Add them at the end of the file and save it. with these settings whenever you plugged your headphone into your PC/laptop ubuntu asks you if it's a headset a Mic or a headphone.
Step Two (echo cancellation)
for disabling echo cancellation and some noise open this file :
/etc/pulse/default.pa
and add
load-module module-echo-cancel
some where into it.
and finally Step Three (your answer)
With this method you can restart your audio card module so your headphone can work again without restarting your PC/Laptop :
it should work :) for doing this at startup do this :
and even if this method didn't work too :/ you need to disable the secure boot as mentioned here.