iulik-pisik commited on
Commit
f0b8559
1 Parent(s): e50c84a

incercarea #20

Browse files
Files changed (1) hide show
  1. horoscop_neti.py +76 -0
horoscop_neti.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ import os
3
+ import json
4
+
5
+ import datasets
6
+ from datasets.utils.py_utils import size_str
7
+ from tqdm import tqdm
8
+
9
+ # _BASE_URL = "https://huggingface.co/datasets/mozilla-foundation/common_voice_11_0/resolve/main/"
10
+
11
+ class HoroscopNeti(datasets.GeneratorBasedBuilder):
12
+
13
+ def _info(self):
14
+ return datasets.DatasetInfo(
15
+ description="Descrierea datasetului tău.",
16
+ features=datasets.Features({
17
+ "path": datasets.Value("string"),
18
+ "audio": datasets.features.Audio(sampling_rate=16000),
19
+ "transcript": datasets.Value("string"),
20
+ }),
21
+ supervised_keys=("audio", "transcript"),
22
+ homepage="URL către pagina de Hugging Face a datasetului",
23
+ citation="Referința de citare a datasetului",
24
+ )
25
+
26
+ def _split_generators(self):
27
+
28
+ return [
29
+ datasets.SplitGenerator(
30
+ name=datasets.Split.TRAIN,
31
+ gen_kwargs={
32
+ "audio_dir": "audio/train",
33
+ "transcript_dir": "transcript/train",
34
+ },
35
+ ),
36
+ datasets.SplitGenerator(
37
+ name=datasets.Split.TEST,
38
+ gen_kwargs={
39
+ "audio_dir": "audio/test",
40
+ "transcript_dir": "transcript/test",
41
+ },
42
+ ),
43
+ datasets.SplitGenerator(
44
+ name=datasets.Split.VALIDATION,
45
+ gen_kwargs={
46
+ "audio_dir": "audio/validation",
47
+ "transcript_dir": "transcript/validation",
48
+ },
49
+ ),
50
+ ]
51
+
52
+ def _generate_examples(self, audio_dir, transcript_dir):
53
+ for root, _, files in os.walk(transcript_dir):
54
+ for file in files:
55
+ if not file.endswith(".txt"):
56
+ continue
57
+
58
+ transcript_path = os.path.join(transcript_dir, file)
59
+ audio_path = os.path.join(audio_dir, file.replace(".txt", ".wav"))
60
+
61
+ if not os.path.exists(audio_path):
62
+ continue
63
+
64
+ with open(transcript_path, "r", encoding="utf-8") as f:
65
+ transcript = f.read().strip()
66
+
67
+ with open(audio_path, "rb") as af:
68
+ audio_bytes = af.read()
69
+
70
+ example_id = os.path.splitext(file)[0]
71
+
72
+ yield example_id, {
73
+ "path": audio_path,
74
+ "audio": {"path": audio_path, "bytes": audio_bytes},
75
+ "transcript": transcript,
76
+ }