I'm using a raspberry pi for a custom voice assistant I'm building. I need to mute and unmute the microphone for certain parts of the program I'm running. Is there a simple lx terminal command to do this? I'm using a voice hat from AIY projects if that makes any difference. I'm not using a usb mic.
3 Answers
Try amixer
:
amixer sset 'Capture' cap
amixer sset 'Capture' nocap
You may have to find out the control name for the microphone in your setup if you use additional hardware. amixer scontrols
will list the controls you have.
There's also pactl
command which should work on PulseAudio level. Identify the mic in the output of pactl list sources
and then mute / unmute the source by number
pactl set-source-mute 0 1 # mute source 0
pactl set-source-mute 0 0 # unmute source 0
-
please explain the "pactl" more, my rpi recognizes the microphone on pulseaudio. thanks for the info so far– UNKNOWNCommented Mar 31, 2021 at 0:45
-
If you are building voice assistant, instead of muting microphone. I suggest to disable / enable the wake word listener. If you are using MyCroft, then MyPrecise is the work word listener which you can disable and enable when required
I am not aware of any shell commands that is designed for it, but if we assume your microphone is connected via USB, you can disable and enable the specific USB port.
First check the path of your device via lsusb -t
.
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
To disable hub: echo '1-1.1' | sudo tee /sys/bus/usb/drivers/usb/unbind
. You can again enable it via binding it. The detailed discussion is available here.