Last active
September 3, 2024 05:18
-
-
Save Sudo-Ivan/8b649fa5caeff46d86bd5c094e20e3a8 to your computer and use it in GitHub Desktop.
Linux Audio Sink Script
This file contains hidden or 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 | |
# Colors for output | |
GREEN='\033[0;32m' | |
RED='\033[0;31m' | |
NC='\033[0m' | |
# Check command existence | |
command_exists() { | |
command -v "$1" >/dev/null 2>&1 | |
} | |
# Prompt user for sink name | |
read -p "Enter the desired name for the audio sink: " SINK_NAME | |
if [ -z "$SINK_NAME" ]; then | |
echo -e "${RED}Sink name cannot be empty. Exiting.${NC}" | |
exit 1 | |
fi | |
echo -e "${GREEN}Checking for audio system...${NC}" | |
# Determine and configure based on the available audio system | |
if command_exists pactl info; then | |
echo -e "${GREEN}PipeWire detected.${NC}" | |
echo -e "${GREEN}Creating virtual sink and remapping source for PipeWire...${NC}" | |
pactl load-module module-null-sink sink_name=${SINK_NAME} \ | |
sink_properties=device.description=${SINK_NAME} | |
echo -e "${GREEN}Virtual sink '${SINK_NAME}' and remapped source created for PipeWire.${NC}" | |
elif command_exists pacmd info; then | |
echo -e "${GREEN}PulseAudio detected.${NC}" | |
echo -e "${GREEN}Creating virtual sink for PulseAudio...${NC}" | |
if pacmd load-module module-null-sink sink_name=${SINK_NAME} && \ | |
pacmd update-sink-proplist ${SINK_NAME} device.description=${SINK_NAME}; then | |
echo -e "${GREEN}Adding loopback to virtual sink for PulseAudio...${NC}" | |
if pacmd load-module module-loopback sink=${SINK_NAME}; then | |
echo -e "${GREEN}Virtual sink '${SINK_NAME}' created for PulseAudio.${NC}" | |
else | |
echo -e "${RED}Failed to create loopback module.${NC}" | |
exit 1 | |
fi | |
else | |
echo -e "${RED}Failed to create virtual sink.${NC}" | |
exit 1 | |
fi | |
else | |
echo -e "${RED}No compatible audio system detected. Please ensure you have PulseAudio or PipeWire installed.${NC}" | |
exit 1 | |
fi | |
echo -e "${GREEN}Setup Complete!${NC}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment