Go to file
Jeff Moe a6989c9456 Doc note now elsewhere 2023-09-21 17:04:30 -06:00
samples@64640a5ed3 Mono sample 2023-09-21 15:15:35 -06:00
.gitattributes git lfs for .wav 2023-09-21 13:38:05 -06:00
.gitignore ignore tmp files 2023-09-21 12:35:44 -06:00
.gitmodules Sound samples submodule 2023-09-21 13:45:48 -06:00
LICENSE Apache 2.0 License 2023-09-21 12:35:36 -06:00
README.md alsa-utils dep 2023-09-21 17:01:02 -06:00
requirements-dev.txt black formatting 2023-09-21 13:01:02 -06:00
requirements.txt Python requirements 2023-09-21 12:57:43 -06:00
sndid Add command line options to sndid 2023-09-21 14:41:14 -06:00
sndid-alsa Stream from alsa in to server script 2023-09-21 16:57:00 -06:00
sndid-client Rename python client script 2023-09-21 16:22:31 -06:00
sndid-server Doc note now elsewhere 2023-09-21 17:04:30 -06:00

README.md

sndid

sndid identifies sounds.

Install

Install thusly.

Using Debian Stable (12/Bookworm).

Install thine dependencies:

sudo apt update
sudo apt install git ffmpeg python3-pip python3-virtualenv \
  netcat-traditional sox alsa-utils

Clone repo:

git clone https://spacecruft.org/deepcrayon/sndid
cd sndid/

If you want some sound samples, pull the submodule:

git submodule init
git submodule update

Set up Python to taste, such as:

virtualenv env
source env/bin/activate
pip install --upgrade pip setuptools wheel

Install Python dependencies:

pip install -r requirements.txt

Usage

Command line

As such:

./sndid

Help:

$ ./sndid -h
usage: sndid [-h] [-i INPUT] [-t LATITUDE] [-n LONGITUDE] [-y YEAR] [-m MONTH] [-d DAY] [-c CONFIDENCE]

Run sndid

options:
  -h, --help            show this help message and exit
  -i INPUT, --input INPUT
                        Input filename to process (default samples/sample.wav)
  -t LATITUDE, --latitude LATITUDE
                        Latitude (default 40.57)
  -n LONGITUDE, --longitude LONGITUDE
                        Longitude (default -105.23)
  -y YEAR, --year YEAR  Year (default 2023)
  -m MONTH, --month MONTH
                        Month (default 9)
  -d DAY, --day DAY     Day (default 19)
  -c CONFIDENCE, --confidence CONFIDENCE
                        Minimum Confidence (default 0.50)

Sample output:

$ ./sndid
Labels loaded.
load model True
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Model loaded.
Labels loaded.
load_species_list_model
Meta model loaded.
read_audio_data
read_audio_data: complete, read  20 chunks.
analyze_recording sample.wav
recording has lon/lat
set_predicted_species_list_from_position
return_predicted_species_list
35
100 species loaded.
[{'common_name': 'Hairy Woodpecker', 'scientific_name': 'Dryobates villosus', 'start_time': 15.0, 'end_time': 18.0, 'confidence': 0.8371534943580627}, {'common_name': 'Hairy Woodpecker', 'scientific_name': 'Dryobates villosus', 'start_time': 18.0, 'end_time': 21.0, 'confidence': 0.8111729025840759}, {'common_name': 'Hairy Woodpecker', 'scientific_name': 'Dryobates villosus', 'start_time': 30.0, 'end_time': 33.0, 'confidence': 0.50068598985672}, {'common_name': 'Hairy Woodpecker', 'scientific_name': 'Dryobates villosus', 'start_time': 33.0, 'end_time': 36.0, 'confidence': 0.7170186042785645}, {'common_name': 'Hairy Woodpecker', 'scientific_name': 'Dryobates villosus', 'start_time': 39.0, 'end_time': 42.0, 'confidence': 0.6576249003410339}, {'common_name': 'Hairy Woodpecker', 'scientific_name': 'Dryobates villosus', 'start_time': 48.0, 'end_time': 51.0, 'confidence': 0.8048814535140991}, {'common_name': 'Hairy Woodpecker', 'scientific_name': 'Dryobates villosus', 'start_time': 51.0, 'end_time': 54.0, 'confidence': 0.9604988694190979}, {'common_name': 'Hairy Woodpecker', 'scientific_name': 'Dryobates villosus', 'start_time': 54.0, 'end_time': 57.0, 'confidence': 0.8156641125679016}, {'common_name': 'Hairy Woodpecker', 'scientific_name': 'Dryobates villosus', 'start_time': 57.0, 'end_time': 60.0, 'confidence': 0.8230038285255432}]

Server

Run thusly:

./sndid-server

Help:

$ ./sndid-server -h
usage: sndid-server [-h] [-i IP] [-p PORT] [-t LATITUDE] [-n LONGITUDE] [-y YEAR] [-m MONTH] [-d DAY] [-c CONFIDENCE]

Run sndid-server

options:
  -h, --help            show this help message and exit
  -i IP, --ip IP        Server IP address (default 127.0.0.1)
  -p PORT, --port PORT  Server network port (default 9988)
  -t LATITUDE, --latitude LATITUDE
                        Latitude (default 40.57)
  -n LONGITUDE, --longitude LONGITUDE
                        Longitude (default -105.23)
  -y YEAR, --year YEAR  Year (default 2023)
  -m MONTH, --month MONTH
                        Month (default 9)
  -d DAY, --day DAY     Day (default 19)
  -c CONFIDENCE, --confidence CONFIDENCE

