Eu tenho tentado configurar meu microfone USB para alternar para o padrão e fazer o loopback automaticamente com o udev.
Minhas regras atuais são:
ACTION=="add", ATTR{idVendor}=="046d", ATTR{idProduct}=="0a03", GROUP=="audio" RUN+="/usr/bin/micplug"
ACTION=="remove", ENV{ID_MODEL}=="Logitech_USB_Microphone", RUN+="/usr/bin/micunplug"
O script do micplug é:
#!/bin/bash
echo "setting source mic" >> /home/wanderingconfused/test
pacmd set-default-source alsa_input.usb-Logitech_Logitech_USB_Microphone-00.analog-mono
echo "loopback mic" >> /home/wanderingconfused/test
pactl load-module module-loopback latency_msec=1 source=alsa_input.usb-Logitech_Logitech_USB_Microphone-00.analog-mono sink=alsa_output.pci-0000_00_14.2.analog-stereo
Que define o microfone como a fonte padrão e faz um loopback.
O script do micunplug é:
#!/bin/bash
echo "turn off loopback" >> /home/wanderingconfused/test
pactl unload-module $(pactl list short modules | awk '$2 == "module-loopback" { print $1 }' - )
echo "setting source webcam" >> /home/wanderingconfused/test
pacmd set-default-source alsa_input.usb-046d_081b_4B042590-02.analog-mono
O que desativa o loopback e retorna a fonte padrão para minha webcam.
Os scripts funcionam exatamente como planejados por conta própria. No entanto, quando o udev os executa, meu tudo ecoa no arquivo de teste, mas o pulseaudio ignora os comandos.
Eu estava pensando que tinha algo a ver com permissões, e é por isso que adicionei GROUP. Eu tentei alguns grupos e proprietários e tentei MODE =="0660", mas neste momento estou perplexo.
Editar 3/3/2017
Então agora meu / usr / bin / pulse_events_wrapper é:
#!/bin/bash
# Get UID of user running pulseaudio (uses the first if more than one)
PUID='ps -C pulseaudio -o ruid= | awk '{print $1}''
if [ ! -z "$PUID" ]; then
# environment variables to export
export PULSE_RUNTIME_PATH="/var/run/user/$PUID/pulse"
export HOME='getent passwd $PUID | cut -d: -f6'
if [ -x "$HOME/.pulse_events" ]; then
# Pass single command line arg to user script
nohup sudo -u "#$PUID" -E $HOME/.pulse_events $1 >/dev/null 2>&1 &
fi
fi
e o script home / .pulse_events é
!/bin/bash
case $1 in
micplug)
echo "setting source mic" >> /home/wanderingconfused/test
pacmd set-default-source alsa_input.usb-Logitech_Logitech_USB_Microphone-00.analog-mono >>/home/wanderingconfused/test 2>&1
echo "loopback mic" >> /home/wanderingconfused/test
pactl load-module module-loopback latency_msec=1 source=alsa_input.usb-Logitech_Logitech_USB_Microphone-00.analog-mono sink=alsa_output.pci-0000_00_14.2.analog-stereo$
;;
micunplug)
echo "turn off loopback" >> /home/wanderingconfused/test
pactl unload-module $(pactl list short modules | awk '$2 == "module-loopback" { print $1 }' - ) >>/home/wanderingconfused/test 2>&1
echo "setting source webcam" >> /home/wanderingconfused/test
pacmd set-default-source alsa_input.usb-046d_081b_4B042590-02.analog-mono >>/home/wanderingconfused/test 2>&1
;;
esac
Funciona, mas eu prefiro não colocar tudo isso em um arquivo. Eu tentei remover os ecos e rotear tudo para null, mas depois ele parou de funcionar.
Além disso, o microfone desconecta-se quando eu olho para o arquivo de teste:
setting source mic
loopback mic
68
turn off loopback
setting source webcam
turn off loopback
turn off loopback
You have to specify a module index or name
setting source webcam
You have to specify a module index or name
setting source webcam
Source alsa_input.usb-Logitech_Logitech_USB_Microphone-00.analog-mono does not exist.
70
Failure: No such entity
setting source mic
Source alsa_input.usb-Logitech_Logitech_USB_Microphone-00.analog-mono does not exist.
loopback mic
78
turn off loopback
turn off loopback
setting source webcam
You have to specify a module index or name
setting source webcam
setting source mic
Source alsa_input.usb-Logitech_Logitech_USB_Microphone-00.analog-mono does not exist.
loopback mic
80
turn off loopback
turn off loopback
setting source webcam
Failure: No such entity
setting source webcam
setting source mic
loopback mic
82
turn off loopback
turn off loopback
setting source webcam
You have to specify a module index or name
setting source webcam
setting source mic
Source alsa_input.usb-Logitech_Logitech_USB_Microphone-00.analog-mono does not exist.
loopback mic
84
turn off loopback
turn off loopback
setting source webcam
You have to specify a module index or name
setting source webcam
setting source mic
loopback mic
87
turn off loopback
setting source webcam
turn off loopback
You have to specify a module index or name
setting source webcam
Outra coisa estranha, apesar de dizer: "Fonte alsa_input.usb-Logitech_Logitech_USB_Microphone-00.analog-mono não existe." Ainda funciona.