kresnik namvandy commited on
Commit
1acd883
1 Parent(s): 5225ee1

Update zeroth_korean.py (#1)

Browse files

- Update zeroth_korean.py (2e0772a8878d88b2fcdd471a0f0a0d6f0dfc0af2)


Co-authored-by: Songwoojin <namvandy@users.noreply.huggingface.co>

Files changed (1) hide show
  1. zeroth_korean.py +111 -111
zeroth_korean.py CHANGED
@@ -1,112 +1,112 @@
1
- # coding=utf-8
2
- # Copyright 2021 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
- # Lint as: python3
17
- """Librispeech automatic speech recognition dataset."""
18
-
19
- from __future__ import absolute_import, division, print_function
20
-
21
- import glob
22
- import os
23
-
24
- import datasets
25
-
26
-
27
- _CITATION = """\
28
-
29
- """
30
-
31
- _DESCRIPTION = """\
32
- This is Zeroth-Korean corpus,
33
- licensed under Attribution 4.0 International (CC BY 4.0)
34
- The data set contains transcriebed audio data for Korean. There are 51.6 hours transcribed Korean audio for training data (22,263 utterances, 105 people, 3000 sentences) and 1.2 hours transcribed Korean audio for testing data (457 utterances, 10 people). This corpus also contains pre-trained/designed language model, lexicon and morpheme-based segmenter(morfessor).
35
- Zeroth project introduces free Korean speech corpus and aims to make Korean speech recognition more broadly accessible to everyone.
36
- This project was developed in collaboration between Lucas Jo(@Atlas Guide Inc.) and Wonkyum Lee(@Gridspace Inc.).
37
-
38
- Contact: Lucas Jo(lucasjo@goodatlas.com), Wonkyum Lee(wonkyum@gridspace.com)
39
- """
40
-
41
- _URL = "http://www.openslr.org/40"
42
- _DL_URL = "https://www.openslr.org/resources/40/zeroth_korean.tar.gz"
43
-
44
-
45
- class ZerothKoreanASRConfig(datasets.BuilderConfig):
46
-
47
-
48
- def __init__(self, **kwargs):
49
- """
50
- Args:
51
- data_dir: `string`, the path to the folder containing the files in the
52
- downloaded .tar
53
- citation: `string`, citation for the data set
54
- url: `string`, url for information about the data set
55
- **kwargs: keyword arguments forwarded to super.
56
- """
57
- super(ZerothKoreanASRConfig, self).__init__(version=datasets.Version("1.0.1", ""), **kwargs)
58
-
59
-
60
- class ZerothKoreanASR(datasets.GeneratorBasedBuilder):
61
- """Librispeech dataset."""
62
-
63
- BUILDER_CONFIGS = [
64
- ZerothKoreanASRConfig(name="clean", description="'Clean' speech.")
65
- ]
66
-
67
- def _info(self):
68
- return datasets.DatasetInfo(
69
- description=_DESCRIPTION,
70
- features=datasets.Features(
71
- {
72
- "file": datasets.Value("string"),
73
- "audio": datasets.features.Audio(sampling_rate=16_000),
74
- "text": datasets.Value("string"),
75
- "speaker_id": datasets.Value("int64"),
76
- "chapter_id": datasets.Value("int64"),
77
- "id": datasets.Value("string"),
78
- }
79
- ),
80
- supervised_keys=("speech", "text"),
81
- homepage=_URL,
82
- citation=_CITATION,
83
- )
84
-
85
- def _split_generators(self, dl_manager):
86
- archive_path = dl_manager.download_and_extract(_DL_URL)
87
- #print(archive_path)
88
- return [
89
- datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"archive_path": archive_path, "split_name": f"train_data_01"}),
90
- datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"archive_path": archive_path, "split_name": f"test_data_01"}),
91
- ]
92
-
93
- def _generate_examples(self, archive_path, split_name):
94
-
95
- transcripts_glob = os.path.join(archive_path, split_name, "*/*/*.txt")
96
- for transcript_file in glob.glob(transcripts_glob):
97
- path = os.path.dirname(transcript_file)
98
- with open(os.path.join(path, transcript_file)) as f:
99
- for line in f:
100
- line = line.strip()
101
- key, transcript = line.split(" ", 1)
102
- audio_file = f"{key}.flac"
103
- speaker_id, chapter_id = [int(el) for el in key.split("_")[:2]]
104
- example = {
105
- "id": key,
106
- "speaker_id": speaker_id,
107
- "chapter_id": chapter_id,
108
- "file": os.path.join(path, audio_file),
109
- "audio": os.path.join(path, audio_file),
110
- "text": transcript,
111
- }
112
  yield key, example
 
