-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement RecordingFileObject class (#82)
* Implement RecordingFileObject class * Fix minor formatting * Add documentation for new Recording classes
- Loading branch information
Showing
6 changed files
with
133 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import requests | ||
import io | ||
|
||
from datetime import datetime | ||
from pprint import pprint | ||
from birdnetlib import RecordingFileObject | ||
from birdnetlib.analyzer import Analyzer | ||
|
||
# Mississippi Kite from Xeno-Canto. | ||
r = requests.get("https://xeno-canto.org/669899/download") | ||
analyzer = Analyzer() | ||
|
||
with io.BytesIO(r.content) as fileObj: | ||
recording = RecordingFileObject( | ||
analyzer, | ||
fileObj, | ||
lat=35.6, | ||
lon=-77.3, | ||
date=datetime(year=2023, month=6, day=27), # use date or week_48 | ||
min_conf=0.25, | ||
) | ||
recording.analyze() | ||
pprint(recording.detections) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
from birdnetlib.main import Recording, Detection, MultiProcessRecording, RecordingBuffer | ||
from birdnetlib.main import ( | ||
Recording, | ||
Detection, | ||
MultiProcessRecording, | ||
RecordingBuffer, | ||
RecordingFileObject, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from birdnetlib import Recording, RecordingFileObject | ||
from birdnetlib.analyzer import Analyzer | ||
import io | ||
from pprint import pprint | ||
import os | ||
|
||
|
||
def test_without_species_list(): | ||
# Process file with command line utility, then process with python library and ensure equal commandline_results. | ||
|
||
lon = -120.7463 | ||
lat = 35.4244 | ||
week_48 = 18 | ||
min_conf = 0.25 | ||
input_path = os.path.join(os.path.dirname(__file__), "test_files/soundscape.wav") | ||
|
||
analyzer = Analyzer() | ||
|
||
# Analyzer with file path. | ||
|
||
recording_from_path = Recording( | ||
analyzer, | ||
input_path, | ||
lat=lat, | ||
lon=lon, | ||
week_48=week_48, | ||
min_conf=min_conf, | ||
) | ||
recording_from_path.analyze() | ||
pprint(recording_from_path.detections) | ||
|
||
# Analyze with file object. | ||
with open(input_path, "rb") as file: | ||
binary_data = file.read() | ||
|
||
with io.BytesIO(binary_data) as fileObj: | ||
recording_from_file_obj = RecordingFileObject( | ||
analyzer, | ||
fileObj, | ||
lat=lat, | ||
lon=lon, | ||
week_48=week_48, | ||
min_conf=min_conf, | ||
) | ||
recording_from_file_obj.analyze() | ||
pprint(recording_from_file_obj.detections) | ||
|
||
# Check that detections match. | ||
assert len(recording_from_path.detections) > 0 | ||
assert recording_from_path.detections == recording_from_file_obj.detections |