Acoustic Sound Recorder
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.
You'll need
- Raspberry Pi 3, 4, 5, or Zero 2 W (any with USB)
- A microphone — pick one based on what you're recording:
- USB mic (Samson Go Mic, MOVO UM700, FIFINE K669): easiest, plug-and-play with ALSA
- USB audio interface + XLR mic: best quality, more expensive
- I²S MEMS mic (Adafruit SPH0645, INMP441): tiny, low-power, needs wiring to GPIO
- ReSpeaker 2-Mics HAT: stereo array, good for room recording and voice
- External USB drive or large SD card (32 GB+) if recording continuously
- Raspberry Pi OS Lite (64-bit recommended)
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.
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:
- BirdNET-Analyzer — identifies ~6000 bird species from short clips. Runs on a Pi 4/5 in roughly real time for short files.
- YAMNet (TensorFlow Lite) — general 521-class audio classifier (speech, music, animals, vehicles, etc.). Lighter than BirdNET but less specific.
Both produce CSV labels per file — store alongside the audio, then query with grep or import into SQLite for searchable archives.
Troubleshooting
- Recording stutters or has clicks: the USB bus is saturated. Move the mic to a different USB port (USB 2 ports often work better than USB 3 for audio on Pi 4/5), or reduce sample rate to 22050 Hz.
- "Device or resource busy": another process is holding the mic. Find it:
fuser -v /dev/snd/*and stop it before retrying. - Drive fills up unexpectedly: add a daily cleanup:
find ~/recordings -mtime +30 -delete(keeps 30 days). - Want remote access to recordings? Pair with the Cloudflare Tunnel tutorial to expose a small file-server on the Pi without opening router ports.