1
+ # coding=utf-8
2
+ # Copyright 2021 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Lint as: python3
17
+ """Librispeech automatic speech recognition dataset."""
18
+
19
+ from __future__ import absolute_import, division, print_function
20
+
21
+ import glob
22
+ import os
23
+
24
+ import datasets
25
+
26
+
27
+ _CITATION = """\
28
+
29
+ """
30
+
31
+ _DESCRIPTION = """\
32
+ This is Zeroth-Korean corpus,
33
+ licensed under Attribution 4.0 International (CC BY 4.0)
34
+ The data set contains transcriebed audio data for Korean. There are 51.6 hours transcribed Korean audio for training data (22,263 utterances, 105 people, 3000 sentences) and 1.2 hours transcribed Korean audio for testing data (457 utterances, 10 people). This corpus also contains pre-trained/designed language model, lexicon and morpheme-based segmenter(morfessor).
35
+ Zeroth project introduces free Korean speech corpus and aims to make Korean speech recognition more broadly accessible to everyone.
36
+ This project was developed in collaboration between Lucas Jo(@Atlas Guide Inc.) and Wonkyum Lee(@Gridspace Inc.).
37
+
38
+ Contact: Lucas Jo(lucasjo@goodatlas.com), Wonkyum Lee(wonkyum@gridspace.com)
39
+ """
40
+
41
+ _URL = "http://www.openslr.org/40"
42
+ _DL_URL = "https://www.openslr.org/resources/40/zeroth_korean.tar.gz"
43
+
44
+
45
+ class ZerothKoreanASRConfig(datasets.BuilderConfig):
46
+
47
+
48
+ def __init__(self, **kwargs):
49
+ """
50
+ Args:
51
+ data_dir: `string`, the path to the folder containing the files in the
52
+ downloaded .tar
53
+ citation: `string`, citation for the data set
54
+ url: `string`, url for information about the data set
55
+ **kwargs: keyword arguments forwarded to super.
56
+ """
57
+ super(ZerothKoreanASRConfig, self).__init__(version=datasets.Version("1.0.1", ""), **kwargs)
58
+
59
+
60
+ class ZerothKoreanASR(datasets.GeneratorBasedBuilder):
61
+ """Librispeech dataset."""
62
+
63
+ BUILDER_CONFIGS = [
64
+ ZerothKoreanASRConfig(name="clean", description="'Clean' speech.")
65
+ ]
66
+
67
+ def _info(self):
68
+ return datasets.DatasetInfo(
69
+ description=_DESCRIPTION,
70
+ features=datasets.Features(
71
+ {
72
+ "file": datasets.Value("string"),
73
+ "audio": datasets.features.Audio(sampling_rate=16_000),
74
+ "text": datasets.Value("string"),
75
+ "speaker_id": datasets.Value("int64"),
76
+ "chapter_id": datasets.Value("int64"),
77
+ "id": datasets.Value("string"),
78
+ }
79
+ ),
80
+ supervised_keys=("speech", "text"),
81
+ homepage=_URL,
82
+ citation=_CITATION,
83
+ )
84
+
85
+ def _split_generators(self, dl_manager):
86
+ archive_path = dl_manager.download_and_extract(_DL_URL)
87
+ #print(archive_path)
88
+ return [
89
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"archive_path": archive_path, "split_name": f"train_data_01"}),
90
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"archive_path": archive_path, "split_name": f"test_data_01"}),
91
+ ]
92
+
93
+ def _generate_examples(self, archive_path, split_name):
94
+
95
+ transcripts_glob = os.path.join(archive_path, split_name, "*/*/*.txt")
96
+ for transcript_file in glob.glob(transcripts_glob):
97
+ path = os.path.dirname(transcript_file)
98
+ with open(os.path.join(path, transcript_file), encoding="utf-8-sig") as f:
99
+ for line in f:
100
+ line = line.strip()
101
+ key, transcript = line.split(" ", 1)
102
+ audio_file = f"{key}.flac"
103
+ speaker_id, chapter_id = [int(el) for el in key.split("_")[:2]]
104
+ example = {
105
+ "id": key,
106
+ "speaker_id": speaker_id,
107
+ "chapter_id": chapter_id,
108
+ "file": os.path.join(path, audio_file),
109
+ "audio": os.path.join(path, audio_file),
110
+ "text": transcript,
111
+ }
112
  yield key, example