From 38423f4bff76f7188785aed351642fed658b2058 Mon Sep 17 00:00:00 2001 From: alexbelgium Date: Sat, 15 Aug 2026 07:57:39 +0200 Subject: [PATCH] fix(birdnet-pi-zach): make ALSA_CARD actually select the microphone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Port of the birdnet-pi fix in #2972. birdnet-pi-zach is a sibling wrapper around the zach7036 BirdNET-Pi fork, and carried the identical defect: 99-run.sh was byte-identical to birdnet-pi's before the fix, and 01-structure.sh still is, so this is an exact port rather than an adaptation — verified by diffing the result against the fixed file (identical). ALSA_CARD was copied straight into REC_CARD, but BirdNET-Pi passes REC_CARD to `arecord -D` and `ffmpeg -f alsa -i`, which want an ALSA PCM name. A card index like `1` became "Unknown PCM 1" and nothing recorded. It is now converted to plughw:CARD=,DEV=0, with values that already are PCM names passed through. The sed also clobbered the symlink: 01-structure.sh links $HOME/BirdNET-Pi/birdnet.conf -> /config/birdnet.conf (confirmed present in this add-on, same CONFIG_FILES loop), and `sed -i` replaces a symlink with a regular file, detaching it from the file the WebUI writes to. Now edits /config/birdnet.conf with --follow-symlinks. version 2026.07.10.2 -> 2026.08.15, matching the new CHANGELOG heading. This add-on's updater.json has an empty upstream_version and is paused, so there is no upstream prefix to derive a patch counter from; the family's date convention governs instead. Without the bump Supervisor would never offer the rebuild and the fix would ship inert. Shellcheck: clean apart from two pre-existing SC2015 warnings in the unrelated AUDIO_GID block, which are present on master and left alone. Co-Authored-By: Claude Opus 5 --- birdnet-pi-zach/CHANGELOG.md | 3 +++ birdnet-pi-zach/config.yaml | 2 +- .../rootfs/etc/cont-init.d/99-run.sh | 25 ++++++++++++++----- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/birdnet-pi-zach/CHANGELOG.md b/birdnet-pi-zach/CHANGELOG.md index 8cfe01fbdc..75f6f1235a 100644 --- a/birdnet-pi-zach/CHANGELOG.md +++ b/birdnet-pi-zach/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2026.08.15 (15-08-2026) +- Fix: `ALSA_CARD` now really selects the microphone. Its value was copied as-is into `REC_CARD`, but BirdNET-Pi hands `REC_CARD` to `arecord -D` / `ffmpeg -f alsa -i`, which expect an ALSA PCM name: a card index such as `1` gave `Unknown PCM 1` and no recording at all. It is now converted to `plughw:CARD=,DEV=0`, while a value that already is a PCM name (`dsnoop:CARD=Audio,DEV=0`, `default`, `null`, `pulse`, `pipewire`, ...) is used as provided +- Fix: writing `REC_CARD` no longer detaches `birdnet.conf` from `/config`. `sed -i` replaced the `$HOME/BirdNET-Pi/birdnet.conf` symlink with a regular file, so later edits from the WebUI went to a different file than the one the add-on had written; it now edits `/config/birdnet.conf` with `--follow-symlinks` ## 2026.07.10-2 (10-07-2026) - Minor bugs fixed ## 2026.07.10 (10-07-2026) diff --git a/birdnet-pi-zach/config.yaml b/birdnet-pi-zach/config.yaml index 401f3cf952..e87b2add01 100644 --- a/birdnet-pi-zach/config.yaml +++ b/birdnet-pi-zach/config.yaml @@ -116,5 +116,5 @@ tmpfs: true udev: true url: https://github.com/alexbelgium/hassio-addons/tree/master/birdnet-pi-zach usb: true -version: 2026.07.10.2 +version: 2026.08.15 video: true diff --git a/birdnet-pi-zach/rootfs/etc/cont-init.d/99-run.sh b/birdnet-pi-zach/rootfs/etc/cont-init.d/99-run.sh index 85c69008c8..d59313ab41 100755 --- a/birdnet-pi-zach/rootfs/etc/cont-init.d/99-run.sh +++ b/birdnet-pi-zach/rootfs/etc/cont-init.d/99-run.sh @@ -66,12 +66,25 @@ fi || true # Use ALSA CARD defined in add-on options if available if [ -n "${ALSA_CARD:-}" ]; then - bashio::log.warning "ALSA_CARD is defined, the birdnet.conf is adapt to use device $ALSA_CARD" - for file in "$HOME"/BirdNET-Pi/birdnet.conf /config/birdnet.conf; do - if [ -f "$file" ]; then - sed -i "/^REC_CARD/c\REC_CARD=$ALSA_CARD" "$file" - fi - done + # REC_CARD is passed as-is to "arecord -D" (scripts/birdnet_recording.sh) and to + # "ffmpeg -f alsa -i" (scripts/livestream.sh), so it must be an ALSA PCM name. + # ALSA_CARD holds a card index (1) or a card id (Audio), which are not PCM names: + # writing them as-is gives "Unknown PCM 1" and no recording at all. Build a PCM + # name from them, and pass through a value that already is one (plughw:...). + if [[ "$ALSA_CARD" == *:* ]] || [[ "$ALSA_CARD" =~ ^(default|null|pulse|pipewire)$ ]]; then + REC_CARD="$ALSA_CARD" + else + REC_CARD="plughw:CARD=${ALSA_CARD},DEV=0" + fi + bashio::log.warning "ALSA_CARD is defined, the birdnet.conf is adapted to use device $REC_CARD" + # --follow-symlinks : $HOME/BirdNET-Pi/birdnet.conf is a symlink to /config/birdnet.conf + # (01-structure.sh), and sed -i would replace it with a regular file, detaching it from + # the file the WebUI writes to. Only /config/birdnet.conf is updated directly, since the + # home-path symlink is writable by the pi/caddy user and could be repointed before this + # root-run script gets to it. + if [ -f /config/birdnet.conf ]; then + sed -i --follow-symlinks "/^REC_CARD/c\REC_CARD=$REC_CARD" /config/birdnet.conf + fi fi # Define permissions for audio