Skip to content

About

A Python library for Real-time Music Alignment

Resources

Contributing

Stars

94 stars

Watchers

5 watching

Forks

Repository files navigation

Matchmaker

GitHub release PyPI version Unit Tests

Matchmaker is a Python library for real-time music alignment.

Music alignment is a fundamental MIR task, and real-time music alignment is a necessary component of many interactive applications (e.g., automatic accompaniment systems, automatic page turning).

Unlike offline alignment methods, for which state-of-the-art implementations are publicly available, real-time (online) methods have no standard implementation, forcing researchers and developers to build them from scratch for their projects.

We aim to provide efficient reference implementations of score followers for use in real-time applications which can be easily integrated into existing projects.

The full documentation for matchmaker is available online at readthedocs.org.

Setup

Python version: 3.10, 3.11, 3.12, 3.13

Choose the installation that fits your use case:

I want to... Install
Get started quickly — test with recorded audio or MIDI files pip install pymatchmaker
Use a locally connected microphone or MIDI keyboard pip install pymatchmaker[devices]
Develop or contribute to matchmaker pip install -e ".[dev]" (see below)

Option 1: Base install

pip install pymatchmaker

Supports simulation mode: run online alignment against recorded audio or MIDI performance files.

Note: Requires Fluidsynth to be installed on your system:

conda install -c conda-forge fluidsynth

conda-forge has no Fluidsynth package for Windows; see Installing Fluidsynth on Windows.

Option 2: Live device support

pip install pymatchmaker[devices]

Adds PyAudio and python-rtmidi for real-time input from a locally connected microphone or MIDI keyboard.

Note: pyaudio requires PortAudio to be installed on your system:

conda install -c conda-forge fluidsynth portaudio

On Windows, the pyaudio wheels already include PortAudio, so only Fluidsynth is needed.

Option 3: Development install (from source)

For contributors or anyone who wants to modify the source code. Requires conda.

# Clone the repository
git clone https://github.com/pymatchmaker/matchmaker.git
cd matchmaker

# Create and activate a conda environment
conda create -n matchmaker python=3.12
conda activate matchmaker

# Install system dependencies (Linux and macOS; on Windows, see below)
conda install -c conda-forge gcc=12.1.0 glib fluidsynth portaudio

# Install matchmaker in editable mode with all dev dependencies (includes [devices])
pip install -e ".[dev]"

On Windows, skip the system dependencies step: conda-forge has neither gcc=12.1.0 nor Fluidsynth for Windows, and none of these packages are needed there. Instead, install the Visual C++ build tools to compile the Cython extensions and install Fluidsynth from its release ZIP. The rest of the steps are the same, in a conda environment or a plain venv.

Note: partitura will download MuseScore_General.sf3 (a free soundfont) on first use. This may take a moment.

Known Setup Issues

Missing Visual C++ build tools (on Windows)

Building from source (pip install -e ., or the sdist) fails with Microsoft Visual C++ 14.0 or greater is required if no C++ compiler is installed. Having Visual Studio installed is not enough; it also needs the C++ workload. Install the build tools with winget:

winget install --id Microsoft.VisualStudio.2022.BuildTools --override "--quiet --wait --norestart --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"

Or download vs_BuildTools.exe from https://visualstudio.microsoft.com/visual-cpp-build-tools/ and run:

vs_buildtools.exe --norestart --passive --downloadThenInstall --includeRecommended --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Workload.MSBuildTools

Installing Fluidsynth on Windows

Without Fluidsynth, import fluidsynth raises ImportError("Couldn't find the FluidSynth library."). pyfluidsynth looks for libfluidsynth-3.dll in C:\tools\fluidsynth\bin and on PATH:

  1. Download the ZIP for your architecture (e.g. fluidsynth-v2.6.1-win10-x64-cpp11.zip) from https://github.com/FluidSynth/fluidsynth/releases/latest.
  2. Extract it and rename the extracted folder (e.g. fluidsynth-v2.6.1-win10-x64-cpp11) to C:\tools\fluidsynth, so that the DLL is at C:\tools\fluidsynth\bin\libfluidsynth-3.dll. Alternatively, put the folder anywhere and add its bin directory to PATH.
  3. Check with python -c "import fluidsynth".

With Chocolatey, choco install fluidsynth installs it to C:\tools\fluidsynth as well.

Using Fluidsynth installed from Homebrew on macOS

We recommend installing Fluidsynth via conda in a dedicated environment. If you use the Homebrew-installed Fluidsynth instead, you may encounter ImportError("Couldn't find the FluidSynth library.") with pyfluidsynth. See this Stack Overflow answer for a fix.

Usage Examples

Quickstart (simulation mode)

You can test the alignment with a score and a performance file. No extra dependencies needed beyond the base install.

