Last active
July 25, 2020 07:55
-
-
Save bassmanitram/495fd35b76083f0c4a79777b8ab470fd to your computer and use it in GitHub Desktop.
Workaround script to help solve Ubuntu 16.04 HDMI sound issues when ALSA can use the HDMI sink, but Pulse thinks it's unplugged
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
{ | |
# | |
# Get rid of pulse and its cache (so this script can be run multiple times) | |
# | |
rm ~/.config/pulse/* | |
pulseaudio -k | |
# | |
# Wait till pulse sorts itself out | |
# | |
sleep 2 | |
# | |
# Find the HDMI "cards" - you will likely have to modify this grep since it is atuned to my | |
# NVidia graphics card's active HDMI audio output device | |
# | |
card=$(aplay -l | grep "NVidia.*HDMI 1" -m 1) | |
# | |
# Log the card | |
# | |
echo $card | |
if [ "${card}" ]; then | |
# | |
# We have a card, so now we parse the aplay output line | |
# | |
# Effectively, it you split it into an array by "," and ":" then: | |
# | |
# the card number is the last "word" of the first item in the array | |
# the device number is the last "word" of the third item in the array | |
# | |
IFS=',:' read -r -a details <<< "${card}" | |
card_number="${details[0]##* }" | |
dev_number="${details[2]##* }" | |
# | |
# After that, just force-add the device's associated ALSA sink to Pulse | |
# | |
pacmd load-module module-alsa-sink device=hw:${card_number},${dev_number} | |
# | |
# And force Pulse to use that ALSA sink as the default output | |
# | |
pacmd set-default-sink alsa_output.hw_${card_number}_${dev_number} | |
else | |
# | |
# Can't find your card - fix the grep on line 18? | |
# | |
echo "No HDMI sound target found" | |
exit 1 | |
fi | |
# | |
# And we put all output into a log file in the home directory | |
# | |
} >> ~/fix_sound.log 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Finally, I helped someone - in the words of my wife "That almost NEVER happens"!