
SoX: How to Record Audio
Updated
Learn how to record audio from your microphone using SoX

Before we start, make sure you have SoX installed on your computer and a microphone ready. Your Mac's built-in one works fine. On a Mac, you can install SoX with Homebrew, and the rec command comes with it:
brew install sox
Record from the Microphone
First, open your terminal and navigate to the folder where you want to save your recording using cd. To record from your default microphone, run rec output.wav. It keeps recording until you press control + C. To record in mono and stop by itself after five seconds, run this command:
rec -c 1 output.wav trim 0 5
Just remember to replace output.wav with the name you want for your recording. The -c 1 flag records a single channel, and trim 0 5 starts at 0 seconds and stops after 5 seconds.
Don't worry if macOS asks whether Terminal can use the microphone the first time. Just allow it. While it records, SoX prints a live level meter, and when it's finished it prints Done.
To make sure everything worked, run soxi -d output.wav. It should print 00:00:05.00.
If you want to stop a recording earlier, just press control + C. SoX still saves everything it recorded so far.