from matchmaker import Matchmaker

mm = Matchmaker(
    score_file="path/to/score.musicxml",
    performance_file="path/to/performance.wav",
    input_type="audio",
)
for current_position in mm.run():
    print(current_position)  # beat position in the score

The returned value is the current position in the score, represented in beats defined by partitura library's note array system. Specifically, each position is calculated for every frame input and interpolated within the score's onset_beat array. Please refer to here for more information about the onset_beat concept.

Live streaming (requires [devices])

To run with a live audio or MIDI input, install with pip install pymatchmaker[devices].

mm = Matchmaker(
    score_file="path/to/score.musicxml",
    input_type="audio",
    device_name_or_index="MacBookPro Microphone",
)
for current_position in mm.run():
    print(current_position)

If no device is specified, the system default is used.

from matchmaker import Matchmaker

# Audio input
mm = Matchmaker(
    score_file="path/to/score.musicxml",
    input_type="audio",
)

# MIDI input
mm = Matchmaker(
    score_file="path/to/score.musicxml",
    input_type="midi",
)

Streaming from a non-device source (BytesAudioStream / BytesMidiStream)

For input that does not come from a local audio / MIDI device (a WebSocket handler forwarding browser data, a subprocess, an IPC pipe, etc.), use the built-in BytesAudioStream and BytesMidiStream classes. Both pull raw bytes chunks from a queue.Queue you control and feed them through the same processor pipeline as the device-backed streams. No pyaudio or python-rtmidi install is required.

Audio. The producer pushes raw float32 PCM bytes (one hop_length chunk per item), followed by None to end the stream:

import queue
from matchmaker import Matchmaker
from matchmaker.io.audio import BytesAudioStream
from matchmaker.features.audio import ChromagramProcessor

data_queue = queue.Queue()

# In a producer thread (e.g. WebSocket handler):
#     data_queue.put(pcm_chunk_bytes)   # float32 PCM, hop_length samples
#     ...
#     data_queue.put(None)              # end of stream

stream = BytesAudioStream(
    processor=ChromagramProcessor(sample_rate=22050, hop_length=441),
    sample_rate=22050,
    hop_length=441,
    data_queue=data_queue,
)
mm = Matchmaker(
    score_file="path/to/score.musicxml",
    input_type="audio",
    stream=stream,
)
for current_position in mm.run():
    print(current_position)

MIDI. The producer pushes raw MIDI bytes (e.g. 3 bytes per note_on / note_off, exactly what the Web MIDI API gives you):

import queue
from matchmaker import Matchmaker
from matchmaker.io.midi import BytesMidiStream
from matchmaker.features.midi import PitchProcessor

data_queue = queue.Queue()

# In a producer thread:
#     data_queue.put(midi_bytes)   # e.g. bytes([0x90, 60, 100])
#     ...
#     data_queue.put(None)

stream = BytesMidiStream(processor=PitchProcessor(), data_queue=data_queue)
mm = Matchmaker(
    score_file="path/to/score.musicxml",
    input_type="midi",
    stream=stream,
)
for current_position in mm.run():
    print(current_position)

The browser side just forwards what Web MIDI API hands it:

const midiAccess = await navigator.requestMIDIAccess();
midiAccess.inputs.forEach((input) => {
  input.onmidimessage = (event) => {
    // event.data is a Uint8Array (typically 3 bytes for note_on / note_off)
    ws.send(event.data);   // forward as a binary WebSocket frame
  };
});

The Python WebSocket handler reads the binary frame and calls data_queue.put(message_bytes). No JSON / dict / base64 conversion is needed at any layer.

Running Examples

The repository includes a ready-to-use example script that demonstrates the complete workflow:

# Run with input type (uses default method by each input)
python run_examples.py --audio

# Run with specific method
python run_examples.py --midi --method hmm

This script runs a complete example with score following and evaluation, saving results to the results/ directory.

Evaluation output

Field Meaning
mean_b, median_b, std_b Mean, median, and standard deviation of the absolute score-position error, in beats.
accuracy_0.05b, accuracy_0.1b, accuracy_0.3b, accuracy_0.5b, accuracy_1b, accuracy_2b Fraction of annotated onsets within each beat-error tolerance.
skewness, kurtosis Unitless statistics describing the asymmetry and tail weight of the signed score-position error distribution.
smoothness Trajectory smoothness measured with SPARC. Higher (less negative) values indicate smoother motion.
rtf Alignment runtime divided by the annotated performance span. Lower values mean faster processing.
feature_latency_ms, inference_latency_ms Mean feature-extraction and inference time per frame, in milliseconds; reported for audio input.

matchmaker.utils.eval.evaluate_alignment() returns the accuracy and smoothness fields directly; the example script adds runtime and latency measurements.

