Skip to main content

Music Perception Toolbox (Python)

Perceptually and cognitively motivated measures of pitch similarity, consonance, and the structure of scales and rhythms.

The toolbox is available in parallel MATLAB and Python implementations with identical semantics. This package is the Python one; the full repository, including the MATLAB implementation, the User Guide, and the demos, is at https://github.com/andymilne/Music-Perception-Toolbox.

Install

pip install music-perception-toolbox

What it provides

Expectation tensors and their cosine similarity. A weighted multiset of pitches or time points is smoothed into a continuous density over its r-tuples, with a single parameter σ modelling perceptual uncertainty. The density and the cosine similarity of two densities are computed analytically, without discretization, in all four modes (absolute or relative, non-periodic or periodic). The (S)P(C)S family of similarity measures are instances of this.

Consonance and harmonicity. Spectral entropy, template harmonicity, tensor harmonicity, virtual pitch profiles, and Sethares roughness.

Scale and rhythm structure. Circular DFT, balance, evenness, coherence, sameness, n-tuple entropy, edge detection, projected centroid, mean offset, the circular autocorrelation phase matrix, and Markov prediction.

Audio input. Spectral peaks extracted from a recording can be used wherever symbolic pitches can.

Quick example

import numpy as np
import mpt

major = np.array([0.0, 400.0, 700.0])          # cents
minor = np.array([0.0, 300.0, 700.0])

# Spectral pitch class similarity: harmonic partials added, octave-periodic.
spectrum = ["harmonic", 16, "powerlaw", 1.0]
p_a, w_a = mpt.add_spectra(major, None, *spectrum)
p_b, w_b = mpt.add_spectra(minor, None, *spectrum)
d_a = mpt.build_exp_tens(p_a, w_a, 10.0, 1, False, True, 1200)
d_b = mpt.build_exp_tens(p_b, w_b, 10.0, 1, False, True, 1200)
print(mpt.cos_sim_exp_tens(d_a, d_b))

Documentation

The User Guide covers the conceptual foundations and gives a complete function reference for both languages. Nine demo scripts, also provided as Jupyter notebooks, are in python/demos/.

Citation

See CITATION.cff in the repository.

Licence

MIT.

Metadata

Release files for music-perception-toolbox 2.0.3

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

Source distribution (sdist)

Source distribution for music-perception-toolbox 2.0.3
File Size Uploaded
music_perception_toolbox-2.0.3.tar.gz 30.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for music-perception-toolbox 2.0.3
File Interpreter ABI Platform
music_perception_toolbox-2.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 60.3 kB

Release files / music_perception_toolbox-2.0.3.tar.gz

Download URL music_perception_toolbox-2.0.3.tar.gz
Size 30.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7fe16f62ad907dd9e052a82e0aeb021cd9e70e6fb90e1c240303ff13b721707e
BLAKE2b-256 checksum
How to use checksums
635ba9d767075945f5b59fab05c557666bd5e1069bb7a4aa97b9de752438adbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.2

Release files / music_perception_toolbox-2.0.3-py3-none-any.whl

Download URL music_perception_toolbox-2.0.3-py3-none-any.whl
Size 30.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79279d190f1e16f89afa70559bca83b8b69239426265abafa1c197cff08b0d57
BLAKE2b-256 checksum
How to use checksums
23ee149f2c9aff9a2a4753d9015879ae0c788fd82e00534cfa2fc638fa58a2ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

2.0.3 This release

2 release files

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