File size: 2,755 Bytes
11eba43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""LibriS2S dataset."""

import csv
import os
from typing import Dict, List, Tuple

import datasets


_CITATION = """@inproceedings{jeuris-niehues-2022-libris2s,
   title = "{L}ibri{S}2{S}: A {G}erman-{E}nglish Speech-to-Speech Translation Corpus",
   author = "Jeuris, Pedro and Niehues, Jan",
   booktitle = "Proceedings of the Thirteenth Language Resources and Evaluation Conference",
   year = "2022",
   url = "https://aclanthology.org/2022.lrec-1.98",
   pages = "928--935"
}"""

_DESCRIPTION = """LibriS2S: A German-English Speech-to-Speech Translation Corpus"""

_HOMEPAGE = "https://huggingface.co/datasets/PedroDKE/LibriS2S"

_LICENSE = "cc-by-nc-sa-4.0"


class LibriS2S(datasets.GeneratorBasedBuilder):
    """LibriS2S dataset."""

    VERSION = datasets.Version("1.0.0")

    def _info(self) -> datasets.DatasetInfo:
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "book_id": datasets.Value("int64"),
                    "DE_audio": datasets.Audio(),
                    "EN_audio": datasets.Audio(),
                    "score": datasets.Value("float32"),
                    "DE_transcript": datasets.Value("string"),
                    "EN_transcript": datasets.Value("string"),
                }
            ),
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
        """Returns SplitGenerators."""
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "split": "train",
                    "data_dir": ".",
                },
            ),
        ]

    def _generate_examples(self, split: str, data_dir: str) -> Tuple[int, Dict]:
        """Yields examples."""
        csv_path = os.path.join(data_dir, "alignments", "all_de_en_alligned_cleaned.csv")
        
        with open(csv_path, encoding="utf-8") as f:
            reader = csv.DictReader(f)
            for idx, row in enumerate(reader):
                # Handle paths for both DE and EN audio
                de_audio_path = os.path.join(data_dir, row["DE_audio"])
                en_audio_path = os.path.join(data_dir, row["EN_audio"])
                
                yield idx, {
                    "book_id": int(row["book_id"]),
                    "DE_audio": de_audio_path,
                    "EN_audio": en_audio_path,
                    "score": float(row["score"]),
                    "DE_transcript": row["DE_transcript"],
                    "EN_transcript": row["EN_transcript"],
                }