ndx-sound Extension for NWB
NWB extension for sounds.
Installation
pip install ndx-sound
Usage
Python
Add to an NWB file
from pynwb import NWBFile
from scipy.io import wavfile
from ndx_sound import AcousticWaveformSeries
# The file path to the audio file
file_path = "audio_data.wav"
# Read the audio file to get the rate of the recording and the waveform
sampling_rate, samples = wavfile.read(file_path)
# Create an AcousticWaveformSeries object with a given name and description
acoustic_waveform_series = AcousticWaveformSeries(
name="acoustic_stimulus",
data=samples,
rate=sampling_rate,
description="acoustic stimulus",
)
# Create an NWBFile object where this AcousticWaveformSeries can be added to
nwbfile = NWBFile(
session_description=...,
identifier=...,
session_start_time=...,
)
# If a recording of behavior, add to acquisition
nwbfile.add_acquisition(acoustic_waveform_series)
# If a stimulus, add to stimulus
nwbfile.add_stimulus(acoustic_waveform_series)
Visualization
Static widgets
Use plot_sound to visualize the waveform series and the spectrogram.
For longer recordings, specify the time_window argument for the start and end time
of the recording to be shown.
from ndx_sound.widgets import plot_sound
plot_sound(nwbfile.stimulus["acoustic_stimulus"])
# Show only from 5 to 15 seconds
plot_sound(nwbfile.stimulus["acoustic_stimulus"], time_window=(5, 15))
Use acoustic_waveform_widget to include an Audio element that plays the sound.
from ndx_sound.widgets import acoustic_waveform_widget
acoustic_waveform_widget(nwbfile.stimulus["acoustic_stimulus"], time_window=(5, 15))
Interactive widgets
Use AcousticWaveformWidget to use a slider for interactively scrolling through the
recording and a button for changing the duration of the sound that is being shown.
from ndx_sound.widgets import AcousticWaveformWidget
AcousticWaveformWidget(nwbfile.stimulus["acoustic_stimulus"])
nwbwidgets
Use load_widgets to load the interactive sound widget into nwb2widget.
from ndx_sound.widgets import load_widgets
from nwbwidgets import nwb2widget
load_widgets()
nwb2widget(nwbfile)
nwbwidgets and HDF5IO
When using nwb2widget with an NWB file that is read from disk, make sure to have
load_widgets imported within the same Jupyter cell where your data is being loaded.
from pynwb import NWBHDF5IO
from ndx_sound.widgets import load_widgets
from nwbwidgets import nwb2widget
load_widgets()
io = NWBHDF5IO("audio.nwb", mode="r", load_namespaces=True)
nwbfile = io.read()
nwb2widget(nwbfile)
This extension was created using ndx-template.
Metadata
Release files for ndx-sound 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ndx_sound-0.3.0.tar.gz | 15.9 kB | Without provenance | Details for ndx_sound-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ndx_sound-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for ndx_sound-0.3.0-py3-none-any.whl |
Total release size: 23.9 kB
Release files / ndx_sound-0.3.0.tar.gz
| Download URL | ndx_sound-0.3.0.tar.gz |
|---|---|
| Size | 15.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b08e41420f727927659f577e3251499ac75a70580be17ee5b98c729c0f6fa426
|
|
BLAKE2b-256 checksum How to use checksums |
3f26d08c5edc833e7aef8dd79383815c2f582bd7c1cdb55fb0754911ab2e3f21
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / ndx_sound-0.3.0-py3-none-any.whl
| Download URL | ndx_sound-0.3.0-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e916ba172031e430d3b2aebcea4a753eb646ac561ff2fd7862ea8a9810bc1961
|
|
BLAKE2b-256 checksum How to use checksums |
b7ed54b2f776e4659aa6fb7e0b03d895b4b11fa1cfc36013d84a140ae85755c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for ndx-sound 0.3.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.