File size: 5,931 Bytes
b2d92b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import os

import datasets

_CITATION = """\
@InProceedings{Todisco2019,
  Title     = {{ASV}spoof 2019: {F}uture {H}orizons in {S}poofed and {F}ake {A}udio {D}etection},
  Author    = {Todisco, Massimiliano and
               Wang, Xin and
               Sahidullah, Md and
               Delgado, H ́ector and
               Nautsch, Andreas and
               Yamagishi, Junichi and
               Evans, Nicholas and
               Kinnunen, Tomi and
               Lee, Kong Aik},
  booktitle = {Proc. of Interspeech 2019},
  Year      = {2019}
}
"""

_DESCRIPTION = """\
This is a database used for the Third Automatic Speaker Verification Spoofing
and Countermeasuers Challenge, for short, ASVspoof 2019 (http://www.asvspoof.org)
organized by Junichi Yamagishi, Massimiliano Todisco, Md Sahidullah, Héctor
Delgado, Xin Wang, Nicholas Evans, Tomi Kinnunen, Kong Aik Lee, Ville Vestman,
and Andreas Nautsch in 2019.
"""

_HOMEPAGE = "https://datashare.ed.ac.uk/handle/10283/3336"

_LICENSE = "http://opendatacommons.org/licenses/by/1.0/"

_URLS = {
    "LA": "https://datashare.ed.ac.uk/bitstream/handle/10283/3336/LA.zip",
    "PA": "https://datashare.ed.ac.uk/bitstream/handle/10283/3336/PA.zip",
}


class ASVSpoof2019(datasets.GeneratorBasedBuilder):

    VERSION = datasets.Version("1.0.0")

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name="LA", version=VERSION, description="Logical access (LA)"),
        datasets.BuilderConfig(name="PA", version=VERSION, description="Physical access (PA)"),
    ]

    DEFAULT_CONFIG_NAME = "LA"

    def _info(self):
        if self.config.name == "LA":
            features = datasets.Features(
                {
                    "speaker_id": datasets.Value("string"),
                    "audio_file_name": datasets.Value("string"),
                    "audio": datasets.Audio(sampling_rate=16_000),
                    "system_id": datasets.Value("string"),
                    "key": datasets.ClassLabel(names=["bonafide", "spoof"]),
                }
            )
        else:
            features = datasets.Features(
                {
                    "speaker_id": datasets.Value("string"),
                    "audio_file_name": datasets.Value("string"),
                    "audio": datasets.Audio(sampling_rate=16_000),
                    "environment_id": datasets.Value("string"),
                    "attack_id": datasets.Value("string"),
                    "key": datasets.ClassLabel(names=["bonafide", "spoof"]),
                }
            )
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            supervised_keys=("audio", "key"),
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        urls = _URLS[self.config.name]
        data_dir = dl_manager.download_and_extract(urls)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "metadata_filepath": os.path.join(
                        data_dir,
                        self.config.name,
                        f"ASVspoof2019_{self.config.name}_cm_protocols",
                        f"ASVspoof2019.{self.config.name}.cm.train.trn.txt",
                    ),
                    "audios_dir": os.path.join(
                        data_dir, self.config.name, f"ASVspoof2019_{self.config.name}_train", "flac"
                    ),
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={
                    "metadata_filepath": os.path.join(
                        data_dir,
                        self.config.name,
                        f"ASVspoof2019_{self.config.name}_cm_protocols",
                        f"ASVspoof2019.{self.config.name}.cm.dev.trl.txt",
                    ),
                    "audios_dir": os.path.join(
                        data_dir, self.config.name, f"ASVspoof2019_{self.config.name}_dev", "flac"
                    ),
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "metadata_filepath": os.path.join(
                        data_dir,
                        self.config.name,
                        f"ASVspoof2019_{self.config.name}_cm_protocols",
                        f"ASVspoof2019.{self.config.name}.cm.eval.trl.txt",
                    ),
                    "audios_dir": os.path.join(
                        data_dir, self.config.name, f"ASVspoof2019_{self.config.name}_eval", "flac"
                    ),
                },
            ),
        ]

    def _generate_examples(self, metadata_filepath, audios_dir):
        with open(metadata_filepath) as f:
            for i, line in enumerate(f.readlines()):
                if self.config.name == "LA":
                    speaker_id, audio_file_name, _, system_id, key = line.strip().split()
                    result = {
                        "speaker_id": speaker_id,
                        "audio_file_name": audio_file_name,
                        "system_id": system_id,
                        "key": key,
                    }
                elif self.config.name == "PA":
                    speaker_id, audio_file_name, environment_id, attack_id, key = line.strip().split()
                    result = {
                        "speaker_id": speaker_id,
                        "audio_file_name": audio_file_name,
                        "environment_id": environment_id,
                        "attack_id": attack_id,
                        "key": key,
                    }
                result["audio"] = os.path.join(audios_dir, audio_file_name + ".flac")
                yield i, result