Skip to content

Instantly share code, notes, and snippets.

@Its4Nik
Created March 23, 2025 17:51
Show Gist options
  • Save Its4Nik/3b11b0c0fde1e84cd9ff7e9e78e0d678 to your computer and use it in GitHub Desktop.
Save Its4Nik/3b11b0c0fde1e84cd9ff7e9e78e0d678 to your computer and use it in GitHub Desktop.
A simple audio Diagnostic script for usage on Linux devices
#!/bin/bash
# Color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Initialize variables
declare -A STATUS
declare -A CONFLICTS
DIAGNOSIS=""
# Header
echo -e "\n${YELLOW}=== Audio Subsystem Diagnostic Tool ===${NC}\n"
# Function to add diagnosis messages
add_diagnosis() {
DIAGNOSIS+="$1\n"
}
# Check ALSA
check_alsa() {
echo -e "${YELLOW}[1/5] Checking ALSA...${NC}"
if command -v aplay &> /dev/null; then
echo -e "ALSA Utilities: ${GREEN}Installed${NC}"
STATUS["alsa"]=1
# Check sound devices
echo -e "\nPlayback Devices:"
if aplay -l | grep -q 'card'; then
aplay -l | grep 'card'
else
echo -e "${RED}No ALSA playback devices found!${NC}"
add_diagnosis "ALSA: No playback devices detected - check hardware/drivers"
fi
echo -e "\nRecording Devices:"
if arecord -l | grep -q 'card'; then
arecord -l | grep 'card'
else
echo -e "${RED}No ALSA recording devices found!${NC}"
add_diagnosis "ALSA: No recording devices detected"
fi
# Check kernel modules
echo -e "\nSound Modules:"
if lsmod | grep -q 'snd'; then
lsmod | grep 'snd_' | head -n5
else
echo -e "${RED}No sound modules loaded!${NC}"
add_diagnosis "ALSA: No kernel sound modules loaded"
fi
else
echo -e "ALSA Utilities: ${RED}Not Found${NC}"
STATUS["alsa"]=0
fi
echo
}
# Check PulseAudio
check_pulse() {
echo -e "${YELLOW}[2/5] Checking PulseAudio...${NC}"
if command -v pactl &> /dev/null; then
echo -e "PulseAudio: ${GREEN}Installed${NC}"
# Check if running
if pactl info | grep -q 'Server Name'; then
SERVER_NAME=$(pactl info | grep 'Server Name' | cut -d' ' -f3-)
if [[ "$SERVER_NAME" == *"PipeWire"* ]]; then
echo -e "Server: ${YELLOW}PipeWire (Pulse compat)${NC}"
STATUS["pulse_running"]=0
else
echo -e "Server: ${GREEN}PulseAudio${NC}"
STATUS["pulse_running"]=1
fi
else
echo -e "Status: ${RED}Not Running${NC}"
STATUS["pulse_running"]=0
fi
else
echo -e "PulseAudio: ${RED}Not Installed${NC}"
STATUS["pulse"]=0
fi
echo
}
# Check PipeWire
check_pipewire() {
echo -e "${YELLOW}[3/5] Checking PipeWire...${NC}"
if systemctl --user status pipewire.service &> /dev/null; then
echo -e "Status: ${GREEN}Running${NC}"
STATUS["pipewire_running"]=1
# Check if using PulseAudio compatibility
if pactl info | grep -q 'PipeWire'; then
echo -e "Compatibility: ${GREEN}PulseAudio → PipeWire${NC}"
STATUS["pipewire_pulse"]=1
else
echo -e "Compatibility: ${YELLOW}Standalone PipeWire${NC}"
STATUS["pipewire_pulse"]=0
fi
else
echo -e "Status: ${RED}Not Running${NC}"
STATUS["pipewire_running"]=0
fi
echo
}
# Check user groups
check_groups() {
echo -e "${YELLOW}[4/5] Checking User Permissions...${NC}"
groups | grep -q 'audio' && echo -e "audio group: ${GREEN}Member${NC}" || {
echo -e "audio group: ${RED}Not Member${NC}"
add_diagnosis "Permissions: User not in 'audio' group"
}
groups | grep -q 'pulse' && echo -e "pulse group: ${GREEN}Member${NC}" || echo -e "pulse group: ${YELLOW}Not Member${NC}"
echo
}
# Check conflicts
check_conflicts() {
echo -e "${YELLOW}[5/5] Checking Conflicts...${NC}"
# Pulse vs PipeWire
if [[ ${STATUS["pipewire_running"]} -eq 1 && ${STATUS["pulse_running"]} -eq 1 ]]; then
echo -e "${RED}Conflict: Both PipeWire and PulseAudio running!${NC}"
CONFLICTS["pipe-pulse"]=1
add_diagnosis "Conflict: Both PipeWire and PulseAudio running - may cause issues"
fi
# Check for parallel installations
if command -v pulseaudio &> /dev/null && command -v pipewire &> /dev/null; then
echo -e "${YELLOW}Warning: Both PulseAudio and PipeWire installed${NC}"
CONFLICTS["install"]=1
fi
# Check for pipewire-pulse status
if [[ ${STATUS["pipewire_running"]} -eq 1 && ${STATUS["pipewire_pulse"]} -eq 0 ]]; then
echo -e "${YELLOW}Warning: PipeWire running without Pulse compatibility${NC}"
add_diagnosis "Compatibility: PipeWire running without PulseAudio support"
fi
echo
}
# Run checks
check_alsa
check_pulse
check_pipewire
check_groups
check_conflicts
# Generate report
echo -e "\n${YELLOW}=== Diagnostic Summary ===${NC}"
if [[ -z "$DIAGNOSIS" ]]; then
echo -e "${GREEN}No major issues detected!${NC}"
else
echo -e "${RED}Potential issues found:${NC}"
echo -e "$DIAGNOSIS"
fi
echo -e "\n${YELLOW}Troubleshooting Tips:${NC}"
echo "- If no devices found, check kernel modules with 'alsamixer'"
echo "- Ensure only one audio server (Pulse/PipeWire) is running"
echo "- Restart audio with: systemctl --user restart pipewire pulseaudio"
echo "- Check audio group membership: usermod -aG audio \$USER"
echo -e "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment