nihalbaig commited on
Commit
de7841d
1 Parent(s): a67233d

updating the code again!!

Browse files
Files changed (1) hide show
  1. bn_emotion_speech_corpus.py +65 -48
bn_emotion_speech_corpus.py CHANGED
@@ -1,73 +1,90 @@
 
 
 
1
  import datasets
2
 
3
  _CITATION = """\
4
- @dataset{sadia_sultana_2021_4526477,
5
- author = {Sadia Sultana},
6
- title = {SUST Bangla Emotional Speech Corpus (SUBESCO)},
7
- month = feb,
8
- year = 2021,
9
- note = {{This database was created as a part of PhD thesis
10
- project of the author Sadia Sultana. It was
11
- designed and developed by the author in the
12
- Department of Computer Science and Engineering of
13
- Shahjalal University of Science and Technology.
14
- Financial grant was supported by the university.
15
- If you use the dataset please cite SUBESCO and the
16
- corresponding academic journal publication in Plos
17
- One.}},
18
- publisher = {Zenodo},
19
- version = {version - 1.1},
20
- doi = {10.5281/zenodo.4526477},
21
- url = {https://doi.org/10.5281/zenodo.4526477}
22
- }
23
  """
24
 
25
  _DESCRIPTION = """\
26
- SUST Bangla Emotional Speech Corpus Dataset
27
  """
28
- _HOMEPAGE = "https://huggingface.co/datasets/sustcsenlp/bn_emotion_speech_corpus"
29
 
30
- _LICENSE = ""
 
 
31
 
32
- #_REPO = "https://huggingface.co/datasets/sustcsenlp/SUBESCO/resolve/main/corpus/speech/subesco.tar.gz"
33
 
34
- class AudioSet(datasets.GeneratorBasedBuilder):
35
- """"""
 
 
 
 
 
 
 
 
36
 
 
37
  def _info(self):
 
 
 
 
 
 
 
 
 
 
 
 
38
  return datasets.DatasetInfo(
39
  description=_DESCRIPTION,
40
- features=datasets.Features(
41
- {
42
- 'text': datasets.Value("string"),
43
- "audio": datasets.Audio(sampling_rate=16000),
44
- }
45
- ),
46
  supervised_keys=None,
47
  homepage=_HOMEPAGE,
 
48
  citation=_CITATION,
49
  )
50
 
51
  def _split_generators(self, dl_manager):
52
- audio_archive = dl_manager.download("https://huggingface.co/datasets/sustcsenlp/bn_emotion_speech_corpus/resolve/main/subesco.tar.gz")
53
- audio_iters = dl_manager.iter_archive(audio_archive)
 
 
 
54
  return [
55
  datasets.SplitGenerator(
56
  name=datasets.Split.TRAIN,
57
  gen_kwargs={
58
- "audios": audio_iters
59
- }
60
- ),
 
 
 
61
  ]
62
-
63
- def _generate_examples(self, audios):
64
- """This function returns the examples in the raw (text) form."""
65
- idx = 0
66
- for filepath, audio in audios:
67
- description = filepath.split('/')[-1][:-4]
68
- description = description.replace('_', ' ')
69
- yield idx, {
70
- "audio": {"path": filepath, "bytes": audio.read()},
71
- "text": description,
72
- }
73
- idx += 1
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+
4
  import datasets
5
 
6
  _CITATION = """\
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  """
8
 
9
  _DESCRIPTION = """\
10
+ The corpus contains roughly 360 hours of audio and transcripts in Kannada language. The transcripts have beed de-duplicated using exact match deduplication.
11
  """
 
12
 
13
+ _HOMEPAGE = ""
14
+
15
+ _LICENSE = "https://creativecommons.org/licenses/"
16
 
 
17
 
18
+ _METADATA_URLS = {
19
+ "train": "train.jsonl",
20
+ }
21
+ _URLS = {
22
+ "train": "subesco.tar.gz",
23
+
24
+ }
25
+
26
+ class KannadaASRCorpus(datasets.GeneratorBasedBuilder):
27
+ """Kannada ASR Corpus contains transcribed speech corpus for training ASR systems for Kannada language."""
28
 
29
+ VERSION = datasets.Version("1.1.0")
30
  def _info(self):
31
+ features = datasets.Features(
32
+ {
33
+ "path": datasets.Value("string"),
34
+ "audio": datasets.Audio(sampling_rate=16000),
35
+ "speaker_gender": datasets.Value("string"),
36
+ "speaker_number": datasets.Value("int32"),
37
+ "speaker_name": datasets.Value("string"),
38
+ "sentence_number": datasets.Value("int32"),
39
+ "emotional_state": datasets.Value("string"),
40
+ "take_number": datasets.Value("int32"),
41
+ }
42
+ )
43
  return datasets.DatasetInfo(
44
  description=_DESCRIPTION,
45
+ features=features,
 
 
 
 
 
46
  supervised_keys=None,
47
  homepage=_HOMEPAGE,
48
+ license=_LICENSE,
49
  citation=_CITATION,
50
  )
51
 
52
  def _split_generators(self, dl_manager):
53
+ metadata_paths = dl_manager.download(_METADATA_URLS)
54
+ train_archive = dl_manager.download(_URLS["train"])
55
+ local_extracted_train_archive = dl_manager.extract(train_archive) if not dl_manager.is_streaming else None
56
+ train_dir = "train"
57
+
58
  return [
59
  datasets.SplitGenerator(
60
  name=datasets.Split.TRAIN,
61
  gen_kwargs={
62
+ "metadata_path": metadata_paths["train"],
63
+ "local_extracted_archive": local_extracted_train_archive,
64
+ "path_to_clips": train_dir,
65
+ "audio_files": dl_manager.iter_archive(train_archive),
66
+ },
67
+ ),
68
  ]
69
+
70
+ def _generate_examples(self, metadata_path, local_extracted_archive, path_to_clips, audio_files):
71
+ """Yields examples as (key, example) tuples."""
72
+ examples = {}
73
+ with open(metadata_path, encoding="utf-8") as f:
74
+ for key, row in enumerate(f):
75
+ data = json.loads(row)
76
+ examples[data["path"]] = data
77
+ inside_clips_dir = False
78
+ id_ = 0
79
+ for path, f in audio_files:
80
+ if path.startswith(path_to_clips):
81
+ inside_clips_dir = True
82
+ if path in examples:
83
+ result = examples[path]
84
+ path = os.path.join(local_extracted_archive, path) if local_extracted_archive else path
85
+ result["audio"] = {"path": path, "bytes": f.read()}
86
+ result["path"] = path
87
+ yield id_, result
88
+ id_ += 1
89
+ elif inside_clips_dir:
90
+ break