File size: 6,955 Bytes
96fd80c
 
 
44482b3
778b351
96fd80c
09857e0
4323869
 
96fd80c
 
09857e0
4323869
 
96fd80c
 
 
4323869
 
96fd80c
 
 
4323869
 
96fd80c
 
09857e0
 
96fd80c
 
 
09857e0
96fd80c
09857e0
 
96fd80c
 
 
09857e0
 
96fd80c
3423574
 
 
96fd80c
 
3423574
 
96fd80c
3423574
 
 
96fd80c
3423574
 
 
96fd80c
 
 
09857e0
96fd80c
 
e525c10
 
746da34
 
560a88d
 
746da34
e525c10
560a88d
e525c10
746da34
e525c10
560a88d
e525c10
bbea063
96fd80c
 
560a88d
96fd80c
560a88d
 
 
e525c10
09857e0
96fd80c
 
560a88d
96fd80c
560a88d
 
 
e525c10
09857e0
96fd80c
 
 
e525c10
 
 
 
 
 
746da34
96fd80c
778b351
746da34
e525c10
 
560a88d
96fd80c
778b351
b2596b3
44482b3
3423574
 
 
746da34
 
3423574
 
746da34
3423574
 
 
746da34
3423574
 
 
09857e0
778b351
 
e525c10
 
778b351
e525c10
746da34
e525c10
 
560a88d
09857e0
746da34
778b351
746da34
560a88d
44482b3
778b351
44482b3
560a88d
 
 
 
746da34
560a88d
 
746da34
e525c10
 
778b351
e525c10
778b351
e525c10
 
 
 
 
 
 
 
 
 
 
 
 
44482b3
746da34
e525c10
 
 
 
 
 
 
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
import csv
import datasets
from datasets import BuilderConfig, GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split
from pathlib import Path
import os

_PROMPTS_URLS = {
    "dev": "prosodic/validation.csv",
    "train": "prosodic/train.csv",
}

_PROMPTS_FILTERED_URLS = {
    "dev": "prosodic/validation.csv",
    "train": "prosodic/train.csv",
}

_ARCHIVES = {
    "dev": "prosodic.tar.gz",
    "train": "prosodic.tar.gz",
}

_PATH_TO_CLIPS = {
    "dev": "",
    "train": "",
}

class NurcSPConfig(BuilderConfig):
    def __init__(self, prompts_type="original", **kwargs):
        super().__init__(**kwargs)
        self.prompts_type = prompts_type

class NurcSPDataset(GeneratorBasedBuilder):
    BUILDER_CONFIGS = [
        NurcSPConfig(name="original", description="Original audio prompts", prompts_type="original"),
        NurcSPConfig(name="filtered", description="Filtered audio prompts", prompts_type="filtered"),
    ]

    def _info(self):
        return DatasetInfo(
            features=datasets.Features(
                {
                    "path": datasets.Value("string"),
                    "name": datasets.Value("string"),
                    "speaker": datasets.Value("string"),
                    "start_time": datasets.Value("string"),
                    "end_time": datasets.Value("string"),
                    "normalized_text": datasets.Value("string"),
                    "text": datasets.Value("string"),
                    "duration": datasets.Value("string"),
                    "type": datasets.Value("string"),
                    "year": datasets.Value("string"),
                    "gender": datasets.Value("string"),
                    "age_range": datasets.Value("string"),
                    "total_duration": datasets.Value("string"),
                    "quality": datasets.Value("string"),
                    "theme": datasets.Value("string"),
                    "audio": datasets.Audio(sampling_rate=16_000),
                }
            )
        )

    def _split_generators(self, dl_manager):
        print("\n=== Configuration ===")
        print(f"Using prompts_type: {self.config.prompts_type}")
        
        prompts_urls = _PROMPTS_URLS
        if self.config.prompts_type == "filtered":
            prompts_urls = _PROMPTS_FILTERED_URLS
        
        print(f"Downloading prompts from: {prompts_urls}")
        prompts_path = dl_manager.download(prompts_urls)
        print(f"Downloaded prompts to: {prompts_path}")
        
        print(f"Downloading archives from: {_ARCHIVES}")
        archive = dl_manager.download(_ARCHIVES)
        print(f"Downloaded archives to: {archive}")

        return [
            SplitGenerator(
                name=Split.VALIDATION,
                gen_kwargs={
                    "prompts_path": prompts_path["dev"],
                    "path_to_clips": _PATH_TO_CLIPS["dev"],
                    "audio_files": dl_manager.iter_archive(archive["dev"]),
                    "split_name": "validation"
                }
            ),
            SplitGenerator(
                name=Split.TRAIN,
                gen_kwargs={
                    "prompts_path": prompts_path["train"],
                    "path_to_clips": _PATH_TO_CLIPS["train"],
                    "audio_files": dl_manager.iter_archive(archive["train"]),
                    "split_name": "train"
                }
            ),
        ]

    def _generate_examples(self, prompts_path, path_to_clips, audio_files, split_name):
        print(f"\n{'='*50}")
        print(f"Processing {split_name} split")
        print(f"{'='*50}")
        print(f"\nCSV Path: {prompts_path}")
        print(f"Expected clips directory: {path_to_clips}")
        
        examples = {}
        csv_paths = []
        
        # Read CSV file
        print("\n=== Reading CSV ===")
        with open(prompts_path, "r") as f:
            csv_reader = csv.DictReader(f)
            for row in csv_reader:
                file_path = Path(row['path']).as_posix()
                examples[file_path] = {
                    "path": row['path'],
                    "name": row['name'],
                    "speaker": row['speaker'],
                    "start_time": row['start_time'],
                    "end_time": row['end_time'],
                    "normalized_text": row['normalized_text'],
                    "text": row['text'],
                    "duration": row['duration'],
                    "type": row['type'],
                    "year": row['year'],
                    "gender": row['gender'],
                    "age_range": row['age_range'],
                    "total_duration": row['total_duration'],
                    "quality": row['quality'],
                    "theme": row['theme'],
                }
                csv_paths.append(file_path)
        
        print(f"\nFound {len(csv_paths)} entries in CSV")
        print("\nFirst 3 CSV paths:")
        for path in csv_paths[:3]:
            print(f"  CSV path: {path}")
        
        # Process archive
        print("\n=== Processing Archive ===")
        inside_clips_dir = False
        id_ = 0
        matched_files = 0
        archive_paths = []
        
        for path, f in audio_files:
            path = Path(path).as_posix()
            archive_paths.append(path)
            
            if path.startswith(path_to_clips):
                inside_clips_dir = True
                if path in examples:
                    audio = {"path": path, "bytes": f.read()}
                    matched_files += 1
                    yield id_, {**examples[path], "audio": audio}
                    id_ += 1
        
        print("\n=== Path Analysis ===")
        print("\nFirst 3 archive paths:")
        for path in archive_paths[:3]:
            print(f"  Archive path: {path}")
            
            # Try to find potential matches
            print("\nPotential matches in CSV:")
            for csv_path in csv_paths[:3]:
                print(f"\nComparing:")
                print(f"  Archive: {path}")
                print(f"  CSV:     {csv_path}")
                print(f"  Archive parts: {path.split('/')}")
                print(f"  CSV parts:     {csv_path.split('/')}")
                
        print(f"\n=== Summary for {split_name} split ===")
        print(f"Total paths in CSV: {len(csv_paths)}")
        print(f"Total paths found in archive: {len(archive_paths)}")
        print(f"Successfully matched files: {matched_files}")
        
        if matched_files == 0:
            print("\n!!! MATCHING FAILED !!!")
            print("No files were matched between CSV and archive")
            print("\nTroubleshooting:")
            print("1. Check if CSV paths start with the clip directory name")
            print("2. Check for case sensitivity issues")
            print("3. Check for extra/missing directory levels")
            print("4. Check path separator consistency")