Using sox to record audio on OS X

I wanted to record a talk this week so I took my MacBook Pro laptop with me to the auditorium where the talk was being held. I normally use the QuickTime Player to record audio in such cases. But this time when I attempted to use the QuickTime Player, it wouldn't actually start recording. The presenters had started talking when I attempted to begin recording their presentation, so I opted to install Sound eXchange (SoX), which provides a command-line interface (CLI) for recording and editing audio on a variety of operating systems, including Microsoft Windows, Linux, and OS X. Since I had previously installed Homebrew on OS X on the system, I opened a Terminal window and used it to install SoX.





$ brew install sox
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
brew-php-switcher          fortio                     libbitcoin-protocol
eccodes                    goreleaser                 nifi-registry
fork-cleaner               kakoune                    wireguard-go
==> Updated Formulae
poppler                   gst-plugins-bad            pdftoedn
ace                        gst-plugins-base           pdftoipe
activemq                   gst-plugins-good           pdnsrec
agedu                      gst-plugins-ugly           pdsh
ammonite-repl              gst-python                 pegtl
amqp-cpp                   gst-rtsp-server            percona-toolkit
angular-cli                gst-validate               perkeep
annie                      gstreamer                  petsc
ansible                    gtksourceview@4            pgloader
apibuilder-cli             gx                         pgroonga
aptly                      gx-go                      pidgin
arangodb                   heroku                     pilosa
archey                     hesiod                     pipenv
aria2                      hopenpgp-tools             plantuml
armadillo                  icarus-verilog             plowshare
artifactory                imagemagick                postgresql
aws-sdk-cpp                imagemagick@6              postgresql@9.4
awscli                     inetutils                  postgresql@9.5
azure-cli                  infer                      postgresql@9.6
babeld                     ipfs                       postgrest
babl                       ipython                    pound
bcal                       ipython@5                  pre-commit
bettercap                  iso-codes                  presto
binaryen                   ispc                       proguard
bind                       jenkins                    proxytunnel
bitrise                    jfrog-cli-go               psqlodbc
bmake                      jhiccup                    pumba
byacc                      jhipster                   purescript
caddy                      joplin                     qcachegrind
cake                       jsonpp                     qjackctl
calicoctl                  keepassc                   qpm
cargo-completion           kitchen-sync               qt
carrot2                    knot                       raine
cask                       kompose                    raylib
cfitsio                    kubeless                   redshift
cfssl                      kubernetes-cli             reminiscence
cglm                       kubernetes-helm            restic
cimg                       lastpass-cli               restview
citus                      launch4j                   rhino
clang-format               libbi                      rocksdb
clojure                    libbitcoin-client          root
cmake                      libbitcoin-explorer        rsyslog
cockroach                  libbitcoin-server          s-nail
coffeescript               libgphoto2                 sagittarius-scheme
consul                     libidn                     schismtracker
convox                     libidn2                    shfmt
coreos-ct                  libphonenumber             siril
cppcms                     libpq                      skaffold
cromwell                   libpqxx                    skafos
curl                       libqalculate               skipfish
dartsim                    librealsense               snakemake
dash                       libswiften                 snownews
dbxml                      libu2f-host                solr
dcd                        libxlsxwriter              sonar-scanner
debianutils                libxo                      sops
dependency-check           links                      source-to-image
dhall-json                 logtalk                    spades
diamond                    loudmouth                  spdlog
diff-pdf                   lua                        spigot
diffoscope                 lxc                        spring-roo
dlib                       mariadb                    srtp
dnscrypt-proxy             maxwell                    stella
docfx                      mcabber                    stubby
doitlive                   mercurial                  stunnel
dscanner                   meson                      sundials
dspdfviewer                metabase                   swiftformat
dxpy                       micropython                synfig
e2fsprogs                  mikutter                   telegraf
elektra                    mill                       tepl
emscripten                 mitmproxy                  texmath
ethereum                   mlt                        thefuck
faas-cli                   monero                     tile38
fabio                      mongo-c-driver             tippecanoe
fabric                     mongodb                    todoman
fdroidserver               mongodb@3.2                tor
feh                        mpc                        traefik
firebase-cli               mpd                        twarc
fluent-bit                 msgpack                    txr
fmt                        mupdf                      uhd
fn                         mupdf-tools                uncrustify
folly                      mutt                       unrar
fq                         n                          vala
freediameter               nano                       vegeta
fribidi                    neofetch                   vim
fstrm                      neomutt                    vte3
gandi.cli                  node-build                 vtk
gauge                      node@8                     watch
gdal                       nsd                        webpack
gegl                       nss                        whois
geoserver                  open-mpi                   winetricks
get_iplayer                opensc                     wireguard-tools
getdns                     osm2pgrouting              wireshark
git-ftp                    osquery                    wtf
git-lfs                    osrm-backend               x265
gitlab-runner              pam-u2f                    xonsh
glib-networking            pandoc                     xqilla
gnome-builder              paps                       xsv
goenv                      parallel                   you-get
googler                    pari                       youtube-dl
grafana                    passenger                  z3
grpc                       pcb                        zabbix
gst-editing-services       pdal                       zopfli
gst-libav                  pdfgrep                    zsh-autosuggestions
==> Renamed Formulae
latexila -> gnome-latex

