Skip to main content

JupyterBioacoustic

A JupyterLab plugin for reviewing and annotating bioacoustic audio clips.

JupyterBioacoustic Plugin

Documentation

Table of Contents


Install

pip install jupyter-bioacoustic

Optional extras:

pip install "jupyter-bioacoustic[gcs]"    # gs:// audio, data and output sync

SQL (SELECT ...) data needs duckdb (pip install duckdb).

Remote audio

Remote FLAC and WAV files (s3://, gs://, https://) are read with byte-range requests, so only the clip being played is downloaded and multi-hour recordings open in seconds. Other formats, or a range read that fails, fall back to downloading and caching the whole file. Set partial_download=False to always download the whole file. No ffmpeg is needed.

See the Development wiki for building from source.

Quick Start

from jupyter_bioacoustic import BioacousticAnnotator

BioacousticAnnotator(
    data='detections-test.csv',
    audio='test.flac',
    data_index_column='id',
    info_card_title='[[common_name]]',
    form_config='form-review.yaml',
    output='reviews.csv',
).open()

JupyterBioacoustic Plugin

See the Getting Started guide for test files and more examples.

Features

  • Player / Visualizer — browse audio clips with interactive spectrograms and other visualizations (linear, mel, log-frequency, or custom)
  • Configurable Forms — YAML-driven annotation and review forms with selects, textboxes, checkboxes, buttons and toggles (built-in icons, one-click submit), conditional sections, and row / column / grid layouts
  • Keyboard-driven review — j / k between clips, Tab / arrows through the form, and per-element hot keys
  • Collapsible layout — collapse the playlist, spectrogram or form to just the row you need; put a small form beside the spectrogram (side_form) with a draggable divider
  • Annotation Tools — fixed-duration windows, time markers, start/end lines, bounding boxes, and multibox (multiple labeled regions per clip)
  • Built-In & Custom Visualizations — built-in linear and mel spectrograms, log-frequency, bandpass and waveform visualizations. Easily integrate third-party libraries (OpenSoundscape, librosa, SciPy, ...) or write your own
  • Zoom and Capture — keyboard/mouse zoom, drag-to-pan, zoom-to-selection box, and PNG export
  • Flexible data sources — CSV, Parquet, JSON, SQL (DuckDB), API endpoints; remote FLAC/WAV audio read by byte range
  • Syncing — sync local annotation files to remote storage such as S3 and GCS

Documentation

Full documentation is on the wiki:

Usage

The BioacousticAnnotator class has a small interface. The main methods are .open(inline=True), .output(force=False) and .validate(), and .source holds the input data. See the API Reference for the rest (.sync(), .describe(), .configuration, ...).

from jupyter_bioacoustic import BioacousticAnnotator

# Create an instance
ja = BioacousticAnnotator(data='path_to_data.parquet', ...)

# Validate the config (same checks as `jba validate` and the config builder)
# -> {'valid': bool, 'errors': [...], 'warnings': [...]}
ja.validate()

# Open the interface
ja.open()

# Get a dataframe with all the submitted data
# Note: this data is lazy loaded. this will read from
#       file each time you submit.
#       however between submissions it will be cached.
result_df = ja.output()
result_df = ja.output(force=True)  # force re-read from disk

# Dataframe access to the source data (here 'path_to_data.parquet')
ja.source

The parameters for BioacousticAnnotator are listed below. There is one special parameter config that can be used instead of providing the parameter values directly in the notebook. This is a great feature for reproduciblity, organization and avoiding bloated notebooks.

Consider the example above:

BioacousticAnnotator(
    data='detections-test.csv',
    audio='test.flac',
    data_index_column='id',
    info_card_title='[[common_name]]',
    form_config='form-review.yaml',
    output='reviews.csv',
)

This can instead be produced this way

BioacousticAnnotator(
    data='detections-test.csv',
    config='config/review-configuration.yaml',
).open()
# config/review-configuration.yaml
audio: 'test.flac'
data_index_column: 'id'
info_card_title: '[[common_name]]'
form_config: 'form-review.yaml'
output: 'reviews.csv'

For this simple example, this might not seem helpful. However for more advanced configurations this is quite useful. Moreover, in the example above the review-form has a configuration file form-review.yaml. If using config the form can be included directly.

See Configuration for full details. Here is an advanced example:

# BioacousticAnnotator Args
audio: "audio_path"    # column name — auto-detected (no slashes or dots)
data_index_column: id  # required whenever there is a form
display_columns: ["common_name", "confidence", "start_time", "county", "audio_path"]
info_card_title: '[[common_name]]'
info_card_text: '[[confidence]] | [[county]] | [[start_time]]'
capture: 'Save Spectrogram'
capture_dir: 'spectrograms'


# Form
form_config:
  title:
    value: 'REVIEW CLIP'
    progress_tracker: true
  form:
    - select:
        label: Is Valid
        column: is_valid
        required: true
        items:
          - label: 'yes'
            value: 'yes'
          - label: 'no'
            value: 'no'
            form: correction_form   # shown when "no" is selected
    - textbox:
        label: notes
        column: notes
  annotation:
    tools: start_end_time_select
  dynamic_forms:
    correction_form:
      - select:
          label: verified name
          column: verified_common_name
          required: true
          items:
            path: data/categories.csv
            value: common_name
      - select:
          label: verif. confidence
          column: verification_confidence
          items:
            - low
            - medium
            - high
  submission_buttons:
    line: true
    next:
      label: Skip
    submit:
      label: Verify

BioacousticAnnotator Parameters

Parameter Type Default Description
data DataFrame / str / dict required* Input data. String: file path (CSV, Parquet, JSON), URL, api::url, or SQL (SELECT ...). Dict: {value(+source_type)|path|url|uri|api|sql, secrets, columns, index_column, start_time, end_time, duration}.
data_source_type str None How to read data_value: path, url, sql or api. Omitted ⇒ auto-detect.
data_value str None Data source string, read according to data_source_type.
data_path str None Explicit file path for data (overrides data source).
data_url str None Explicit URL for data (overrides data source).
data_sql str None Explicit SQL query for data (overrides data source).
data_api str None Explicit API endpoint for data (overrides data source).
data_index_column str None Column that uniquely identifies each input row. Required when a form is configured.
data_start_time str 'start_time' Column with clip start times (seconds).
data_end_time str 'end_time' Column with clip end times (seconds).
data_duration str / number None Column, or a fixed number of seconds, for clip duration (instead of data_end_time).
data_secrets dict, list, or false None Auth for data loading. {key, value} pairs. Value: env:VAR, dialog, or literal. Set to false to opt out of global secrets fallback.
display_columns list [] Columns for the clip table.
sort str None Column to sort the clip table by (None keeps input order).
sort_order str 'asc' 'asc' or 'desc'.
audio str or dict required* Audio source. String: local path, URL/URI, or column name (auto-detected). Dict: {value(+source_type)|path|url|uri|column|sql|api, prefix, suffix, fallback, secrets, property, response_index}.
audio_source_type str None How to read audio_value: path, url, uri, column, sql or api. Omitted ⇒ auto-detect.
audio_value str None Audio source string, read according to audio_source_type.
audio_path str None Explicit local file path for audio (overrides audio source).
audio_url str None Explicit URL for audio (overrides audio source).
audio_uri str None Alias for audio_url.
audio_column str None Explicit column name for per-row audio (overrides audio source).
audio_prefix str '' Prefix joined with / to audio paths.
audio_suffix str '' Suffix joined with / to audio paths.
audio_fallback str '' Fallback when audio is a column and the row value is empty.
audio_secrets dict, list, or false None Auth for audio loading (same format as data_secrets). Set to false to opt out of global secrets fallback.
audio_sql str None SQL query to resolve audio path. Requires audio_property.
audio_api str None API URL to resolve audio path. Requires audio_property.
audio_property str None Field/column to extract from SQL/API response as the audio path.
audio_response_index int 1 1-based row index for SQL/API response (1 = first row).
secrets dict or list None Global auth — fallback for data_secrets, audio_secrets, and output_secrets. Each can opt out by setting to false.
output str or dict '' Output file path or sync config dict. String: local path. Dict: {path, uri/url, sync_button, recursive, secrets, index_column}. Without one, a form writes to outputs/annotation_output-<timestamp>.csv. See Output & Sync.
output_path str None Explicit local output file path (overrides output string or output.path dict key).
output_url str None Remote sync destination (overrides output.uri/output.url dict key).
output_uri str None Alias for output_url.
output_sync_button bool / str None Show a sync button (true = "Sync", string = custom label, false = hidden). Defaults to "Sync" when a sync URI is set.
output_recursive bool None Passed to io.write() for uploading directories.
output_secrets dict, list, or false None Auth for sync uploads (same format as data_secrets). Set to false to opt out of global secrets fallback.
output_index_column str data_index_column Name of the row-identifier column in the output file.
project str / dict None Project file path (or dict). No other config params allowed when set.
project_name str None Widget header title. Auto-derived from project filename if not set.
config str / dict None Path to a YAML/JSON config file (or dict).
form_config dict / str None Form layout — YAML file, dict, or None for no form.
description str / dict None Collapsible description panel: markdown text, a .md/.txt path, or {title, text, path, open, height}.
description_title, description_text, description_path, description_open, description_height None The description dict keys as separate parameters.
info_card_title str '' Info card title — supports [[column_name]] templates. Also used for capture filenames.
info_card_text str '' Info card text — supports [[column_name]] templates.
duplicate_entries bool False Allow multiple submissions per row. When False, re-submitting a clip replaces its earlier entry.
default_buffer int / float 3 Default buffer time in seconds around each clip
capture bool / str True Capture button (False to hide, string for custom label)
capture_dir str '' Directory prefix for captures
capture_height int None Capture image height in pixels. Defaults to player_height if not set.
spectrogram_resolution int / list [1000, 2000, 4000] Spectrogram width in pixels. List for a dropdown selector, single value for fixed. Prefix an item with selected:: to set the default (e.g. [1000, 'selected::2000', 4000]).
visualizations list ['linear', 'mel'] Visualization types for the dropdown. Built-in strings ('linear', 'mel', 'log_frequency', 'bandpass', 'waveform') or custom callables. See Custom Visualizations.
partial_download bool True Read only the clip's bytes from remote FLAC/WAV audio. Set to False to always download and cache the full file.
width str / int '100%' Widget width (pixels or a percentage string).
clip_table_height int 175 Clip table height in pixels.
player_height int 260 Player/spectrogram height in pixels.
info_card_height int 34 Info card height in pixels.
hide_info_card bool False Hide the info card (the playlist's collapse toggle then gets its own slim row).
playlist_title, spectrogram_title bool / str False Text after the section's collapse chevron: False none, True the standard name, or a string.
playlist_open, spectrogram_open, form_open bool True Whether each section starts expanded. See Layout and Collapsible Sections.
freq_min, freq_max float None Frequency window (kHz) the spectrogram opens with and Reset returns to. Frequency zooms are kept from clip to clip.
form_panel_height int 175 Form panel height in pixels.
session_args list / str / bool None Which **kwargs are allowed: a list of names, one name as a string, True (all) or False (none).
**kwargs Fixed columns in every output row. A name close to a real parameter (e.g. sort_ordr) gives a "Did you mean" warning.

* data is not required if data_value, data_path, data_url, data_sql, or data_api is provided. audio is not required if audio_value, audio_path, audio_url, audio_uri, audio_column, audio_sql, or audio_api is provided.

Demo

Example notebooks are included in the demo/ directory. They require additional dependencies (ipyleaflet, shapely, seaborn, requests).

1. Install with demo dependencies

With pixi:

cd demo
pixi run -e demo jba lab

This launches JupyterLab inside the demo pixi environment with the data-rate limit pre-configured.

With pip:

pip install -e ".[demo]"
jupyter lab --ServerApp.iopub_data_rate_limit=1e10

2. Download audio files (one-time)

Audio files are not included in this repository (they are large FLAC files, ~50-100 MB each).

These are large files. It will likely take multiple minutes per file to download. For demo purposes, you can replace them with any FLAC audio file — the spectrograms will look different but the plugin works the same way.

With AWS CLI (faster):

cd demo
mkdir -p audio
aws s3 cp s3://dse-soundhub/public/audio/dev/20230522_200000.flac audio/test-default.flac --no-sign-request &
aws s3 cp s3://dse-soundhub/public/audio/dev/20230524_200000.flac audio/test1.flac --no-sign-request &
aws s3 cp s3://dse-soundhub/public/audio/dev/20230525_200000.flac audio/test2.flac --no-sign-request &
aws s3 cp s3://dse-soundhub/public/audio/dev/20230526_000000.flac audio/test3.flac --no-sign-request &
wait

With curl:

cd demo
mkdir -p audio
curl -o audio/test-default.flac https://dse-soundhub.s3.us-west-2.amazonaws.com/public/audio/dev/20230522_200000.flac
curl -o audio/test1.flac https://dse-soundhub.s3.us-west-2.amazonaws.com/public/audio/dev/20230524_200000.flac
curl -o audio/test2.flac https://dse-soundhub.s3.us-west-2.amazonaws.com/public/audio/dev/20230525_200000.flac
curl -o audio/test3.flac https://dse-soundhub.s3.us-west-2.amazonaws.com/public/audio/dev/20230526_000000.flac

3. Open a demo notebook

Open simple-examples.ipynb from the JupyterLab file browser. The notebook demonstrates both review and annotation workflows. review-workflows.ipynb has ready-to-use review setups (one-click validation, quick labelling with hot keys, multilabel regions) and layout-examples.ipynb shows the layout options (side form, collapsed sections, row / column / grid forms). See the Demo wiki page for every notebook.

License

BSD 3-Clause

Metadata

Release files for jupyter-bioacoustic 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for jupyter-bioacoustic 0.10.0
File Interpreter ABI Platform Actions
jupyter_bioacoustic-0.10.0-py3-none-any.whl Python 3 none any Details for jupyter_bioacoustic-0.10.0-py3-none-any.whl

Release files / jupyter_bioacoustic-0.10.0-py3-none-any.whl

Download URL jupyter_bioacoustic-0.10.0-py3-none-any.whl
Size 646.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c44009411f99b6a08658eaedf66b82c518b4d8e77ac2e4311928213a15dc885a
BLAKE2b-256 checksum
How to use checksums
3604ffb251a67ffea2c530430c5b58fca12703a2f8cff188e7812e4691be2ee5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Security for jupyter-bioacoustic 0.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page