smoothness measures the smoothness of the alignment path using SPARC (Spectral Arc Length), with higher (less negative) values indicating smoother tracking. Smoothness depends on how positions are reported; compare values only within the same input type (audio or MIDI).

Testing with Different Methods or Features

You can specify the alignment method and feature processor as follows:

from matchmaker import Matchmaker

mm = Matchmaker(
    score_file="path/to/score",
    input_type="audio",
    method="arzt",       # see Alignment Methods section
    processor="chroma",  # see Features section
)
for current_position in mm.run():
    print(current_position)

For options regarding the method, please refer to the Alignment Methods section. For options regarding the processor, please refer to the Features section.

Package Overview

Matchmaker has the following pipeline:

   input source              Stream              Processor              OnlineAlignment
   (audio/MIDI                                   (chroma,               (e.g.,
    file or live)      ─►   AudioStream    ─►    pitch,          ─►    PitchHMM,        ─►   alignment_path
                            MidiStream           ...)                   OLTWArzt, ...)        (2, T) array

Component signatures

  • Stream (AudioStream, MidiStream) reads from a file or live device, hands each frame to its Processor, and pushes the result to a RECVQueue, followed by a STREAM_END sentinel when the source is exhausted.

  • Processor (e.g., ChromagramProcessor, PitchProcessor) takes a (data, frame_time) tuple and returns either a (features, perf_time) tuple or None while buffering. data is np.ndarray for audio or List[(mido.Message, m_time)] for MIDI; perf_time is the timestamp the feature corresponds to (most processors pass frame_time through; MIDI processors that emit note or chord observations, such as PitchProcessor and ChordOnsetProcessor, stamp it with the first note-on time).

  • OnlineAlignment (the score follower base class; e.g., OnlineTimeWarpingArzt, PitchIOIHMM) consumes (features, perf_time) observations from the queue (or directly via __call__), updates its score position per step, and yields the current beat. On stream end it returns the final alignment_path — a (2, T) np.ndarray of (perf_time, score_beat) pairs.

STREAM_END is a module-level sentinel (not a tuple); OnlineAlignment.run() checks for it and exits the read loop.

Score representation

The example score matchmaker/assets/simple_mozart_k265_var1.musicxml is used in tests and the contribution guide. The first two measures:

Beat positions follow the onset_beat field of partitura's note_array(), whose unit is the score's denominator (the quarter note for this 2/4 piece). Notes start at beats 0.00, 0.25, 0.50, 0.75, 1.00, ....

import numpy as np
import partitura as pt

score = pt.load_score("matchmaker/assets/simple_mozart_k265_var1.musicxml")
note_array = score[0].note_array()
score_positions = np.unique(note_array["onset_beat"])
# array([0.  , 0.25, 0.5 , 0.75, 1.  , ..., 13.25, 13.5 ])  shape (54,)

If a score follower reaches the third unique onset:

follower.current_index    # 2
follower.current_position # 0.5  (= score_positions[2])

Alignment Methods

Methods and processors are declared in matchmaker/methods.yaml — the authoritative list is matchmaker.AVAILABLE_METHODS. Adding one is described in HOW_TO_MAKE_CUSTOM_SCORE_FOLLOWERS.md.

Audio (input_type="audio")

Default method: "arzt"

Method Description
"arzt" On-line time warping by Arzt et al. (2008), extending Dixon (2005)
"dixon" On-line time warping by Dixon (2005)
"outerhmm" Two-level HMM with repeats and skips by Nakamura et al. (2016)
"skf" Switching Kalman Filter with hidden tempo by Jiang and Raphael (2020)
"arzt_tempo" On-line time warping by Arzt with a tempo model (Arzt and Widmer, 2010)
"arzt_multi_fold" Arzt OLTW tracking several unfolded score variants in parallel
"pfkorz" Particle filter score follower by Korzeniowski et al. (2013)

MIDI (input_type="midi")

Default method: "pthmm"

Method Description
"arzt" On-line time warping by Arzt et al. (2008), extending Dixon (2005)
"dixon" On-line time warping by Dixon (2005)
"outerhmm" Outer-product HMM score follower by Nakamura et al. (2014)
"hmm" HMM score follower by Cancino-Chacón et al. (2023)
"pthmm" Pitch-based HMM score follower
"pfkorz" Particle filter score follower by Korzeniowski et al. (2013)
"dannenberg" Dynamic-programming score follower by Bloch and Dannenberg (1985)
"SL_OLTW" Symbolic-level OLTW note matcher from parangonar (Peter et al., 2025)
"SLT_OLTW" Symbolic-level OLTW note matcher with tempo, from parangonar (Peter et al., 2025)
"OTM" Online transformer note matcher from parangonar (Peter, 2023)
"OPTM" Online pure-transformer note matcher from parangonar (Peter, 2023)

The parangonar methods match one performed note at a time, so they always run event-based (no MIDI polling).

Features

Audio (input_type="audio")

Default processor: "chroma". Some methods default to their own processor (e.g. "dixon" → "lse"); see default_kwargs in methods.yaml.

Processor Description
"chroma" Chroma features
"mfcc" Mel-frequency cepstral coefficients
"cqt" Constant-Q transform
"mel" Mel-spectrogram
"lse" Log-spectral energy features used in Dixon (2005)
"cqt_spectral_flux" CQT-based spectral flux used in Nakamura et al. (2016)
"raw_spectrum" Raw power spectrum used in Jiang and Raphael (2020)
"korzeniowski" Spectral observations for the Korzeniowski et al. (2013) particle filter

MIDI (input_type="midi")

Default processor: "pitch". Some methods default to their own processor (e.g. MIDI "arzt" / "dixon" → "chord_onset").

Processor Description
"pitch" Binary pitch vector of the note-ons in each MIDI frame (a chord when MIDI polling groups notes)
"chord_onset" Binary pitch vector per chord, merging note-ons that arrive within 35 ms
"pianoroll" Piano-roll of the notes held in each frame
"pitchclass" Pitch-class (12-bin) piano-roll
"korzeniowski" Note observations for the Korzeniowski et al. (2013) particle filter
"parangonar" One partitura note-array row per performed note, for the parangonar methods

Configurations

Initialization parameters for the Matchmaker class:

Parameter Type Default Description
score_file str Path to the score file (.musicxml, .mid, etc.)
performance_file str or None None Path to a recorded performance file for simulation mode. If None, live device input is used.
input_type str "audio" Input modality. Options: "audio", "midi".
method str or None None Alignment method. Defaults to "arzt" for audio, "pthmm" for MIDI. See Alignment Methods.
processor str or None None Feature processor. Defaults to the method's own processor, else "chroma" for audio and "pitch" for MIDI. See Features.
kwargs dict or None None Method-specific parameters (e.g., window_size, sample_rate, frame_rate). If None, built-in defaults for the chosen method are used.
stream Stream or None None Custom Stream instance for external input sources (e.g., WebSocket). If None, the stream is built automatically from input_type.
device_name_or_index str or int or None None Audio/MIDI device name or index for live input. Requires pymatchmaker[devices].
tempo float or None None Initial tempo in BPM for score rendering. If None, inferred from the score.
wait bool False Audio simulation mode only. If True, the performance file is streamed at real-time speed instead of as fast as possible.
unfold_score bool True If True, unfold repeat signs in the score before alignment.

Contributing

For issues, branches and pull requests, see CONTRIBUTING.md. If you want to add a new score follower, please refer to HOW_TO_MAKE_CUSTOM_SCORE_FOLLOWERS.md for the OnlineAlignment interface, boilerplate, and audio/MIDI tips. The same guide is also available in the online docs.

Citing Matchmaker

If you find Matchmaker useful, we would appreciate if you could cite us!

@inproceedings{park_matchmaker_2025,
  title     = {{Matchmaker}: An Open-Source Library for Real-Time Piano Score Following and Systematic Evaluation},
  booktitle = {Proceedings of the 26th International Society for Music Information Retrieval Conference ({ISMIR})},
  author    = {Park, Jiyun and Cancino-Chac{\'o}n, Carlos and Chiruthapudi, Suhit and Nam, Juhan},
  address   = {Daejeon, South Korea},
  year      = {2025}
}
@inproceedings{matchmaker_lbd,
  title     = {{Matchmaker}: A {Python} Library for Real-Time Music Alignment},
  booktitle = {Proceedings of the Late Breaking/Demo Session at the 25th International Society for Music Information Retrieval Conference ({ISMIR})},
  author    = {Park, Jiyun and Cancino-Chac{\'o}n, Carlos and Kwon, Taegyun and Nam, Juhan},
  address   = {San Francisco, USA},
  year      = {2024}
}

Acknowledgments

This work has been supported by the Austrian Science Fund (FWF), grant agreement PAT 8820923 (Rach3: A Computational Approach to Study Piano Rehearsals) and PIN 1347924 (AURA: Augmenting musical interaction via EVAs), as well as by the European Research Council (ERC) under the EU’s Horizon 2020 research & innovation programme, grant agreement No.101019375 (Whither Music?), and by the National Research Foundation of Korea (NRF) grant funded by the Korea government (MSIT) under Grant RS-2023-NR077289.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

About

A Python library for Real-time Music Alignment

Resources

Contributing

Stars

94 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages