mcguirepr89 / BirdNET-Pi

A realtime acoustic bird classification system for the Raspberry Pi 4B, 3B+, and 0W2 built on the TFLite version of BirdNET.
Other
1.28k stars 137 forks source link

Losing Microphone Input After Crash / Reboots #1036

Open bonehead1996 opened 11 months ago

bonehead1996 commented 11 months ago

Describe the bug When rebooting the Pi (using the web interface reboot button and/or a hardware power switch) BirdNET will occasionally come back up but be detecting no sound input leading to essentially blank spectrograms with some interference present. No detections are made either owing to the lack of input.

Restarting the Pi, or starting and stopping individual services does not remedy this issue, and neither does unplugging and re-plugging the USB microphone. The only thing that fixes the issue is re-flashing the SD card with a new image and starting from fresh.

To Reproduce I can't reliably reproduce this but it has happened probably 6 times in about 30 reboots of the Pi, which is unhelpful as I'm trying to run a portable field-deployable instance of BirdNET.

Expected behavior Safely rebooting the Pi shouldn't cause loss of microphone / sound input

Screenshots

Blank Spectrogram after reboot failure :

image

Your build RPi Zero 2 W with "MOVO" generic USB microphone.

Code or log snippets

Attempting to restart the live audio stream produces the following:

 livestream.service - BirdNET-Pi Live Stream
     Loaded: loaded (/home/Bonehead1996/BirdNET-Pi/templates/livestream.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2023-10-03 08:31:12 BST; 6s ago
   Main PID: 522943 (bash)
      Tasks: 2 (limit: 191)
        CPU: 921ms
     CGroup: /system.slice/livestream.service
             ├─522943 bash /usr/local/bin/livestream.sh
             └─522945 ffmpeg -nostdin -loglevel error -ac 2 -f alsa -i default -acodec libmp3lame -b:a 320k -ac 2 -content_type audio/mpeg -f mp3 icecast://source:birdnetpi@localhost:8000/stream -re

Oct 03 08:31:12 BirdnetPi systemd[1]: livestream.service: Consumed 2min 18.868s CPU time.
Oct 03 08:31:12 BirdnetPi systemd[1]: Started BirdNET-Pi Live Stream.
Oct 03 08:31:20 BirdnetPi livestream.sh[522945]: [tcp @ 0x55be4cf6e0] Connection to tcp://localhost:8000 failed: Connection refused
Oct 03 08:31:21 BirdnetPi livestream.sh[522945]: icecast://source:birdnetpi@localhost:8000/stream: Connection refused
Oct 03 08:31:20 BirdnetPi systemd[1]: livestream.service: Main process exited, code=exited, status=1/FAILURE
Oct 03 08:31:20 BirdnetPi systemd[1]: livestream.service: Failed with result 'exit-code'.
Oct 03 08:31:20 BirdnetPi systemd[1]: livestream.service: Consumed 1.032s CPU time.

● icecast2.service - LSB: Icecast2 streaming media server
     Loaded: loaded (/etc/init.d/icecast2; generated)
     Active: active (running) since Tue 2023-10-03 08:31:21 BST; 1s ago
       Docs: man:systemd-sysv-generator(8)
    Process: 522983 ExecStart=/etc/init.d/icecast2 start (code=exited, status=0/SUCCESS)
      Tasks: 4 (limit: 191)
        CPU: 181ms
     CGroup: /system.slice/icecast2.service
             └─522987 /usr/bin/icecast2 -b -c /etc/icecast2/icecast.xml

Oct 03 08:31:21 BirdnetPi icecast2[522947]: Stopping streaming media server: icecast2.
Oct 03 08:31:20 BirdnetPi systemd[1]: icecast2.service: Succeeded.
Oct 03 08:31:20 BirdnetPi systemd[1]: Stopped LSB: Icecast2 streaming media server.
Oct 03 08:31:20 BirdnetPi systemd[1]: icecast2.service: Consumed 3.112s CPU time.
Oct 03 08:31:20 BirdnetPi systemd[1]: Starting LSB: Icecast2 streaming media server...
Oct 03 08:31:21 BirdnetPi icecast2[522983]: Starting streaming media server: icecast2.
Oct 03 08:31:21 BirdnetPi systemd[1]: Started LSB: Icecast2 streaming media server.
Oct 03 08:31:21 BirdnetPi icecast2[522987]: [2023-10-03  08:31:21] WARN CONFIG/_parse_root Warning,  not configured, using default value "localhost". This will cause problems, e.g. with YP directory listings.
Oct 03 08:31:21 BirdnetPi icecast2[522987]: [2023-10-03  08:31:21] WARN CONFIG/_parse_root Warning,  not configured, using default value "Earth".
Oct 03 08:31:21 BirdnetPi icecast2[522987]: [2023-10-03  08:31:21] WARN CONFIG/_parse_root Warning,  contact not configured, using default value "icemaster@localhost".
ehpersonal38 commented 11 months ago

What's actually happening, I think, is that the gain of the microphone is being turned down to a very low level. You can see in the spectogram there actually is some data there. The recommended fix is to turn the gain back up - https://github.com/mcguirepr89/BirdNET-Pi/wiki/Adjusting-your-sound-card.

As to what causes it, I'm not exactly sure. Though I will say that the exact same issue was occuring to me back when I used a MOVO M1, so it may be limited to this brand, or cheaper mics.

bonehead1996 commented 11 months ago

What's actually happening, I think, is that the gain of the microphone is being turned down to a very low level. You can see in the spectogram there actually is some data there. The recommended fix is to turn the gain back up - https://github.com/mcguirepr89/BirdNET-Pi/wiki/Adjusting-your-sound-card.

As to what causes it, I'm not exactly sure. Though I will say that the exact same issue was occuring to me back when I used a MOVO M1, so it may be limited to this brand, or cheaper mics.

You're 100% correct, thank you!

I don't know why I didn't twig that could be the issue. Interesting you had the same issue with a MOVO mic. I'll have to see if I can track down an alternative and test to see if the same issue occurs.