Skip to main content

Open source, scalable acoustic classification for ecology and conservation

Project description

CI Status Documentation Status

OpenSoundscape

OpenSoundscape is a utility library for analyzing bioacoustic data. It consists of Python modules for tasks such as preprocessing audio data, training machine learning models to classify vocalizations, estimating the spatial location of sounds, identifying which species' sounds are present in acoustic data, and more.

These utilities can be strung together to create data analysis pipelines. OpenSoundscape is designed to be run on any scale of computer: laptop, desktop, or computing cluster.

OpenSoundscape is currently in active development. If you find a bug, please submit an issue. If you have another question about OpenSoundscape, please email Sam Lapp (sam.lapp at pitt.edu).

Suggested Citation

Lapp, Rhinehart, Freeland-Haynes, Khilnani, Syunkova, and Kitzes, 2022. "OpenSoundscape v0.8.0".

Installation

OpenSoundscape can be installed on Windows, Mac, and Linux machines. It has been tested on Python 3.7, 3.8, and 3.9. For Apple Silicon (M1 chip) users, Python 3.9 is recommended and may be required to avoid dependency issues. Python version 3.7.0 causes dependency issues and should be avoided.

Most users should install OpenSoundscape via pip: pip install opensoundscape==0.8.0. Contributors and advanced users can also use Poetry to install OpenSoundscape.

For more detailed instructions on how to install OpenSoundscape and use it in Jupyter, see the documentation.

Features & Tutorials

OpenSoundscape includes functions to:

  • load and manipulate audio files
  • create and manipulate spectrograms
  • train CNNs on spectrograms with PyTorch
  • run pre-trained CNNs to detect vocalizations
  • detect periodic vocalizations with RIBBIT
  • load and manipulate Raven annotations

OpenSoundscape can also be used with our library of publicly available trained machine learning models for the detection of 500 common North American bird species.

For full API documentation and tutorials on how to use OpenSoundscape to work with audio and spectrograms, train machine learning models, apply trained machine learning models to acoustic data, and detect periodic vocalizations using RIBBIT, see the documentation.

Quick Start

Using Audio and Spectrogram classes

from opensoundscape.audio import Audio
from opensoundscape.spectrogram import Spectrogram

#load an audio file and trim out a 5 second clip
my_audio = Audio.from_file("/path/to/audio.wav")
clip_5s = my_audio.trim(0,5)

#create a spectrogram and plot it
my_spec = Spectrogram.from_audio(clip_5s)
my_spec.plot()

Load audio starting at a real-world timestamp

from datetime import datetime; import pytz

start_time = pytz.timezone('UTC').localize(datetime(2020,4,4,10,25))
audio_length = 5 #seconds  
path = '/path/to/audiomoth_file.WAV' #an AudioMoth recording

Audio.from_file(path, start_timestamp=start_time,duration=audio_length)

Using a pre-trained CNN to make predictions on long audio files

from opensoundscape.torch.models.cnn import load_model

#get list of audio files
files = glob('./dir/*.WAV')

#generate predictions with a model
model = load_model('/path/to/saved.model')
scores = model.predict(files)

#scores is a dataframe with MultiIndex: file, start_time, end_time
#containing inference scores for each class and each audio window

Training a CNN with labeled audio data

from opensoundscape.torch.models.cnn import CNN
from sklearn.model_selection import train_test_split

#load a DataFrame of one-hot audio clip labels
df = pd.read_csv('my_labels.csv') #index: paths; columns: classes
train_df, validation_df = train_test_split(df,test_size=0.2)

#create a CNN and train on 2-second spectrograms for 2 epochs
model = CNN('resnet18',classes=df.columns,sample_duration=2.0)
model.train(
  train_df,
  validation_df,
  epochs=2
)
#the best model is automatically saved to a file `./best.model`

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opensoundscape-0.8.0.tar.gz (154.7 kB view details)

Uploaded Source

Built Distribution

opensoundscape-0.8.0-py3-none-any.whl (114.2 kB view details)

Uploaded Python 3

File details

Details for the file opensoundscape-0.8.0.tar.gz.

File metadata

  • Download URL: opensoundscape-0.8.0.tar.gz
  • Upload date:
  • Size: 154.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.11.3 pkginfo/1.8.2 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.9.13

File hashes

Hashes for opensoundscape-0.8.0.tar.gz
Algorithm Hash digest
SHA256 3f344d91476116af37edcee75cff455ac8093172f800b3cdb6f51e65c8f4f525
MD5 885ec2f3946d3aba9d3a8d3c28b574ee
BLAKE2b-256 f975c734c566d6ee21121d95c15a00599ce83066d3721b6cccb5db7d7ee8ccc1

See more details on using hashes here.

File details

Details for the file opensoundscape-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: opensoundscape-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 114.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.11.3 pkginfo/1.8.2 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.9.13

File hashes

Hashes for opensoundscape-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 860793b5b588c74bdf05fb41b2a381f7b60b0acdf4c203bfd6494fc6590a9bb5
MD5 20bb29009904dfbd10ab7edf7b7563d7
BLAKE2b-256 59fd6ff16ad37948c4fce63e7dbe9e9bf1f52ceeeb1655f8473e872903c81e0b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page