aburnazyan
commited on
Commit
•
6c81428
1
Parent(s):
67cd8e7
fixes
Browse files- hy_asr_grqaser.py +49 -47
hy_asr_grqaser.py
CHANGED
@@ -1,51 +1,53 @@
|
|
1 |
##
|
2 |
import os
|
3 |
import pandas as pd
|
4 |
-
from datasets import
|
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 |
# if __name__ == "__main__":
|
45 |
-
#
|
46 |
-
# dataset =
|
47 |
-
# print(dataset["train"][
|
48 |
-
# from datasets import load_dataset
|
49 |
-
# load_dataset("aburnazy/hy_asr_grqaser", data_dir=".")
|
50 |
-
|
51 |
-
|
|
|
1 |
##
|
2 |
import os
|
3 |
import pandas as pd
|
4 |
+
from datasets import DatasetBuilder, DatasetInfo, SplitGenerator, Split, Features, Value, Audio, Version
|
5 |
+
|
6 |
+
class HyAsrGrqaser(DatasetBuilder):
|
7 |
+
"""Armenian Audio-Transcription Dataset"""
|
8 |
+
|
9 |
+
VERSION = Version("1.0.0")
|
10 |
+
|
11 |
+
def _info(self):
|
12 |
+
return DatasetInfo(
|
13 |
+
description="This dataset contains Armenian speech and transcriptions.",
|
14 |
+
features=Features({
|
15 |
+
'audio': Audio(sampling_rate=16_000), # Adjust the sampling rate as needed
|
16 |
+
'sentence': Value('string')
|
17 |
+
}),
|
18 |
+
supervised_keys=("audio", "sentence"),
|
19 |
+
)
|
20 |
+
|
21 |
+
def _split_generators(self, dl_manager):
|
22 |
+
"""Returns SplitGenerators."""
|
23 |
+
# Assuming the script is in the root of the project structure
|
24 |
+
data_dir = os.path.dirname(__file__)
|
25 |
+
metadata_path = os.path.join(os.path.dirname(__file__), "metadata.csv")
|
26 |
+
return [
|
27 |
+
SplitGenerator(
|
28 |
+
name=Split.TRAIN,
|
29 |
+
gen_kwargs={"data_dir": data_dir, "metadata_path": metadata_path}
|
30 |
+
),
|
31 |
+
]
|
32 |
+
|
33 |
+
def _generate_examples(self, data_dir, metadata_path):
|
34 |
+
"""Yields examples."""
|
35 |
+
# Load metadata.csv
|
36 |
+
metadata = pd.read_csv(metadata_path)
|
37 |
+
|
38 |
+
# Generate examples
|
39 |
+
for idx, row in metadata.iterrows():
|
40 |
+
file_path = os.path.join(data_dir, row['file_name'])
|
41 |
+
transcription_path = os.path.join(data_dir, row['transcription_file'])
|
42 |
+
with open(transcription_path, 'r') as f:
|
43 |
+
transcription = f.read().strip()
|
44 |
+
yield idx, {
|
45 |
+
'audio': {'path': file_path},
|
46 |
+
'sentence': transcription
|
47 |
+
}
|
48 |
+
|
49 |
+
# Testing the dataset locally
|
50 |
# if __name__ == "__main__":
|
51 |
+
# from datasets import load_dataset
|
52 |
+
# dataset = load_dataset("C:\\Projects\\aeneas\\hy_asr_grqaser\\hy_asr_grqaser.py")
|
53 |
+
# print(dataset["train"][0])
|
|
|
|
|
|
|
|