pyampact.alignment.run_alignment

pyampact.alignment.run_alignment(y, original_sr, piece, nmat, width=3, target_sr=4000, nharm=3, win_ms=100, hop=32, showSpec=False)[source]
Parameters:
  • y (ndarray) – Audio time series.

  • original_sr (int) – Original sample rate of the audio file.

  • piece (Score) – A Score instance containing the symbolic MIDI data.

  • means (ndarray) – Mean values for each state in the alignment process.

  • covars (ndarray) – Covariance values for each state in the alignment process.

  • 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 the analysis.

  • hop (int) – Number of samples between successive frames.

  • showSpec (bool) – If True, displays the spectrogram of the audio.

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.

  • dtw (dict) – A dictionary of DTW returns, including: - ‘M’: The map such that M[:,m] corresponds to the alignment. - ‘MA’: Path from dynamic programming (DP) for MIDI-audio alignment. - ‘RA’: Path from DP for real 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.

  • spec (ndarray) – Spectrogram of the audio file.

  • newNmat (DataFrame) – Updated DataFrame containing the note matrix (nmat) data after alignment.

Notes

This function leverages DTW to align MIDI note information with the time series audio signal. It computes onset and offset times and updates the alignment using a similarity matrix. Optionally, it can display the audio spectrogram for visual analysis.