Module Expr Str Import alias Import alias Import alias identifier Import alias Import alias Import alias Assign NameStore Num Assign NameStore Num Assign NameStore Num Assign NameStore Num FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad keyword NameLoad keyword NameLoad keyword Call AttributeLoad NameLoad attr NameLoad keyword NameLoad Assign NameStore AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr NameLoad keyword Call AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad keyword Num keyword Num Assign NameStore Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr SubscriptLoad AttributeLoad NameLoad attr Index Num NameLoad NameLoad Return TupleLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr keyword NameLoad Assign TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad NameLoad NameLoad NameLoad Assign TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad NameLoad NameLoad NameLoad Assign NameStore BinOpSub Num Call AttributeLoad NameLoad attr NameLoad AttributeLoad NameLoad attr If CompareIs NameLoad NameLoad body Assign NameStore Call AttributeLoad NameLoad attr Assign TupleStore NameStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad keyword Num keyword NameLoad Expr Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index NameLoad SubscriptLoad NameLoad Index NameLoad decorator_list If CompareEq NameLoad Str body Assign NameStore Call AttributeLoad NameLoad attr keyword Str keyword AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword NameLoad keyword NameLoad keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword NameLoad keyword NameLoad keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword NameLoad keyword NameLoad keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword NameLoad keyword NameLoad keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword NameLoad keyword NameLoad keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword NameLoad keyword NameLoad keyword Str keyword Str Assign NameStore Call NameLoad Call AttributeLoad NameLoad attr SubscriptLoad AttributeLoad NameLoad attr Slice Num Print Call AttributeLoad Str attr SubscriptLoad NameLoad Index Str Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index Str keyword SubscriptLoad NameLoad Index Str Print Call AttributeLoad Str attr SubscriptLoad NameLoad Index Str Assign NameStore Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index Str Print Call AttributeLoad Str attr SubscriptLoad NameLoad Index Str SubscriptLoad NameLoad Index Str Expr Call NameLoad NameLoad NameLoad SubscriptLoad NameLoad Index Str SubscriptLoad NameLoad Index Str SubscriptLoad NameLoad Index Str SubscriptLoad NameLoad Index Str SubscriptLoad NameLoad Index Str Print Call AttributeLoad Str attr SubscriptLoad NameLoad Index Str Expr Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index Str If SubscriptLoad NameLoad Index Str body Print Call AttributeLoad Str attr SubscriptLoad NameLoad Index Str Assign NameStore Call AttributeLoad NameLoad attr keyword SubscriptLoad NameLoad Index Str If CompareGt SubscriptLoad AttributeLoad NameLoad attr Index Num SubscriptLoad AttributeLoad NameLoad attr Index Num body Assign NameStore SubscriptLoad NameLoad Slice SubscriptLoad AttributeLoad NameLoad attr Index Num orelse Assign NameStore BinOpSub SubscriptLoad AttributeLoad NameLoad attr Index Num SubscriptLoad AttributeLoad NameLoad attr Index Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr SubscriptLoad NameLoad Index Str Call AttributeLoad NameLoad attr ListLoad NameLoad NameLoad SubscriptLoad NameLoad Index Str
N/A N/A 
Example audio-to-MIDI alignment script.
Requires djitw https://github.com/craffel/djitw/
and librosa >= 0.4 https://github.com/bmcfee/librosa/
 N/A djitw N/A librosa N/A numpy np N/A sys N/A argparse N/A pretty_midi N/A FS 22050 N/A HOP 512 N/A NOTE_START 36 N/A N_NOTES 48 extract_cqt N/A N/A audio_data fs hop note_start n_notes N/A N/A N/A 
    Compute a log-magnitude L2-normalized constant-Q-gram of some audio data.

    Parameters
    ----------
    audio_data : np.ndarray
        Audio data to compute CQT of
    fs : int
        Sampling rate of audio
    hop : int
        Hop length for CQT
    note_start : int
        Lowest MIDI note number for CQT
    n_notes : int
        Number of notes to include in the CQT

    Returns
    -------
    cqt : np.ndarray
        Log-magnitude L2-normalized CQT of the supplied audio data.
    frame_times : np.ndarray
        Times, in seconds, of each frame in the CQT
     N/A cqt N/A N/A librosa cqt audio_data sr fs hop_length hop fmin N/A N/A librosa midi_to_hz note_start n_bins n_notes N/A cqt N/A cqt T N/A cqt N/A N/A librosa logamplitude cqt ref_power N/A N/A cqt max N/A cqt N/A N/A N/A librosa util normalize cqt norm 2.0 axis 1 N/A times N/A N/A librosa frames_to_time N/A N/A np arange N/A N/A cqt shape N/A 0 fs hop N/A N/A cqt times N/A align N/A N/A midi_object audio_data fs hop note_start n_notes penalty N/A N/A N/A 
    Align a MIDI object in-place to some audio data.

    Parameters
    ----------
    midi_object : pretty_midi.PrettyMIDI
        A pretty_midi.PrettyMIDI class instance describing some MIDI content
    audio_data : np.ndarray
        Samples of some audio data
    fs : int
        audio_data's sampling rate, and the sampling rate to use when
        synthesizing MIDI
    hop : int
        Hop length for CQT
    note_start : int
        Lowest MIDI note number for CQT
    n_notes : int
        Number of notes to include in the CQT
    penalty : float
        DTW non-diagonal move penalty
     N/A midi_audio N/A N/A midi_object fluidsynth fs fs N/A N/A midi_gram midi_times N/A extract_cqt midi_audio fs hop note_start n_notes N/A N/A audio_gram audio_times N/A extract_cqt audio_data fs hop note_start n_notes N/A distance_matrix N/A 1 N/A N/A np dot midi_gram N/A audio_gram T N/A N/A penalty None N/A N/A penalty N/A N/A distance_matrix mean N/A N/A p q score N/A N/A djitw dtw distance_matrix gully 0.98 penalty penalty N/A N/A N/A midi_object adjust_times N/A midi_times N/A p N/A audio_times N/A q N/A N/A N/A __name__ __main__ N/A N/A parser N/A N/A argparse ArgumentParser description Align a MIDI file to an audio file. formatter_class N/A argparse ArgumentDefaultsHelpFormatter N/A N/A N/A parser add_argument audio_file action store help Path to the audio file to align to N/A N/A N/A parser add_argument midi_file action store help Path to the MIDI file to align to the audio N/A N/A N/A parser add_argument output_file action store help Path where the aligned MIDI will be written N/A N/A N/A parser add_argument --output_audio default None type str action store help Path where an audio file consisting of the synthesized aligned MIDI in one channel and the audio data in the other will be written N/A N/A N/A parser add_argument --fs default FS type int action store help Global audio sampling rate to use N/A N/A N/A parser add_argument --hop default HOP type int action store help CQT hop length N/A N/A N/A parser add_argument --note_start default NOTE_START type int action store help Lowest CQT MIDI note N/A N/A N/A parser add_argument --n_notes default N_NOTES type int action store help Number of notes in each CQT N/A N/A N/A parser add_argument --penalty default None type float action store help DTW non-diagonal move penalty.  By default, uses the mean of the distance matrix. N/A parameters N/A vars N/A N/A parser parse_args N/A N/A sys argv N/A 1 N/A N/A N/A Loading {} ... format N/A parameters N/A audio_file N/A N/A audio_data _ N/A N/A librosa load N/A parameters N/A audio_file sr N/A parameters N/A fs N/A N/A N/A Loading {} ... format N/A parameters N/A midi_file N/A midi_object N/A N/A pretty_midi PrettyMIDI N/A parameters N/A midi_file N/A N/A N/A Aligning {} to {} ... format N/A parameters N/A audio_file N/A parameters N/A midi_file N/A N/A align midi_object audio_data N/A parameters N/A fs N/A parameters N/A hop N/A parameters N/A note_start N/A parameters N/A n_notes N/A parameters N/A penalty N/A N/A N/A Writing {} ... format N/A parameters N/A output_file N/A N/A N/A midi_object write N/A parameters N/A output_file N/A N/A parameters N/A output_audio N/A N/A N/A N/A Writing {} ... format N/A parameters N/A output_audio N/A midi_audio_aligned N/A N/A midi_object fluidsynth fs N/A parameters N/A fs N/A N/A N/A N/A midi_audio_aligned shape N/A 0 N/A N/A audio_data shape N/A 0 N/A N/A midi_audio_aligned N/A midi_audio_aligned N/A N/A N/A audio_data shape N/A 0 N/A N/A trim_amount N/A N/A N/A audio_data shape N/A 0 N/A N/A midi_audio_aligned shape N/A 0 N/A midi_audio_aligned N/A N/A np append midi_audio_aligned N/A N/A np zeros trim_amount N/A N/A N/A N/A librosa output write_wav N/A parameters N/A output_audio N/A N/A np vstack N/A midi_audio_aligned audio_data N/A parameters N/A fs