Datasets:

Languages:
English
ArXiv:
License:
File size: 2,937 Bytes
976ddd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import os
from datasets import load_dataset, DatasetInfo, DatasetDict, SplitGenerator, Split, Features, Value, Audio

_DESCRIPTION = """
Custom version of the Common Voice dataset with additional test_freq split including custom audio and metadata.
"""

_CITATION = """
@inproceedings{commonvoice:2020,
  author = {Ardila, R. and Branson, M. and Davis, K. and Henretty, M. and Kohler, M. and Meyer, J. and Morais, R. and Saunders, L. and Tyers, F. M. and Weber, G.},
  title = {Common Voice: A Massively-Multilingual Speech Corpus},
  booktitle = {Proceedings of the 12th Conference on Language Resources and Evaluation (LREC 2020)},
  year = 2020
}
"""

_HOMEPAGE = "https://commonvoice.mozilla.org/en/datasets"
_LICENSE = "https://creativecommons.org/publicdomain/zero/1.0/"

class CustomCommonVoice(datasets.GeneratorBasedBuilder):
    """Builder for a modified Common Voice dataset including a custom test_freq split."""

    VERSION = datasets.Version("1.0.0")

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name="test_freq", description="Custom rare test split of the Common Voice dataset."),
    ]

    DEFAULT_CONFIG_NAME = "test_freq"  # Default configuration to use if none specified.

    def _info(self):
        return DatasetInfo(
            description=_DESCRIPTION,
            features=Features({
                "id": Value("string"),
                "utterance": Value("int32"),
                "from": Value("string"),
                "value": Value("string"),
                "emotion": Value("string"),
                "file_name": Value("string"),
                "audio": Audio(sampling_rate=16_000),
            }),
            supervised_keys=("audio", "value"),
            homepage=_HOMEPAGE,
            citation=_CITATION,
            license=_LICENSE,
        )

    def _split_generators(self, dl_manager):
        """Returns SplitGenerators."""
        test_freq_dir = os.path.abspath("test_freq")  # Adjust path as needed
        test_freq_metadata = os.path.join(test_freq_dir, "metadata.jsonl")

        return [
            SplitGenerator(
                name=Split.TEST,
                gen_kwargs={"metadata_path": test_freq_metadata, "audio_dir": test_freq_dir}),
        ]

    def _generate_examples(self, metadata_path, audio_dir):
        """Yields examples."""
        with open(metadata_path, 'r', encoding='utf-8') as f:
            for line in f:
                metadata = json.loads(line)
                audio_path = os.path.join(audio_dir, metadata['file_name'])
                yield metadata['id'], {
                    "id": metadata['id'],
                    "utterance": metadata['utterance'],
                    "from": metadata['from'],
                    "value": metadata['value'],
                    "emotion": metadata['emotion'],
                    "file_name": metadata['file_name'],
                    "audio": audio_path,
                }