==> Installing dependencies for sox: flac, lame, libogg, libvorbis, mad
==> Installing sox dependency: flac
==> Downloading https://homebrew.bintray.com/bottles/flac-1.3.2.el_capitan.bottl
######################################################################## 100.0%
==> Pouring flac-1.3.2.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/flac/1.3.2: 53 files, 1.8MB
==> Installing sox dependency: lame
==> Downloading https://homebrew.bintray.com/bottles/lame-3.100.el_capitan.bottl
######################################################################## 100.0%
==> Pouring lame-3.100.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/lame/3.100: 27 files, 2.1MB
==> Installing sox dependency: libogg
==> Downloading https://homebrew.bintray.com/bottles/libogg-1.3.3.el_capitan.bot
######################################################################## 100.0%
==> /Pouring libogg-1.3.3.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/libogg/1.3.3: 97 files, 460.7KB
==> /Installing sox dependency: libvorbis
==> /Downloading https://homebrew.bintray.com/bottles/libvorbis-1.3.6.el_capitan.
######################################################################## 100.0%
==> /Pouring libvorbis-1.3.6.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/libvorbis/1.3.6: 157 files, 2.3MB
==> /Installing sox dependency: mad
==> /Downloading https://homebrew.bintray.com/bottles/mad-0.15.1b.el_capitan.bott
######################################################################## 100.0%
==> /Pouring mad-0.15.1b.el_capitan.bottle.1.tar.gz
🍺  /usr/local/Cellar/mad/0.15.1b: 12 files, 325.2KB
==> /Installing sox
==> /Downloading https://homebrew.bintray.com/bottles/sox-14.4.2_1.el_capitan.bot
######################################################################## 100.0%
==> /Pouring sox-14.4.2_1.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/sox/14.4.2_1: 23 files, 1.8MB
$

I was then able to record the talk to a WAV file using sox -d film.wav. I hit the control-c keys to terminate the recording. The -d option tells SoX to use the default audio device. The filename that follows it is the output file name. SoX can also record to an MP3 file.

Save on a Computer: Run Windows, Mac, and Linux with VirtualBox
Save on a Computer: Run Windows,
Mac, and Linux with VirtualBox
1x1 px

$ sox -d film.wav

Input File     : 'default' (coreaudio)
Channels       : 2
Sample Rate    : 44100
Precision      : 32-bit
Sample Encoding: 32-bit Signed Integer PCM

In:0.00% 01:08:41.38 [00:00:00.00] Out:182M  [   -==|==-   ]        Clip:1.24k^C
sox WARN sox: `coreaudio' input clipped 1238 samples
Aborted.
$ ls -lh film.wav
-rw-r--r--  1 jasmith1  1286109195   1.4G May 23 12:12 film.wav
$

I was then able to listen to the WAV output file with iTunes or using the sox play command, i.e., play film.wav. On OS X systems, you can also use the afplay command to listen to audio files. The volume was much louder when I used the play command to listen to the file than it was when I used iTunes.

Udemy Generic Category (English)120x600




$ play film.wav

film.wav:

 File Size: 1.45G     Bit Rate: 2.82M
  Encoding: Signed PCM    
  Channels: 2 @ 32-bit   
Samplerate: 44100Hz      
Replaygain: off         
  Duration: 01:08:41.36  

In:0.38% 00:00:15.60 [01:08:25.75] Out:688k  [      |      ]        Clip:16   

You can see the options for the sox command using sox --help.

$ sox --help
sox:      SoX v

Usage summary: [gopts] [[fopts] infile]... [fopts] outfile [effect [effopt]]...

SPECIAL FILENAMES (infile, outfile):
-                        Pipe/redirect input/output (stdin/stdout); may need -t
-d, --default-device     Use the default audio device (where available)
-n, --null               Use the `null' file handler; e.g. with synth effect
-p, --sox-pipe           Alias for `-t sox -'

SPECIAL FILENAMES (infile only):
"|program [options] ..." Pipe input from external program (where supported)
http://server/file       Use the given URL as input file (where supported)

GLOBAL OPTIONS (gopts) (can be specified at any point before the first effect):
--buffer BYTES           Set the size of all processing buffers (default 8192)
--clobber                Don't prompt to overwrite output file (default)
--combine concatenate    Concatenate all input files (default for sox, rec)
--combine sequence       Sequence all input files (default for play)
-D, --no-dither          Don't dither automatically
--dft-min NUM            Minimum size (log2) for DFT processing (default 10)
--effects-file FILENAME  File containing effects and options
-G, --guard              Use temporary files to guard against clipping
-h, --help               Display version number and usage information
--help-effect NAME       Show usage of effect NAME, or NAME=all for all
--help-format NAME       Show info on format NAME, or NAME=all for all
--i, --info              Behave as soxi(1)
--input-buffer BYTES     Override the input buffer size (default: as --buffer)
--no-clobber             Prompt to overwrite output file
-m, --combine mix        Mix multiple input files (instead of concatenating)
--combine mix-power      Mix to equal power (instead of concatenating)
-M, --combine merge      Merge multiple input files (instead of concatenating)
--norm                   Guard (see --guard) & normalise
--play-rate-arg ARG      Default `rate' argument for auto-resample with `play'
--plot gnuplot|octave    Generate script to plot response of filter effect
-q, --no-show-progress   Run in quiet mode; opposite of -S
--replay-gain track|album|off  Default: off (sox, rec), track (play)
-R                       Use default random numbers (same on each run of SoX)
-S, --show-progress      Display progress while processing audio data
--single-threaded        Disable parallel effects channels processing
--temp DIRECTORY         Specify the directory to use for temporary files
-T, --combine multiply   Multiply samples of corresponding channels from all
                         input files (instead of concatenating)
