pyampact.alignment.run_DTW_alignment
- pyampact.alignment.run_DTW_alignment(y, original_sr, piece, tres, width, target_sr, nharm, win_ms, hop, nmat, showSpec)[source]
Perform a dynamic time warping (DTW) alignment between an audio file and its corresponding MIDI file.
This function returns the aligned onset and offset times with corresponding MIDI note numbers, as well as the spectrogram of the audio and other DTW-related data.
- Parameters:
y (ndarray) – Audio time series of the file.
original_sr (int) – Original sample rate of the audio file.
piece (Score) – A Score instance containing the symbolic (MIDI) data.
tres (float) – Time resolution for MIDI-to-spectrum information conversion.
width (float) – Width parameter for the DTW alignment.
target_sr (int) – Target sample rate for resampling the audio (if needed).
nharm (int) – Number of harmonics to include in the analysis.
win_ms (float) – Window size in milliseconds for analysis.
hop (int) – Number of samples between successive frames for analysis.
nmat (DataFrame) – DataFrame containing note matrix (nmat) data before alignment.
showSpec (bool) – If True, displays the spectrogram of the audio file.
- Returns:
align (dict) – MIDI-audio alignment structure from DTW containing: - ‘on’: Onset times of the notes. - ‘off’: Offset times of the notes. - ‘midiNote’: MIDI note numbers corresponding to the aligned notes.
spec (ndarray) – Spectrogram of the audio file.
dtw (dict) – A dictionary of DTW returns, including: - ‘M’: The map such that M[:,m] corresponds to the alignment. - ‘MA/RA’: Path from dynamic programming (DP) for MIDI-audio alignment. - ‘S’: Similarity matrix used in the alignment process. - ‘D’: Spectrogram of the audio. - ‘notemask’: The MIDI-note-derived mask used in the alignment. - ‘pianoroll’: MIDI-note-derived piano roll.
nmat (DataFrame) – Updated DataFrame containing the note matrix (nmat) data after alignment.