Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
np.array([1, 1, 1]),
),
'notes_2',
)
]
note_data_3 = [
(
utils.NoteData(
np.array([[0.0, 0.5, 1.0], [0.5, 1.0, 1.5]]).T,
np.array([1108.731, 1108.731, 1108.731]),
np.array([1, 1, 1]),
),
'notes_1',
),
(
utils.NoteData(
np.array([[0.0, 0.7, 1.0], [0.7, 1.0, 1.5]]).T,
np.array([1108.731, 1108.731, 1108.731]),
np.array([1, 1, 1]),
),
'notes_2',
),
]
note_data_4 = (
utils.NoteData(
np.array([[0.0, 0.5, 1.0], [0.5, 1.0, 1.5]]).T,
np.array([1108.731, 1108.731, 1108.731]),
np.array([1, 1, 1]),
),
None,
)
note_data_5 = [
'audio_path': 'tests/resources/mir_datasets/DALI/'
+ 'audio/4b196e6c99574dd49ad00d56e132712b.mp3',
'audio_url': 'zUzd9KyIDrM',
'dataset_version': 1,
'ground_truth': False,
'language': 'english',
'release_date': '2005',
'scores_manual': 0,
'scores_ncc': 0.9644769596900552,
'title': 'B.Y.O.B.',
'track_id': '4b196e6c99574dd49ad00d56e132712b',
'url_working': True,
}
expected_property_types = {
'notes': utils.NoteData,
'words': utils.LyricData,
'lines': utils.LyricData,
'paragraphs': utils.LyricData,
'annotation_object': DALI.Annotations,
}
run_track_tests(track, expected_attributes, expected_property_types)
path_save = '/home/mfuentes/astre/code/repositories/mirdata/tests/resources/mir_datasets/DALI/annotations'
name = 'test'
track.annotation_object.write_json(path_save, name)
audio, sr = track.audio
assert sr == 48000
assert audio.shape == (94208,)
def _load_note_ann(jams_path, string_num):
"""
Args:
jams_path (str): Path of the jams annotation file
string_num (int), in range(6): Which string to load.
0 is the Low E string, 5 is the high e string.
"""
jam = jams.load(jams_path)
anno_arr = jam.search(namespace='note_midi')
anno = anno_arr.search(data_source=str(string_num))[0]
intervals, values = anno.to_interval_values()
return utils.NoteData(intervals, values, np.ones_like(values))
Convert notes annotations into jams format using note_to_midi from librosa.
Parameters
----------
notes: tuple
A tuple in the format (NoteData, str), where str describes the annotation
and NoteData is the notes mirdata annotation format.
Returns
-------
jannot_notes: JAM note_midi annotation object.
'''
jannot_note = jams.Annotation(namespace='note_hz')
jannot_note.annotation_metadata = jams.AnnotationMetadata(data_source='mirdata')
if notes[0] is not None:
if type(notes[0]) != utils.NoteData:
raise TypeError('Type should be NoteData.')
for beg, end, n in zip(
notes[0].intervals[:, 0], notes[0].intervals[:, 1], notes[0].notes
):
jannot_note.append(time=beg, duration=end - beg, value=n)
if notes[1] is not None:
jannot_note.sandbox = jams.Sandbox(name=notes[1])
return jannot_note
Returns:
note_data (NoteData)
"""
if midi is None:
midi = load_midi(midi_path)
intervals = []
pitches = []
confidence = []
for note in midi.instruments[0].notes:
intervals.append([note.start, note.end])
pitches.append(librosa.midi_to_hz(note.pitch))
confidence.append(note.velocity)
return utils.NoteData(np.array(intervals), np.array(pitches), np.array(confidence))
with gzip.open(annotations_path, 'rb') as f:
output = pickle.load(f)
except Exception as e:
with gzip.open(annotations_path, 'r') as f:
output = pickle.load(f)
text = []
notes = []
begs = []
ends = []
for annot in output.annotations['annot'][granularity]:
notes.append(round(annot['freq'][0], 3))
begs.append(round(annot['time'][0], 3))
ends.append(round(annot['time'][1], 3))
text.append(annot['text'])
if granularity == 'notes':
annotation = utils.NoteData(np.array([begs, ends]).T, np.array(notes), None)
else:
annotation = utils.LyricData(
np.array(begs), np.array(ends), np.array(text), None
)
return annotation