Skip to content

Instantly share code, notes, and snippets.

@HonbraDev
Last active July 14, 2021 16:17
Show Gist options
  • Save HonbraDev/7aef7ce727716963eca0c3919bb4beec to your computer and use it in GitHub Desktop.
Save HonbraDev/7aef7ce727716963eca0c3919bb4beec to your computer and use it in GitHub Desktop.
PulseAudio virtual microphone sink

Virtmic

A simple PulseAudio virtual microphone sink manager / VB Cable alternative

Installation

curl -s https://gist.githubusercontent.com/HonbraDev/7aef7ce727716963eca0c3919bb4beec/raw/virtmic.sh?$(date +%s) | sudo tee /usr/bin/virtmic > /dev/null; sudo chmod +x /usr/bin/virtmic

Then check the executable with sudoedit /usr/bin/virtmic

Help() {
echo "Available arguments:
add <deviceid>
remove <deviceid>
list"
}
while getopts ":h" option; do
case $option in
h)
Help
exit
;;
esac
done
if [ "$1" == "" ]; then
Help
exit
fi
if [ "$1" == "add" ]; then
if [ "$2" == "" ]; then
echo Please enter the device id.
exit
fi
echo Adding virtual device with id $2
pactl load-module module-null-sink sink_name=virtmic$2 \
sink_properties=device.description=Virtual_speaker_$2 >/dev/null
pactl load-module module-remap-source \
master=virtmic$2.monitor source_name=virtmic$2 \
source_properties=device.description=Virtual_microphone_$2 >/dev/null
exit
fi
if [ "$1" == "remove" ]; then
if [ "$2" == "" ]; then
echo Please enter the device id.
exit
fi
echo Removing virtual device with id $2
pactl list short modules | grep "sink_name=virtmic$2" | cut -f1 | xargs -L1 pactl unload-module
fi
if [ "$1" == "list" ]; then
echo Active virtual devices:
pactl list short modules | grep "sink_name=" | cut -f3 | cut -d ' ' -f1 | cut -c 18-
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment