File size: 5,809 Bytes
05da4fa
 
734c8eb
927b3bd
734c8eb
05da4fa
734c8eb
05da4fa
 
 
 
 
 
 
 
 
6663a58
 
05da4fa
 
 
 
 
1b9fccd
9f2d453
c712e3e
224edaa
7f02aff
 
 
6663a58
27f3f20
b70ff63
1b9fccd
 
05da4fa
 
 
 
927b3bd
 
 
 
21e571a
9f2d453
224edaa
 
09e946b
927b3bd
 
734c8eb
 
05da4fa
 
 
 
 
21e571a
05da4fa
 
 
 
 
 
734c8eb
05da4fa
 
 
734c8eb
21e571a
421aac0
7f02aff
 
 
 
 
c55b167
 
 
 
 
 
 
 
7f02aff
c55b167
7f02aff
 
21e571a
734c8eb
 
05da4fa
 
 
927b3bd
6d32bc3
927b3bd
6663a58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05da4fa
734c8eb
 
 
50a4920
734c8eb
 
05da4fa
50a4920
734c8eb
 
05da4fa
50a4920
734c8eb
 
 
05da4fa
624ac80
6663a58
795f52c
06d9173
50a4920
06d9173
 
6f2769e
62a331c
50a4920
 
6663a58
c55b167
7f02aff
 
 
c55b167
 
 
 
 
927b3bd
6663a58
 
 
927b3bd
9f2d453
06d9173
9f2d453
 
 
 
 
 
 
 
 
 
 
 
 
927b3bd
 
 
05da4fa
 
 
 
 
1b9fccd
 
 
 
 
 
 
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import csv
import os
import datasets
import pandas as pd

# Metadata

_DESCRIPTION = """\

Mumospee is a continuously growing, comprehensive, multilingual dataset across different modalities. 
This is the small version include no more 1000 rows.

"""

_LICENSE = "Creative Commons Attribution 4.0 International"

_LANGUAGES = ["en", "bg", "de", "ar"] 

_TAGS = ["CoVoST", "GigaSpeech", "peoples_speech", "Librispeech", "LibriTTS", "Emilia", "MOSEL"]

_SPLITS = ["train", "validation", "test"]

# BuilderConfig class for your dataset
class MumospeeDatasetConfig(datasets.BuilderConfig):
    def __init__(self, split, language=None, tag=None, **kwargs):
        super().__init__(**kwargs)
        self.split=split
        self.language = language
        self.tag = tag
    




class MumospeeDataset(datasets.GeneratorBasedBuilder):

    VERSION = datasets.Version("1.0.0")

    # Define the available configurations (could be subsets like split or language)
    BUILDER_CONFIGS = [
        MumospeeDatasetConfig(
            name="default",
            version=datasets.Version("1.0.0"),
            description=_DESCRIPTION,
            split="train",
            language=None,
            tag=None
            )
        ]
    DEFAULT_CONFIG_NAME = "default"

    def _info(self):
        # Define the features of your dataset
        features = datasets.Features({
            "path": datasets.Value("string"),
            "url": datasets.Value("string"),
            "type": datasets.Value("string"),
            "duration": datasets.Value("string"),
            "language": datasets.Value("string"),
            "transcript": datasets.Value("string"),
            "tag": datasets.Value("string"),
            "split": datasets.Value("string"),
            "license": datasets.Value("string")
        })
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            license=_LICENSE,
        )
    
    def _adapt_args(self, arg, accepted_arg):
        """
        Adpat the input and make sure it outs as list 
        and all the elements within the list are accpeted.
        """

        if arg:
            if isinstance(arg, str):
                adapted_arg = [arg]
            else:
                adapted_arg = arg
            for aa in adapted_arg:
                if aa not in accepted_arg:
                    raise ValueError(f"Invalid input: '{aa}'. Accepted values are: {', '.join(accepted_arg)}.")
        else:
            adapted_arg = accepted_arg

        return adapted_arg


    def _split_generators(self, dl_manager):
        """Split the dataset into train, validation, and test."""
        # Your dataset might have specific splits like "train", "dev", "test"
        splits = ["train", "validation", "test"]

        csv_path = dl_manager.download_and_extract("dataset.csv")


        # ===To download the url
        # Load CSV to retrieve URLs for audio files
        # data = pd.read_csv(csv_path)
        # url_list = data["url"].tolist()  # List of all URLs in the CSV file
        # url_list = list(set(url_list))

        # # Download all files listed in the 'url' column and store the local paths
        # downloaded_files = dl_manager.download(url_list)

        # # Add the downloaded file paths to the DataFrame to make them accessible in `_generate_examples`
        # data["local_path"] = downloaded_files

        #===




        # Define the splits and pass the language and tag filters to _generate_examples
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={"filepath": csv_path}
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={"filepath": csv_path}
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={"filepath": csv_path}
            ),
        ]


    def _generate_examples(self, filepath):

        data = pd.read_csv(filepath)
        split = self.config.split
      
        language = self.config.language
        tag = self.config.tag

        print(f'Return {split} dataset in langauge of {language}, originally from {tag}.')

        data_split = data[data["split"] == split]

    
        language_list = self._adapt_args(language, _LANGUAGES)
        tag_list = self._adapt_args(tag, _TAGS)

        print(f"Following langauges will be loaded: {language_list}")
        print(f"Following dataset will be loaded: {tag_list}")

        data_split = data_split[data_split["language"].isin(language_list)]
        data_split = data_split[data_split["tag"].isin(tag_list)]

        if data_split.empty:
            print(f"No data found for split='{split}', language='{language}', tag='{tag}'. Returning None.")
            return  # This exits the generator without yielding any examples

        else:

            for i, row in data_split.iterrows():
                yield i, {
                    "path": row["path"],
                    #"local_path": row["local_path"],
                    "url": row["url"],
                    "type": row["type"],
                    "duration": float(row["duration"]),
                    "language": row["language"],
                    "transcript": row["transcript"],
                    "tag": row["tag"],
                    "split": row["split"],
                    "license": row["license"]
                }



    def _download_audio(self, audio_url):
        """Download audio from a URL if needed (you could also implement streaming)."""
        # This is an example function for downloading audio if it's needed
        # You can integrate this within your data processing pipeline if required
        pass