Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
]
f0_data_6 = [(None, None)]
f0_data_7 = [
(
utils.EventData(
np.array([0.2, 0.3]),
np.array([0.3, 0.4]),
np.array(['event A', 'event B']),
),
None,
)
]
jam_1 = jams_utils.jams_converter(f0_data=f0_data_1)
jam_2 = jams_utils.jams_converter(f0_data=f0_data_2)
jam_3 = jams_utils.jams_converter(f0_data=f0_data_3)
jam_6 = jams_utils.jams_converter(f0_data=f0_data_6)
time, duration, value, confidence = get_jam_data(jam_1, 'pitch_contour', 0)
assert time == [0.016, 0.048]
assert duration == [0.0, 0.0]
assert value == [
{'frequency': 0.0, 'index': 0, 'voiced': False},
{'frequency': 260.9, 'index': 0, 'voiced': True},
]
assert confidence == [0.0, 1.0]
assert jam_2.annotations[0]['sandbox']['name'] == 'f0s_1'
time, duration, value, confidence = get_jam_data(jam_3, 'pitch_contour', 0)
assert time == [0.016, 0.048]
assert duration == [0.0, 0.0]
jam_1 = jams_utils.jams_converter(lyrics_data=[(None, None)], metadata=metadata_1)
assert jam_1['file_metadata']['title'] == 'Le ciel est blue'
assert jam_1['file_metadata']['artist'] == 'Meatloaf'
assert jam_1['file_metadata']['duration'] == 1.5
assert jam_1['sandbox']['favourite_color'] == 'rainbow'
# test meatadata value None
metadata_2 = {
'duration': 1.5,
'artist': 'breakmaster cylinder',
'title': None,
'extra': None,
}
jam2 = jams_utils.jams_converter(metadata=metadata_2)
assert jam2.validate()
assert jam2['file_metadata']['duration'] == 1.5
assert jam2['file_metadata']['artist'] == 'breakmaster cylinder'
assert jam2['file_metadata']['title'] == ''
assert 'extra' not in jam2['sandbox']
def test_metadata():
metadata_1 = {
'duration': 1.5,
'artist': 'Meatloaf',
'title': 'Le ciel est blue',
'favourite_color': 'rainbow',
}
jam_1 = jams_utils.jams_converter(lyrics_data=[(None, None)], metadata=metadata_1)
assert jam_1['file_metadata']['title'] == 'Le ciel est blue'
assert jam_1['file_metadata']['artist'] == 'Meatloaf'
assert jam_1['file_metadata']['duration'] == 1.5
assert jam_1['sandbox']['favourite_color'] == 'rainbow'
# test meatadata value None
metadata_2 = {
'duration': 1.5,
'artist': 'breakmaster cylinder',
'title': None,
'extra': None,
}
jam2 = jams_utils.jams_converter(metadata=metadata_2)
assert jam2.validate()
assert jam2['file_metadata']['duration'] == 1.5
assert duration == [0.227, 0.51]
assert value == ['is', 'cool']
assert confidence == [None, None]
time, duration, value, confidence = get_jam_data(jam_6, 'lyrics', 0)
assert time == []
assert duration == []
assert value == []
assert confidence == []
assert type(jam_1) == jams.JAMS
with pytest.raises(TypeError):
jams_utils.jams_converter(lyrics_data=lyrics_data_4)
with pytest.raises(TypeError):
jams_utils.jams_converter(lyrics_data=lyrics_data_5)
with pytest.raises(TypeError):
jams_utils.jams_converter(lyrics_data=lyrics_data_7)
assert value == [
{'frequency': 0.0, 'index': 0, 'voiced': False},
{'frequency': 230.5, 'index': 0, 'voiced': True},
]
assert confidence == [0.0, 1.0]
time, duration, value, confidence = get_jam_data(jam_6, 'pitch_contour', 0)
assert time == []
assert duration == []
assert value == []
assert confidence == []
assert type(jam_1) == jams.JAMS
with pytest.raises(TypeError):
jams_utils.jams_converter(f0_data=f0_data_4)
with pytest.raises(TypeError):
jams_utils.jams_converter(f0_data=f0_data_5)
with pytest.raises(TypeError):
jams_utils.jams_converter(f0_data=f0_data_7)
],
]
lyrics_data_6 = [(None, None)]
lyrics_data_7 = [
(
utils.EventData(
np.array([0.2, 0.3]),
np.array([0.3, 0.4]),
np.array(['event A', 'event B']),
),
None,
)
]
jam_1 = jams_utils.jams_converter(lyrics_data=lyrics_data_1)
jam_2 = jams_utils.jams_converter(lyrics_data=lyrics_data_2)
jam_3 = jams_utils.jams_converter(lyrics_data=lyrics_data_3)
jam_6 = jams_utils.jams_converter(lyrics_data=lyrics_data_6)
time, duration, value, confidence = get_jam_data(jam_1, 'lyrics', 0)
assert time == [0.027, 0.232]
assert duration == [0.2, 0.51]
assert value == ['The', 'Test']
assert confidence == [None, None]
assert jam_2.annotations[0]['sandbox']['name'] == 'lyrics_1'
time, duration, value, confidence = get_jam_data(jam_3, 'lyrics', 0)
assert time == [0.027, 0.232]
assert duration == [0.2, 0.51]
assert value == ['The', 'Test']
assert confidence == [None, None]
def to_jams(self):
"""Jams: the track's data in jams format"""
metadata = {k: v for k, v in self._track_metadata.items() if v is not None}
metadata['duration'] = librosa.get_duration(self.audio[0], self.audio[1])
return jams_utils.jams_converter(
f0_data=[(self.pitch, 'annotated pitch')], metadata=metadata
)
def to_jams(self):
"""Jams: the track's data in jams format"""
return jams_utils.jams_converter(metadata=self._track_metadata) # TODO PR #185