spotify / basic-pitch

A lightweight yet powerful audio-to-MIDI converter with pitch bend detection
https://basicpitch.io
Apache License 2.0
3.33k stars 255 forks source link

Notes in MIDI output are different in python program compared to the demo website #134

Open pulsar666 opened 1 month ago

pulsar666 commented 1 month ago

Description: I'm experiencing an issue where the MIDI output generated by the basic_pitch library on my local machine has a lot of off notes. However, when I use the demo website, the notes seem to be correct. This appears to be similar to the issue discussed in #[126], but I'm still encountering the problem.

Environment:

Steps to Reproduce:

  1. Install the required packages:

    pip install basic_pitch[tf]
  2. Use the following script to convert an audio file to MIDI:

    import os
    from basic_pitch.inference import predict_and_save
    from basic_pitch import ICASSP_2022_MODEL_PATH
    
    def convert_to_midi(audio_file, output_directory):
        print(audio_file)
        # Verify the file exists
        if not os.path.exists(audio_file):
            raise FileNotFoundError(f"File not found: {audio_file}")
    
        try:
            predict_and_save(
                audio_path_list=[audio_file],  # <input-audio-path-list>
                output_directory=output_directory,  # <output-directory>
                save_midi=True,  # <save-midi>
                sonify_midi=False,  # <sonify-midi>
                save_model_outputs=True,  # <save-model-outputs>
                save_notes=True,  # <save-notes>
                model_or_model_path=ICASSP_2022_MODEL_PATH,
                minimum_note_length=11,
                maximum_frequency=3000.0,  # Maximum Pitch
            )
        except Exception as e:
            print(f"Error reading or converting audio file: {e}")
            raise
    
    output_dir = 'output'
    convert_to_midi("E:/Data/pycharm_projects/azimuth-melody-extraction-v2/output_directory/test-audio.wav", output_dir)
    print(f"MIDI file is saved at {output_dir}")
  3. Compare the MIDI output generated by the script with the output generated by the demo website.

Expected behavior: The MIDI output generated by the script should have the correct notes, similar to the output generated by the demo website.

Actual behavior: The MIDI output generated by the script has a lot of off notes.

Additional context:


Would be great if anyone can tell me how to get the exact output that is produced by the demo website: basic pitch demo

pulsar666 commented 1 month ago

anyone that can help with correct settings for the predict_and_save() that will produce the same output as the demo site?

pulsar666 commented 1 month ago

I believe the python version is causing is. I tried with 3.10 and the notes do overlap with what is being produced by the demo site, although the pitch velocities are definitely different

drubinstein commented 4 weeks ago

Hi and thanks for your interest in Basic Pitch.

A few follow up questions:

If you have an audio file you could share that'd also be great. It looks like the velocities in basic-pitch and basic-pitch-ts could be slightly different.