--version                Display version number of SoX and exit
-V[LEVEL]                Increment or set verbosity level (default 2); levels:
                           1: failure messages
                           2: warnings
                           3: details of processing
                           4-6: increasing levels of debug messages
FORMAT OPTIONS (fopts):
Input file format options need only be supplied for files that are headerless.
Output files will have the same format as the input file where possible and not
overridden by any of various means including providing output format options.

-v|--volume FACTOR       Input file volume adjustment factor (real number)
--ignore-length          Ignore input file length given in header; read to EOF
-t|--type FILETYPE       File type of audio
-e|--encoding ENCODING   Set encoding (ENCODING may be one of signed-integer,
                         unsigned-integer, floating-point, mu-law, a-law,
                         ima-adpcm, ms-adpcm, gsm-full-rate)
-b|--bits BITS           Encoded sample size in bits
-N|--reverse-nibbles     Encoded nibble-order
-X|--reverse-bits        Encoded bit-order
--endian little|big|swap Encoded byte-order; swap means opposite to default
-L/-B/-x                 Short options for the above
-c|--channels CHANNELS   Number of channels of audio data; e.g. 2 = stereo
-r|--rate RATE           Sample rate of audio
-C|--compression FACTOR  Compression factor for output format
--add-comment TEXT       Append output file comment
--comment TEXT           Specify comment text for the output file
--comment-file FILENAME  File containing comment text for the output file
--no-glob                Don't `glob' wildcard match the following filename

AUDIO FILE FORMATS: 8svx aif aifc aiff aiffc al amb au avr cdda cdr cvs cvsd cvu da
t dvms f32 f4 f64 f8 flac fssd gsm gsrt hcom htk ima ircam la lpc lpc10 lu maud mp2
 mp3 nist ogg prc raw s1 s16 s2 s24 s3 s32 s4 s8 sb sf sl sln smp snd sndr sndt sou
 sox sph sw txw u1 u16 u2 u24 u3 u32 u4 u8 ub ul uw vms voc vorbis vox wav wavpcm w
ve xa
PLAYLIST FORMATS: m3u pls
AUDIO DEVICE DRIVERS: coreaudio

EFFECTS: allpass band bandpass bandreject bass bend biquad chorus channels compand 
contrast dcshift deemph delay dither divide+ downsample earwax echo echos equalizer
 fade fir firfit+ flanger gain highpass hilbert input# loudness lowpass mcompand no
iseprof noisered norm oops output# overdrive pad phaser pitch rate remix repeat rev
erb reverse riaa silence sinc spectrogram speed splice stat stats stretch swap synt
h tempo treble tremolo trim upsample vad vol
  * Deprecated effect    + Experimental effect    # LibSoX-only effect
EFFECT OPTIONS (effopts): effect dependent; see --help-effect
$

Related articles:

  1. Recording audio on a Mac OS X system with QuickTime Player
  2. Installing Homebrew on Mac OS X
  3. Installing MTR on an OS X system
  4. BREW
  5. Audio File Play - afplay
  6. afconvert
  7. Obtaining info on an audio file with afinfo