How to record audio from terminal in macOS Mojave?

Solution 1:

They have restricted access to the microphone from the terminal by default after the update.

You need to go to System Preferences > Security & Privacy > Privacy > Microphone and tick the box for the terminal and it should all work again.

Solution 2:

If Terminal isn't showing up in the System Preferences list for microphone permissions and it hasn't requested permission (a problem on Mojave/Catalina), open it by:

open /System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal

Then run a program that uses the mic e.g.

sox -d -d 

(Note: You will need to install SoX. This specific command will let you hear your mic input. You could also use pyaudio, FFmpeg, ecasound etc.)

That should trigger it to request. If that didn't work try running the command on a different command line e.g. iTerm2. This is a problem and solution very similar to the one for Audacity on Catalina. I'm not sure what the exact cause is though.