No sound in Ubuntu 18.04

When I first installed it there was sound but after doing updates, upgrades, installations and couple of restarts the sound is gone.

I ran this codes -

sudo alsa force-reload

Then restarted but no luck.

Then I tried,

sudo apt-get remove --purge alsa-base pulseaudio
sudo apt-get install alsa-base pulseaudio
sudo alsa force-reload

But still no luck.


I found a way to get back the sound.

I ran this code -

pactl load-module module-detect

and got

21

Now the sound is back.

The problem was it was not detecting any Hardware Output Devices


Have you checked the output options at sound settings?

After having updated my hardware (graphic card with built-in sound module) the setting had changed without notice. Also there were two different HDMI devices listed. Only one of them was working.