2023-09-21 12:35:13 -06:00
|
|
|
# sndid
|
|
|
|
`sndid` identifies sounds.
|
|
|
|
|
|
|
|
|
|
|
|
# Install
|
|
|
|
Install thusly.
|
|
|
|
|
|
|
|
Using Debian Stable (12/Bookworm).
|
|
|
|
|
|
|
|
Install thine dependencies:
|
|
|
|
```
|
|
|
|
sudo apt update
|
2023-09-21 17:01:02 -06:00
|
|
|
sudo apt install git ffmpeg python3-pip python3-virtualenv \
|
|
|
|
netcat-traditional sox alsa-utils
|
2023-09-21 12:35:13 -06:00
|
|
|
```
|
|
|
|
|
|
|
|
Clone repo:
|
|
|
|
```
|
|
|
|
git clone https://spacecruft.org/deepcrayon/sndid
|
|
|
|
cd sndid/
|
|
|
|
```
|
|
|
|
|
2023-09-21 13:47:43 -06:00
|
|
|
If you want some sound samples, pull the submodule:
|
|
|
|
|
|
|
|
```
|
|
|
|
git submodule init
|
|
|
|
git submodule update
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2023-09-21 12:35:13 -06:00
|
|
|
Set up Python to taste, such as:
|
|
|
|
```
|
2023-09-21 12:59:07 -06:00
|
|
|
virtualenv env
|
2023-09-21 12:35:13 -06:00
|
|
|
source env/bin/activate
|
|
|
|
pip install --upgrade pip setuptools wheel
|
|
|
|
```
|
|
|
|
|
|
|
|
Install Python dependencies:
|
|
|
|
```
|
|
|
|
pip install -r requirements.txt
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
# Usage
|
2023-09-21 14:42:41 -06:00
|
|
|
## Command line
|
|
|
|
As such:
|
2023-09-21 12:35:13 -06:00
|
|
|
|
2023-09-21 13:51:51 -06:00
|
|
|
```
|
|
|
|
./sndid
|
|
|
|
```
|
2023-09-21 12:35:13 -06:00
|
|
|
|
2023-09-21 14:42:41 -06:00
|
|
|
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)
|
|
|
|
```
|
|
|
|
|
2023-09-21 15:26:48 -06:00
|
|
|
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}]
|
|
|
|
```
|
|
|
|
|
2023-09-21 14:42:41 -06:00
|
|
|
|
2023-09-21 14:28:37 -06:00
|
|
|
## 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
|
|
|
|
```
|
|
|
|
|
2023-09-21 15:26:48 -06:00
|
|
|
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}]
|
|
|
|
```
|
|
|
|
|
2023-09-21 12:35:13 -06:00
|
|
|
|
2023-09-21 15:19:52 -06:00
|
|
|
## Client
|
2023-09-21 16:22:47 -06:00
|
|
|
Requires mono wav file.
|
|
|
|
|
|
|
|
To convert stereo to mono with sox:
|
2023-09-21 15:19:52 -06:00
|
|
|
|
|
|
|
```
|
2023-09-21 16:22:47 -06:00
|
|
|
sox -c 2 stereo.wav -c 1 mono.wav
|
2023-09-21 15:19:52 -06:00
|
|
|
```
|
|
|
|
|
2023-09-21 15:53:47 -06:00
|
|
|
|
2023-09-21 16:22:47 -06:00
|
|
|
Run client to submit file to server thusly:
|
2023-09-21 15:53:47 -06:00
|
|
|
|
2023-09-21 16:22:47 -06:00
|
|
|
```
|
|
|
|
./sndid-client
|
|
|
|
```
|
2023-09-21 15:53:47 -06:00
|
|
|
|
|
|
|
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)
|
|
|
|
```
|
2023-09-21 15:26:48 -06:00
|
|
|
|
2023-09-21 16:22:47 -06:00
|
|
|
Sample output:
|
|
|
|
|
|
|
|
```
|
|
|
|
$ ./sndid-client
|
|
|
|
Sending samples/mono.wav to 127.0.0.1:9988
|
|
|
|
```
|
|
|
|
|
2023-09-21 16:59:54 -06:00
|
|
|
## 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`.
|
|
|
|
|
2023-09-21 15:19:52 -06:00
|
|
|
|
2023-09-21 12:35:13 -06:00
|
|
|
# Development
|
|
|
|
To "develop", install the requirements:
|
|
|
|
|
|
|
|
```
|
|
|
|
pip install -r requirements-dev.txt
|
|
|
|
```
|
|
|
|
|
2023-09-21 12:59:07 -06:00
|
|
|
Then run black on the Python files for nice formatting:
|
2023-09-21 12:35:13 -06:00
|
|
|
|
|
|
|
```
|
|
|
|
black *.py
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
# Upstream
|
2023-09-21 12:51:50 -06:00
|
|
|
## Birds
|
|
|
|
### BirdNet
|
|
|
|
* BirdNet is the main upstream project:
|
|
|
|
https://birdnet.cornell.edu/
|
|
|
|
|
|
|
|
* The source code is available here:
|
|
|
|
https://github.com/kahst/BirdNET-Analyzer
|
|
|
|
|
|
|
|
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.
|
2023-09-21 14:47:24 -06:00
|
|
|
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`),
|
2023-09-21 12:51:50 -06:00
|
|
|
but the source code to birdnetlib itself is
|
2023-09-21 14:47:24 -06:00
|
|
|
under the Apache 2.0 license.
|
|
|
|
birdnetlib is Free Software / Open Source Software, with non-libre dependency.
|
2023-09-21 12:51:50 -06:00
|
|
|
|
|
|
|
|
|
|
|
https://github.com/joeweiss/birdnetlib
|
|
|
|
|
2023-09-21 12:35:13 -06:00
|
|
|
|
2023-09-21 13:51:51 -06:00
|
|
|
# Status
|
|
|
|
Alpha, initial development.
|
|
|
|
|
|
|
|
|
2023-09-21 12:35:13 -06:00
|
|
|
# Copyright
|
2023-09-21 12:51:50 -06:00
|
|
|
Unofficial project, not related to BirdNet or Joe Weiss.
|
2023-09-21 12:35:13 -06:00
|
|
|
|
|
|
|
Upstream sources under their respective copyrights.
|
|
|
|
|
|
|
|
|
|
|
|
# License
|
|
|
|
Apache 2.0.
|
|
|
|
|
|
|
|
*Copyright © 2023, Jeff Moe.*
|
|
|
|
|