Audio Card Test

A test if there is some problems to select the right audio card.

Inspired from: https://wiki.archlinux.org/title/Advanced_Linux_Sound_Architecture

Audio_card_test.zip

The code:

#!/bin/bash
#
# RJP 14.2.2025 audio card test script
# Packages alsa and yad must be installed
#
#
aplay -l | awk -F \: '/,/{print $2}' | awk '{print $1}' | uniq > /tmp/adevice-full.txt
AUDIO=$(/tmp/adevice-full.txt)
choose=$(cat /tmp/adevice-full.txt | \
yad --list --text="Choose audio device" --title="Choose audio device" --height=500 --width=600 --center \
--column="")
--button=Exit:1
cat "$choose" 2> /tmp/audio2.txt
cat /tmp/audio2.txt | awk '{print $2}' > /tmp/audiodevice
cat /tmp/audiodevice | sed 's/^.//' > /tmp/audiodevice3
sed 's/.$//' /tmp/audiodevice3 > /tmp/audiodevice4
sed 's/.$//' /tmp/audiodevice4 > /tmp/audiodevice5
sed 's/.$//' /tmp/audiodevice5 > /tmp/audio.txt
#
#
#
yad --center --width=300 --height=100 --text-align=center --title="QUESTION" --text="Test selected card"
if [ $? = 0 ];
then
x-terminal-emulator -e "aplay -D plughw:CARD=$(cat /tmp/audio.txt) /usr/share/sounds/alsa/Noise.wav" & \
#
# Message if audio was running or not
#
sleep 0,5 && (ps -ef|grep -v grep|grep aplay >/dev/null && echo "If you heard noise, the card is the right. You can close this message" || echo "if you did not heard noise, you probably has the wrong audio device. You can close this message") > /tmp/message.txt
yad --center --width=700 --height=200 --text-align=center --title="RESULT" --text="INFO: $(cat /tmp/message.txt)"
#
fi
sleep 1
rm /tmp/audio2.txt /tmp/adevice.txt /tmp/audiodevice3 /tmp/audiodevice4 /tmp/audiodevice4 /tmp/audiodevice5 /tmp/audio.txt


———————————————–
Audio_card_test_FULL

Audio_card_test_FULL.zip

Audio Card Test with full options (all cards).

#!/bin/bash
#
# RJP 14.2.2025 audio card test script
# Packages alsa and yad must be installed
# 15.2.2025 Test with all options as all choises
#
aplay -L | grep :CARD > /tmp/adevice-full.txt
AUDIO=$(/tmp/adevice-full.txt)
choose=$(cat /tmp/adevice-full.txt | \
yad --list --text="Choose audio device" --title="Choose audio device" --height=500 --width=600 --center \
--column="")
--button=Exit:1
cat "$choose" 2> /tmp/audio2.txt
cat /tmp/audio2.txt | awk '{print $2}' > /tmp/audiodevice
cat /tmp/audiodevice | sed 's/^.//' > /tmp/audiodevice3
sed 's/.$//' /tmp/audiodevice3 > /tmp/audiodevice4
sed 's/.$//' /tmp/audiodevice4 > /tmp/audiodevice5
sed 's/.$//' /tmp/audiodevice5 > /tmp/audio.txt
#
#
#
yad --center --width=300 --height=100 --text-align=center --title="QUESTION" --text="Test selected card"
if [ $? = 0 ];
then
x-terminal-emulator -e "aplay -D $(cat /tmp/audio.txt) /usr/share/sounds/alsa/Noise.wav" & \
#
# Message if audio was running or not
#
sleep 0,5 && (ps -ef|grep -v grep|grep aplay >/dev/null && echo "If you heard noise, the card is the right. You can close this message" || echo "if you did not heard noise, you probably has the wrong audio device. You can close this message") > /tmp/message.txt
yad --center --width=700 --height=200 --text-align=center --title="RESULT" --text="INFO: $(cat /tmp/message.txt)"
#
fi
sleep 1
rm /tmp/audio2.txt /tmp/adevice.txt /tmp/audiodevice3 /tmp/audiodevice4 /tmp/audiodevice4 /tmp/audiodevice5 /tmp/audio.txt

###########################################
####### DEFAULT CARD CHANGER SCRIPT #########
###########################################

The safest way to edit /etc/asound.conf file is to use some editor. But if you want to live dangerously, you can use SET_DEFAULT_SOUNDCARD-final.

If you mess your audio, a default asound.conf file is in this package, so you can use it as a backup.

sudo cp asound.conf /etc/asound.conf

Using Mini-Control-Center you can make a speaker test and more other tests.

Set_Default_Soundcard.zip

#!/bin/bash
# RJP 18.2.2024 Default sound card changer
# Requires alsa-utils, libasound2-plugin-equal, alsa and yad
# 21.2.2025 Fixed version 3 (final version)
cp /etc/asound.conf /tmp/asound000.conf
sed '/defaults.pcm.card/ s/^#*//' /tmp/asound000.conf > /tmp/asound00.conf
sed '/defaults.ctl.card/ s/^#*//' /tmp/asound00.conf > /tmp/asound0.conf
#
CARD=`yad --center --width=500 --height=100 --text-align=center --title=$"Set Card number to the" --text="Set Card number to the" --entry --entry-label=BOX --entry-text=""`
if [ $? = 0 ];
then
x-terminal-emulator -e "sudo cp /etc/asound.conf /etc/asound.conf.bak"
sleep 0,1
/bin/bash -c "sed -i 's/defaults.pcm.card [0-9]\+/defaults.pcm.card $CARD /g' /tmp/asound0.conf "&& \
sleep 0,1
/bin/bash -c "sed -i 's/defaults.ctl.card [0-9]\+/defaults.ctl.card $CARD /g' /tmp/asound0.conf " && \
#
sed -i 87q /tmp/asound0.conf
x-terminal-emulator -e "sudo cp /tmp/asound0.conf /etc/asound.conf" && \
sleep 1
yad --center --width=300 --height=100 --text-align=center --title="ASOUND.CONF EDIDED" --text="DONE"
else exit 0
fi
#
# If you want to check set sound card, remove # in the front of the next line
# cat /etc/asound.conf | grep card > /tmp/card.txt && xdg-open /tmp/card.txt && \
rm /tmp/asound000.conf /tmp/asound00.conf /tmp/asound0.conf /tmp/asound2.conf /tmp/card.txt /tmp/asound.conf.txt /tmp/asound.conf

Read also: https://puolanka.info/goto/how-to-make-asoundrc-file/