tphakala / birdnet-go

Realtime BirdNET soundscape analyzer
Other
137 stars 14 forks source link

Listening device mismatch in Docker #140

Closed farski closed 2 weeks ago

farski commented 1 month ago

When I run arecord -l, I get:

**** List of CAPTURE Hardware Devices ****
card 1: Device [USB Audio Device], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #14 

However, when I start the Docker container, I see:

BirdNET-Go build date: 2024-05-01T17:38:41Z, using config file: /root/.config/birdnet-go/config.yaml
BirdNET GLOBAL 6K V2.4 FP32 model initialized, using 4 threads of available 4 CPUs
System details: linux debian 12.5 on  hardware
Starting analyzer in realtime mode. Threshold: 0.8, sensitivity: 1, interval: 15
[2024-05-03T08:05:27-04:00] [INFO] ⇨ http server started on [::]:8080
Capture Devices
    0: Discard all samples (playback) or generate zero samples (capture), 6e756c6c, 
    1: Default Audio Device, 64656661756c74, [default]
    2: Default Audio Device, 73797364656661756c74, 
    3: USB Audio Device, USB Audio, 3a312c30, 
Listening on device: Default Audio Device (device ID 64656661756c74)

I could just be misunderstanding what the logs are trying to say, or how devices on the host exist with the Docker environment, but I would expect it to be listening on the USB Audio device that matches that arecord output.

It is recording clips and when I play them back they sound find, but the detections are not correct; it's not really detecting anything. There are occasional detections, but they are all false positives, it's not picking up any of the normal birds that it would normally be detecting ever couple of minutes.

tphakala commented 1 month ago
Capture Devices
    0: Discard all samples (playback) or generate zero samples (capture), 6e756c6c, 
    1: Default Audio Device, 64656661756c74, [default]
    2: Default Audio Device, 73797364656661756c74, 
    3: USB Audio Device, USB Audio, 3a312c30, 
Listening on device: Default Audio Device (device ID 64656661756c74)

"Default Audio Device" is "USB Audio Device" in your case, as you do not have any other audio capture devices on your system.

It is recording clips and when I play them back they sound find, but the detections are not correct; it's not really detecting anything. There are occasional detections, but they are all false positives, it's not picking up any of the normal birds that it would normally be detecting ever couple of minutes.

This I do not understand though .. what hardware are you using? How high CPU utilisation your system has when birdnet-go container is running? Could it be that CPU is saturated.

farski commented 1 month ago

CPU when running in docker looked to be holding at about 40%.

I grabbed the most recent binary and tried that too.

BirdNET-Go build date: 2024-05-01T17:10:00Z, using config file: /home/birdnet/.config/birdnet-go/config.yaml
BirdNET GLOBAL 6K V2.4 FP32 model initialized, using 4 threads of available 4 CPUs
System details: linux raspbian 12.5 on Raspberry Pi 4 Model B Rev 1.5 hardware
Starting analyzer in realtime mode. Threshold: 0.8, sensitivity: 1, interval: 15
[2024-05-03T09:27:25-04:00] [INFO] ⇨ http server started on [::]:8080
Capture Devices
    0: Discard all samples (playback) or generate zero samples (capture), 6e756c6c, 
    1: Playback/recording through the PulseAudio sound server, 64656661756c74, [default]
    2: Rate Converter Plugin Using Libav/FFmpeg Library, 6c617672617465, 
    3: Rate Converter Plugin Using Samplerate Library, 73616d706c6572617465, 
    4: Rate Converter Plugin Using Speex Resampler, 737065657872617465, 
    5: JACK Audio Connection Kit, 6a61636b, 
    6: Open Sound System, 6f7373, 
    7: PulseAudio Sound Server, 70756c7365, 
    8: Plugin using Speex DSP (resample, agc, denoise, echo, dereverb), 7370656578, 
    9: Plugin for channel upmix (4,6,8), 75706d6978, 
    10: Plugin for channel downmix (stereo) with a simple spacialization, 76646f776e6d6978, 
    11: USB Audio Device, USB Audio, 3a312c30, 
Listening on device: Playback/recording through the PulseAudio sound server (device ID 64656661756c74)

Is that what you'd expect to see? Or should it be using USB Audio Device?

tphakala commented 1 month ago

On Linux applications typically do not use direct audio hardware devices, there is always some kind of abstraction layer in between. On output you provided your system has Pulse Audio which has control of your USB Audio Device and BirdNET-Go mini audio library has tapped into Pulse Audio server for audio capture, this is expected behavior.

farski commented 1 month ago

Cool, thanks for the explanation. Running the latest release outside of Docker is yielding more normal results. I can spend some more time on the Docker setup this weekend.

tphakala commented 1 month ago

Commits 7041fe0bbb33e7ab53b01b2186cb8754abcafe5a and 7f56d6a91b4a8aaf13b45e14c2870af03733b25e introduce user configurable setting for selecting audio source.

config.yaml example

realtime:
    audio:
        source: "USB Audio Device"

cli example

birdnet-go realtime --source "USB Audio Device"