from midiutil import MIDIFile ### Change the following two lists with correct values, ### based on your animation and the sound requirements. frame_numbers = [17, 34, 46, 56, 66, 77] sound_notes = [96, 100, 103, 107, 110, 90] output_path = "C:\MyTest\sound.mid" duration = 0.1 # In beats tempo = 120 # In BPM volume = 100 # 0-127, as per the MIDI standard ### No need to change anything below this line. ############################################################ track = 0 channel = 0 time = [] for i in range(len(frame_numbers)): time.append(frame_numbers[i]/15) MyMIDI = MIDIFile(1) MyMIDI.addTempo(track, time[0], tempo) for i, pitch in enumerate(sound_notes): MyMIDI.addNote(track, channel, pitch, time[i], duration, volume) with open(output_path, "wb") as output_file: MyMIDI.writeFile(output_file)