Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_load_lines():
data_path = (
'tests/resources/mir_datasets/DALI/annotations/'
+ '4b196e6c99574dd49ad00d56e132712b.gz'
)
line_data = dali.load_annotations_granularity(data_path, 'lines')
assert type(line_data) == utils.LyricData
assert type(line_data.start_times) == np.ndarray
assert type(line_data.end_times) == np.ndarray
assert type(line_data.lyrics) == np.ndarray
print(line_data.start_times)
print(line_data.end_times)
print(line_data.lyrics)
assert np.array_equal(line_data.start_times, np.array([24.125, 24.42]))
assert np.array_equal(line_data.end_times, np.array([24.42, 24.568]))
assert np.array_equal(line_data.lyrics, np.array(['why do', 'they']))
# load a file which doesn't exist
line_none = dali.load_annotations_granularity('fake/file/path', 'lines')
assert line_none is None
def test_lyrics():
lyrics_data_1 = [
(
utils.LyricData(
np.array([0.027, 0.232]),
np.array([0.227, 0.742]),
np.array(['The', 'Test']),
np.array([None, None]),
),
None,
)
]
lyrics_data_2 = [
(
utils.LyricData(
np.array([0.027, 0.232]),
np.array([0.227, 0.742]),
np.array(['The', 'Test']),
np.array([None, None]),
),
),
'lyrics_2',
),
]
lyrics_data_4 = (
utils.LyricData(
np.array([0.027, 0.232]),
np.array([0.227, 0.742]),
np.array(['The', 'Test']),
np.array([None, None]),
),
'lyrics_1',
)
lyrics_data_5 = [
(
utils.LyricData(
np.array([0.027, 0.232]),
np.array([0.227, 0.742]),
np.array(['The', 'Test']),
np.array([None, None]),
),
'lyrics_1',
),
[
utils.LyricData(
np.array([0.0, 0.232]),
np.array([0.227, 0.742]),
np.array(['is', 'cool']),
np.array([None, None]),
),
'lyrics_2',
],
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
Convert lyrics annotations into jams format.
Parameters
----------
lyrics: tuple
A tuple in the format (LyricData, str), where str describes the annotation
and LyricData is the lyric mirdata annotation format.
Returns
-------
jannot_lyric: JAM lyric annotation object.
'''
jannot_lyric = jams.Annotation(namespace='lyrics')
jannot_lyric.annotation_metadata = jams.AnnotationMetadata(data_source='mirdata')
if lyrics[0] is not None:
if type(lyrics[0]) != utils.LyricData:
raise TypeError('Type should be LyricData.')
for beg, end, lyric in zip(
lyrics[0].start_times, lyrics[0].end_times, lyrics[0].lyrics
):
jannot_lyric.append(time=beg, duration=end - beg, value=lyric)
if lyrics[1] is not None:
jannot_lyric.sandbox = jams.Sandbox(name=lyrics[1])
return jannot_lyric
reader = csv.reader(fhandle, delimiter=' ')
start_times = []
end_times = []
lyrics = []
pronunciations = []
for line in reader:
start_times.append(float(line[0]) / 1000.0)
end_times.append(float(line[1]) / 1000.0)
lyrics.append(line[2])
if len(line) > 2:
pronunciation = ' '.join(line[3:])
pronunciations.append(pronunciation if pronunciation != '' else None)
else:
pronunciations.append(None)
lyrics_data = utils.LyricData(
np.array(start_times),
np.array(end_times),
np.array(lyrics),
np.array(pronunciations),
)
return lyrics_data