NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

naplib-python: Neural Acoustic Data Processing and Analysis Tools in Python

Gavin Mischler, Vinay Raghavan, Menoua Keshishian, Nima MesgaraniarXiv 2023 · DOI

Abstract

Recently, the computational neuroscience community has pushed for more transparent and reproducible methods across the field. In the interest of unifying the domain of auditory neuroscience, naplib-python provides an intuitive and general data structure for handling all neural recordings and stimuli, as well as extensive preprocessing, feature extraction, and analysis tools which operate on that data structure. The package removes many of the complications associated with this domain, such as varying trial durations and multi-modal stimuli, and provides a general-purpose analysis framework that interfaces easily with existing toolboxes used in the field.

Introduction

Auditory neuroscience presents unique data challenges. Unlike many other fields, experiments often involve naturalistic stimuli—like speech or music—where trials vary significantly in duration. Furthermore, researchers must juggle multi-modal data: raw neural recordings (EEG, iEEG, ECoG), acoustic waveforms, time-frequency representations, and linguistic metadata like transcripts or phoneme labels.

Historically, the tools to handle this were scattered across different languages (like the MATLAB-based NAPlib) or were too general-purpose to handle auditory-specific needs like linguistic alignment. This fragmentation leads to "bespoke" code for every lab, making it difficult to reproduce results or collaborate across disciplines. naplib-python aims to be the "standard toolbox" that bridges these gaps.

The Data Object and Methodology

The core of the library is the Data object, a flexible container reminiscent of a pandas DataFrame but optimized for neuroscience. It stores any number of trials and fields (e.g., "resp" for neural responses, "stim" for audio) without enforcing equal durations across trials. This structure is specifically designed to handle the non-uniformity of naturalistic stimuli.

The naplib-python Data object structure, organizing trials and multi-modal fields.

Key modules include:

  • Features: Implements auditory spectrograms (modeling the inner ear) and provides a forced aligner (based on Prosodylab-Aligner) to automatically map speech audio to phonetic and word-level timing.
  • Encoding: Features a robust Temporal Receptive Field (TRF) class. While it defaults to cross-validated ridge regression, it is designed to be compatible with the scikit-learn API, allowing users to swap in L1-regularized or non-linear models easily.
  • Preprocessing: Specialized tools for intracranial data, such as extracting high-gamma envelopes via filter banks and Hilbert transforms.
  • Segmentation: Methods to "slice" continuous data based on aligned labels, such as isolating neural responses to the onset of every phoneme in a sentence.

The library also emphasizes native support for the Brain Imaging Data Structure (BIDS), the gold standard for organizing neuroimaging data. This allows researchers to import complex, multi-trial datasets into a naplib-python analysis pipeline with a single line of code.

Ecosystem Integration and Key Insights

naplib-python acts as "glue" software. It doesn't try to reinvent the wheel; instead, it provides a high-level interface that integrates existing powerhouses like MNE-Python (for visualization), NEMS (for encoding), and scikit-learn (for machine learning).

By moving away from rigid, fixed-length "epochs" common in other EEG tools, naplib-python is uniquely suited for naturalistic speech research where a "trial" might be a 5-second sentence or a 5-minute story. This unified API lowers the barrier to entry for tasks that previously required deep expertise in signal processing or linguistics, such as phonetic feature extraction or fitting forward/backward STRF models.

Impact and Future Directions

While naplib-python is a software framework rather than a benchmarking study, its utility is already proven. It was a critical component in recent peer-reviewed research on noise adaptation mechanisms in the auditory cortex (Mischler et al., 2022). Common analysis pipelines that previously required hundreds of lines of custom code can now be executed in just a few lines.

The authors identify two primary areas for improvement: memory efficiency and output flexibility. Currently, all operations are performed in-memory, which can be inefficient for massive datasets. Future work includes implementing dynamic data loading, which would allow the library to load and save individual trial data on the fly, enabling the analysis of datasets larger than a computer's RAM.

Software Availability

The package is open-source and maintained via GitHub, supporting a wide range of operating systems and dependencies.

Software metadata and repository information for naplib-python.

Summary updated

BibTeX
@misc{mischler2023naplib,
  author = {Gavin Mischler and Vinay Raghavan and Menoua Keshishian and Nima Mesgarani},
  title = {{naplib-python: Neural Acoustic Data Processing and Analysis Tools in Python}},
  year = {2023},
  eprint = {2304.01799},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2304.01799},
}
Figure