← All projects

Acoustic Sound Recorder

Medium · ~1 hour · Any Pi with USB or I²S audio input

Turn a Pi into a continuous (or scheduled, or sound-triggered) audio capture rig. Useful for ambient field recording, bird and wildlife monitoring, room acoustic logging, sleep tracking, or building a dataset for downstream audio classification.

Storage adds up fast. 16-bit / 44.1 kHz mono WAV is ~5 MB per minute (~7 GB/day). Plan on either an external drive, periodic deletion, or recording in compressed FLAC/Opus. Numbers in the steps below assume mono recording — double everything for stereo.

You'll need

1. Confirm the mic is detected

Plug in the USB mic (or wire up the I²S board), boot, then list audio capture devices:

arecord -l

You should see something like:

card 1: Device [USB Audio Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Note the card and device numbers — you'll address the mic as plughw:1,0 (card 1, device 0).

2. Test a 5-second recording

arecord -D plughw:1,0 -f S16_LE -r 44100 -c 1 -d 5 test.wav
aplay test.wav

Flags explained: -f S16_LE = 16-bit signed little-endian PCM; -r 44100 = sample rate; -c 1 = mono; -d 5 = duration. If aplay can't reach a speaker, copy the WAV to your laptop and play it there.

Hearing nothing? Run alsamixer, press F6 to select your USB card, press F4 to switch to Capture view, and unmute (M) plus raise the gain. USB mics often boot muted.

3. Set up rolling capture

For continuous recording into hourly files (great for later review or classification):

mkdir -p ~/recordings
arecord -D plughw:1,0 -f S16_LE -r 44100 -c 1 \
  --max-file-time 3600 \
  --use-strftime ~/recordings/%Y-%m-%d_%H-%M-%S.wav

This writes one WAV per hour, named by start timestamp. Stops only when interrupted — wrap it in a systemd service so it survives reboots (see step 5).

4. Optional: trigger recording on sound

For wildlife or security applications, you usually don't want hours of silence. Install sox and let it gate recording on signal level:

sudo apt install sox
rec -c 1 -r 44100 ~/recordings/$(date +%Y%m%d_%H%M%S).wav \
  silence 1 0.1 1% 1 2.0 1%

The silence filter starts recording when the signal exceeds 1% RMS for 0.1s and stops after 2 seconds of silence below 1%. Tune the thresholds for your environment — bedrooms need lower than busy streets.

5. Run it as a service

Create /etc/systemd/system/sound-recorder.service:

[Unit]
Description=Continuous audio capture
After=sound.target

[Service]
Type=simple
User=pi
ExecStart=/usr/bin/arecord -D plughw:1,0 -f S16_LE -r 44100 -c 1 \
  --max-file-time 3600 \
  --use-strftime /home/pi/recordings/%%Y-%%m-%%d_%%H-%%M-%%S.wav
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

The doubled %% escapes percent signs for systemd. Enable and start:

sudo systemctl daemon-reload
sudo systemctl enable --now sound-recorder
sudo systemctl status sound-recorder

6. Compress to save space (optional)

Convert finished hourly WAVs to FLAC (lossless, ~50% smaller) or Opus (lossy, ~10× smaller) with a cron job:

# Every 5 minutes, compress any closed WAVs older than 10 minutes.
*/5 * * * * find /home/pi/recordings -name '*.wav' -mmin +10 \
  -exec flac --delete-input-file --silent {} \;

Swap flac for opusenc --bitrate 24 {} {}.opus && rm {} if size matters more than fidelity (good for speech, bird calls, ambient).

7. Optional: classify what you recorded

Two batteries-included options for tagging recordings:

Both produce CSV labels per file — store alongside the audio, then query with grep or import into SQLite for searchable archives.

Troubleshooting