File size: 1,364 Bytes
0109099
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# coding=utf-8

import os
import numpy as np
import datasets


_DATA_URL = "https://huggingface.co/datasets/Matthijs/cmu-arctic-xvectors/resolve/main/spkrec-xvect.zip"


class ArcticXvectors(datasets.GeneratorBasedBuilder):

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name="default",
            version=datasets.Version("0.0.1", ""),
            description="",
        )
    ]

    def _info(self):
        return datasets.DatasetInfo(
            features=datasets.Features(
                {
                    "filename": datasets.Value("string"),
                    "xvector": datasets.Sequence(feature=datasets.Value(dtype="float32"), length=512),
                }
            ),
        )

    def _split_generators(self, dl_manager):
        archive = os.path.join(dl_manager.download_and_extract(_DATA_URL), "spkrec-xvect")
        return [
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION, gen_kwargs={"files": dl_manager.iter_files(archive)}
            ),
        ]

    def _generate_examples(self, files):
        for i, file in enumerate(sorted(files)):
            if os.path.basename(file).endswith(".npy"):
                yield str(i), {
                    "filename": os.path.basename(file)[:-4],  # strip off .npy
                    "xvector": np.load(file),
                }