2

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.

1
  • if I have to start a bounty for this please upvote this question so I can continue to ask questions in the future
    – UNKNOWN
    Commented Mar 28, 2021 at 12:39

3 Answers 3

2
+50

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
2
  • please explain the "pactl" more, my rpi recognizes the microphone on pulseaudio. thanks for the info so far
    – UNKNOWN
    Commented Mar 31, 2021 at 0:45
  • You can also do amixer sset Capture toggle.
    – jbrock
    Commented Jul 30, 2023 at 18:00
2

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

2
  • That is not how my recognizer works, I specifically need the mic muted
    – UNKNOWN
    Commented Mar 31, 2021 at 0:46
  • Try amixer set Mic nocap to mute & amixer set Mic cap to unmute
    – ismail
    Commented Apr 1, 2021 at 6:53
0

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.

2
  • this is not a usb device it is built on a Aiy kit
    – UNKNOWN
    Commented Mar 27, 2021 at 23:16
  • sorry for not mentioning that
    – UNKNOWN
    Commented Mar 27, 2021 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.