Sample output on startup:

$ ./sndid-server
sndid-server Birdnetlib started
IP: 127.0.0.1
PORT: 9988

After client connects and sends mono wav:

Labels loaded.
load model True
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Model loaded.
Labels loaded.
load_species_list_model
Meta model loaded.
read_audio_data: complete, read  20 chunks.
analyze_recording buffer
recording has lon/lat
set_predicted_species_list_from_position
return_predicted_species_list
35
100 species loaded.
[{'common_name': 'Hairy Woodpecker',
  'confidence': 0.837184488773346,
  'end_time': 18.0,
  'scientific_name': 'Dryobates villosus',
  'start_time': 15.0},
 {'common_name': 'Hairy Woodpecker',
  'confidence': 0.8105885982513428,
  'end_time': 21.0,
  'scientific_name': 'Dryobates villosus',
  'start_time': 18.0},
 {'common_name': 'Hairy Woodpecker',
  'confidence': 0.47060683369636536,
  'end_time': 24.0,
  'scientific_name': 'Dryobates villosus',
  'start_time': 21.0},
 {'common_name': 'Hairy Woodpecker',
  'confidence': 0.5013241171836853,
  'end_time': 33.0,
  'scientific_name': 'Dryobates villosus',
  'start_time': 30.0},
 {'common_name': 'Hairy Woodpecker',
  'confidence': 0.7146830558776855,
  'end_time': 36.0,
  'scientific_name': 'Dryobates villosus',
  'start_time': 33.0},
 {'common_name': 'Hairy Woodpecker',
  'confidence': 0.6557420492172241,
  'end_time': 42.0,
  'scientific_name': 'Dryobates villosus',
  'start_time': 39.0},
 {'common_name': 'Hairy Woodpecker',
  'confidence': 0.3896884322166443,
  'end_time': 45.0,
  'scientific_name': 'Dryobates villosus',
  'start_time': 42.0},
 {'common_name': 'Hairy Woodpecker',
  'confidence': 0.806126594543457,
  'end_time': 51.0,
  'scientific_name': 'Dryobates villosus',
  'start_time': 48.0},
 {'common_name': 'Hairy Woodpecker',
  'confidence': 0.9604253768920898,
  'end_time': 54.0,
  'scientific_name': 'Dryobates villosus',
  'start_time': 51.0},
 {'common_name': 'Hairy Woodpecker',
  'confidence': 0.8147749900817871,
  'end_time': 57.0,
  'scientific_name': 'Dryobates villosus',
  'start_time': 54.0},
 {'common_name': 'Hairy Woodpecker',
  'confidence': 0.8241879343986511,
  'end_time': 60.0,
  'scientific_name': 'Dryobates villosus',
  'start_time': 57.0}]

Client

Requires mono wav file.

To convert stereo to mono with sox:

sox -c 2 stereo.wav -c 1 mono.wav

Run client to submit file to server thusly:

./sndid-client

Help:

$ ./sndid-client.py -h
usage: sndid-client.py [-h] [-i IP] [-p PORT] [-f FILE]

Run sndid-client

options:
  -h, --help            show this help message and exit
  -i IP, --ip IP        Server IP address (default 127.0.0.1)
  -p PORT, --port PORT  Server network port (default 9988)
  -f FILE, --file FILE  Input filename to process (default samples/mono.wav)

Sample output:

$ ./sndid-client
Sending samples/mono.wav to 127.0.0.1:9988

ALSA Client

Use this script to stream from the microphone to the server, using ALSA.

./sndid-alsa

Help:

$ ./sndid-alsa -h
usage: sndid-alsa [-h] [-i IP] [-p PORT] [-r RATE] [-t TIME]

Run sndid-alsa

options:
  -h, --help            show this help message and exit
  -i IP, --ip IP        Server IP address (default 127.0.0.1)
  -p PORT, --port PORT  Server network port (default 9988)
  -r RATE, --rate RATE  Rate in Hertz (default 48000)
  -t TIME, --time TIME  Length of segments in seconds (default 10)

Sample output:

$ ./sndid-alsa 
Streaming ALSA in to 127.0.0.1:9988
Recording WAVE 'stdin' : Float 32 bit Little Endian, Rate 48000 Hz, Mono

Exit with CTRL-C.

Development

To "develop", install the requirements:

pip install -r requirements-dev.txt

Then run black on the Python files for nice formatting:

black *.py

Upstream

Birds

BirdNet

Unfortunately the project has a horrible license, CC-NC-BY-SA 4.0, which isn't even a software license. The authors of the license themselves say it shouldn't be used for software. It's not just the data files, such as the models that are NC (which would be ok), but the source code itself is NC. I haven't double checked the Python imports, but it would be interesting to see if they are even compatible with the NC license, since the NC license is incompatible with so many Free Software and Open Source Software licenses. There is a bug open to fix the license, and change it to Apache 2.0, which would be sane. I hope this happens:

https://github.com/kahst/BirdNET-Analyzer/issues/154

birdnetlib

birdnetlib is based on BirdNet, but with a different codebase and author. birdnetlib uses BirdNet's non-libre NC model files. birdnetlib has a dependency on the non-free BirdNet-Analyzer Python code (e.g. via pip install), but the source code to birdnetlib itself is under the Apache 2.0 license. birdnetlib is Free Software / Open Source Software, with non-libre dependency.

https://github.com/joeweiss/birdnetlib

Status

Alpha, initial development.

Copyright

Unofficial project, not related to BirdNet or Joe Weiss.

Upstream sources under their respective copyrights.

License

Apache 2.0.

Copyright © 2023, Jeff Moe.