You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there, this is the issue I was referring to in #13 - reporting anyway even though code isn't here to refer to.
Not sure if this is on purpose or not, but I've noticed there's a mismatch between input audio file duration and the length of the midi data saved to disk. It appears the midi ends right after the final note event. so, in cases where there's a bit of silence at the end of the input audio clip, this silence is left out of the MIDI data.
Not too familiar with mido, but if I understand correctly, we'd just have to add the correct end_of_file event with the correct time tick value.
My current solution is to inject this event into the midi objects like this:
defadd_end_time_to_midi(mid, duration_seconds, default_tempo=500000):
""" Adds an empty event at the end of each track to ensure correct MIDI duration. Args: mid: mido.MidiFile object duration_seconds: desired duration in seconds default_tempo: tempo to use if none found in file (default: 500000 microseconds per beat) Returns: mido.MidiFile with correct end time """# Find tempo from the file or use defaulttempo=default_tempofortrackinmid.tracks:
formsgintrack:
ifmsg.type=='set_tempo':
tempo=msg.tempobreak# Calculate total ticks neededtotal_ticks=int(duration_seconds*1000000*mid.ticks_per_beat/tempo)
fortrackinmid.tracks:
current_ticks=sum(msg.timeformsgintrack)
ifcurrent_ticks<total_ticks:
# Add empty meta message at the endfrommidoimportMetaMessagetrack.append(MetaMessage('end_of_track', time=total_ticks-current_ticks))
returnmid
The text was updated successfully, but these errors were encountered:
Hi there, this is the issue I was referring to in #13 - reporting anyway even though code isn't here to refer to.
Not sure if this is on purpose or not, but I've noticed there's a mismatch between input audio file duration and the length of the midi data saved to disk. It appears the midi ends right after the final note event. so, in cases where there's a bit of silence at the end of the input audio clip, this silence is left out of the MIDI data.
Not too familiar with
mido
, but if I understand correctly, we'd just have to add the correctend_of_file
event with the correct time tick value.My current solution is to inject this event into the midi objects like this:
The text was updated successfully, but these errors were encountered: