Repository navigation
Digitally silent recordings: PulseAudio is started even for direct ALSA devices (and two neighbours of that bug) #654
Yannick158
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Posting this as a discussion as well as a PR, because it is the kind of thing
you only find by accident, and the symptom gives you nothing to search for.
The symptom
Recordings are digitally silent. Not quiet — silent: WAV files of the
right length and the right size, appearing at the normal rate, amplitude
exactly
0.000000. The service isactive, the disk fills up, nothing islogged, and BirdNET simply reports no detections.
Check it on your own station:
Maximum amplitude: 0.000000is a dead giveaway. Real room noise sitsaround 0.001–0.01.
The cause
scripts/birdnet_recording.shstarts PulseAudio unconditionally beforearecord:If your
REC_CARDis a direct ALSA device —plughw:…,hw:…,dsnoop:…,or a custom PCM from
/etc/asound.conf— PulseAudio opens the card first andarecordgets a device that is already taken. On a headless install itcannot work even in principle: with no session bus there is nowhere for
PulseAudio to hand the stream on.
The fix
Start PulseAudio only for devices that actually go through it:
The empty case is deliberate: with no
REC_CARD,arecordruns without-Dand uses the ALSA default, which on a desktop install is PulseAudio. Those
setups keep working exactly as before. Only the case that is currently broken
changes.
I have this open as #653 if a maintainer wants to take it. Until then the
edit above is three lines in one file, and it survives until the next update
overwrites it.
Worth knowing: the AvianVisitors fork already does this
Twarner491/AvianVisitors
arrived at the same guard independently and ships it today:
Two people hitting the same wall and writing the same four lines is
reasonable evidence that it belongs upstream.
Two neighbours of this bug
While chasing it I hit two more things that produce "no detections" with no
error. Both are configuration rather than code:
Card numbers move across reboots. A USB microphone that was
card 3cancome back as
card 1, andREC_CARD="plughw:3,0"then points at nothing.The unit fails on every start and sits in
activating, so it never shows asfailed— easy to miss for weeks. Use the stable name instead:The live stream and the analysis cannot both hold the microphone, because
both open
$REC_CARDand most USB capture devices allow one client. Theusual advice is to disable
livestream.service. You do not have to — ALSA'sdsnoopsplits one capture stream between several readers. The importantdetail, which cost me an evening: put a
plugin front of the dsnoop PCM andpoint
REC_CARDat that, not at the dsnoop device directly. Without theplugwrapper, a client asking for a rate or format the slave does notprovide fails to open — which is exactly what happens to ffmpeg while
arecordkeeps working fine.Then
REC_CARD="birdmic", and both services run off the same microphone.Two readers at once proves it:
arecord -D birdmic -d 3 -f S16_LE -r 48000 /tmp/a.wav & arecord -D birdmic -d 3 -f S16_LE -r 48000 /tmp/b.wavAll three are written up as a docs page in a PR on the AvianVisitors side;
happy to open the same here if that is wanted.
Running on a Pi 4, Bookworm, headless, USB mic, since August — about 10 000
detections through a dsnoop PCM with both services live.
All reactions