I wanted a way to get audio to BirdNET-Go (https://github.com/tphakala/birdnet-go) from low-budget devices spread across my property. This script turns a Pi into an appliance for exactly that purpose. I found that the actual capture and stream function leaves plenty of headroom even on a Zero 2W, so since BirdNET-Go can really only tell me if the RTSP stream is up or down, I implemented a simple busybox function to publish a "health" overview page on port 8080. Eventually, I plan to migrate away from the static page generation and publish to MQTT or otherwise integrate into Home Assistant for monitoring the node(s).
- Raspberry Pi Zero 2W
- Micro-to-A USB adapter.
- $1 USB sound card
- $3 omnidirectional lav microphone.
- Standard Pi power supply.
- 3D printed case.
- MediaMTX running on a separate server alongside BirdNET-Go in Docker on OpenMediaVault.
- Captures audio from a USB sound card, encodes in AAC and publishes to an RTSP destination with FFMPEG.
- Optional: applies gain to audio before encoding.
- Optional: generates a static html system health page served on port 8080.
- Put birdfeeder-audio.service in /etc/systemd/system/
- Put birdfeeder-audio.service in /usr/local/bin/
- DEVICE: USB mic / sound card hardware ID (find via via arecord -l, mine tends to be 0,0)
- RATE: Audio capture frequency (set to 48khz as that's my sound card's native)
- BITRATE: Streaming bitrate, 128k seems to work just fine but this can be dropped down as needed, or increased with higher quality audio input.
- URL: RTSP publishing path
- THREAD_QUEUE_SIZE: Prevents loss of audio from spotty connections, good results at 4096.
- GAIN_DB: Birdnet will normalize levels in clips, but live audio was low. I constantly used gain in the UI. Applying 15db gain worked for me.
- LIMITER_LEVEL: This is just to prevent clipping, but realistically if this is utilized a lot, gain is too high.
- STATUS_ENABLE: 1 turns on this functionality, 0 disables it.
- STATUS_DIR: This is where we're writing the health information to periodically.
- STATUS_INTERVAL: This is how frequently we're updating the health data file.
- Basically any adjustments you make to the .sh, just reboot the Pi instead of restarting the service.
- systemctl status birdfeeder-audio.service should tell you what's going on if there are any errors.
I still need to evaluate power usage and heat tolerance to build a more rugged enclosure, or potentially even migrate away from the Pi Zero hardware. I also need to evaluate the audio quality with a better microphone setup (preferably not USB), but a bird or a cat literally stole my RODE mic a while back. I'm sure there's more.