Getting Started

bayesian_listener simulates and fits a Bayesian model of human sound localisation from individual head-related transfer functions (HRTFs).

With this package you can:

  • Simulate predicted sound-localisation responses for any HRTF, returning a full response distribution over all source directions.

  • Fit the model to measured behavioural data to estimate listener-specific noise parameters via maximum likelihood.

Installation

pip install bayesian_listener

Note

Requires Python 3.10 or higher. For the statistical framework see Model and Statistical Framework.

Minimal working example

The example below downloads a single listener’s HRTF from the SONICOM dataset, computes the auditory features, runs Bayesian inference across all measured source directions, and adds motor noise to produce simulated pointing responses.

import urllib.request
from bayesian_listener import BayesianListener

# Download one SONICOM HRTF (≈ 10 MB; runs once).
sofa_path = "P0001_FreeFieldCompMinPhase_48kHz.sofa"
urllib.request.urlretrieve(
    "https://transfer.ic.ac.uk:9090/2022_SONICOM-HRTF-DATASET/"
    "P0001/HRTF/HRTF/48kHz/" + sofa_path,
    sofa_path,
)

listener = BayesianListener(sofa_path)
responses = listener.localise(repetitions=10)

# responses is a pyfar.Coordinates object (azimuth, elevation, radius).
print(responses.spherical_elevation[:5])

Note

localise builds the template on the first call (a few seconds); results are cached automatically so subsequent calls return immediately.

What to do next