Ejemplo n.º 1
0
def load_lyrics(fhandle: TextIO) -> annotations.LyricData:
    """Load an ikala lyrics annotation

    Args:
        fhandle (str or file-like): File-like object or path to lyric annotation file

    Raises:
        IOError: if lyrics_path does not exist

    Returns:
        LyricData: lyric annotation data

    """
    # input: start time (ms), end time (ms), lyric, [pronunciation]
    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)
        else:
            pronunciations.append("")

    lyrics_data = annotations.LyricData(
        np.array([start_times, end_times]).T,
        lyrics,
        pronunciations,
    )
    return lyrics_data
Ejemplo n.º 2
0
def load_annotations_granularity(annotations_path, granularity):
    """Load annotations at the specified level of granularity

    Args:
        annotations_path (str): path to a DALI annotation file
        granularity (str): one of 'notes', 'words', 'lines', 'paragraphs'

    Returns:
        NoteData for granularity='notes' or LyricData otherwise

    """
    try:
        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 = annotations.NoteData(
            np.array([begs, ends]).T, np.array(notes), None)
    else:
        annotation = annotations.LyricData(
            np.array([begs, ends]).T, text, None)
    return annotation
Ejemplo n.º 3
0
def test_lyric_data():
    intervals = np.array([[1.0, 2.0], [1.5, 3.0], [2.0, 3.0]])
    lyrics = ["E:m", "A", "G:7"]
    pronunciations = ["a", "", "b"]
    lyric_data = annotations.LyricData(intervals, lyrics, pronunciations)
    assert np.allclose(lyric_data.intervals, intervals)
    assert lyric_data.lyrics == lyrics
    assert lyric_data.pronunciations == pronunciations
def load_phrases(fhandle: TextIO) -> annotations.LyricData:
    """Load lyric phrases annotation

    Args:
        fhandle (str or file-like): path or file-like object pointing to a lyric annotation file

    Returns:
        LyricData: lyric phrase annotation

    """
    start_times = []
    end_times = []
    lyrics = []

    reader = csv.reader(fhandle, delimiter="\t")
    for line in reader:
        start_times.append(float(line[0]))
        end_times.append(float(line[1]))
        lyrics.append(line[2] if line[2] != "sil" else "")

    return annotations.LyricData(
        np.array([start_times, end_times]).T,
        lyrics,
    )
Ejemplo n.º 5
0
def test_lyrics():
    lyrics_data_1 = [
        (
            annotations.LyricData(
                np.array([[0.027, 0.232], [0.227, 0.742]]).T,
                ["The", "Test"],
                ["", ""],
            ),
            None,
        )
    ]
    lyrics_data_2 = [
        (
            annotations.LyricData(
                np.array([[0.027, 0.232], [0.227, 0.742]]).T,
                ["The", "Test"],
                ["", ""],
            ),
            "lyrics_1",
        )
    ]
    lyrics_data_3 = [
        (
            annotations.LyricData(
                np.array([[0.027, 0.232], [0.227, 0.742]]).T,
                ["The", "Test"],
                ["", ""],
            ),
            "lyrics_1",
        ),
        (
            annotations.LyricData(
                np.array([[0.0, 0.232], [0.227, 0.742]]).T,
                ["is", "cool"],
                ["", ""],
            ),
            "lyrics_2",
        ),
    ]
    lyrics_data_4 = (
        annotations.LyricData(
            np.array([[0.027, 0.232], [0.227, 0.742]]).T,
            ["The", "Test"],
            ["", ""],
        ),
        "lyrics_1",
    )
    lyrics_data_5 = [
        (
            annotations.LyricData(
                np.array([[0.027, 0.232], [0.227, 0.742]]).T,
                ["The", "Test"],
                ["", ""],
            ),
            "lyrics_1",
        ),
        [
            annotations.LyricData(
                np.array([[0.0, 0.232], [0.227, 0.742]]).T,
                ["is", "cool"],
                ["", ""],
            ),
            "lyrics_2",
        ],
    ]
    lyrics_data_6 = [(None, None)]
    lyrics_data_7 = [
        (
            annotations.EventData(
                np.array([[0.2, 0.3], [0.3, 0.4]]).T,
                ["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]

    time, duration, value, confidence = get_jam_data(jam_3, "lyrics", 1)
    assert time == [0.0, 0.232]
    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)