albertvillanova HF staff commited on
Commit
7d33148
1 Parent(s): 0e634bb

Delete loading script

Browse files
Files changed (1) hide show
  1. arabic_speech_corpus.py +0 -145
arabic_speech_corpus.py DELETED
@@ -1,145 +0,0 @@
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
- """Arabic Speech Corpus"""
18
-
19
-
20
- import os
21
-
22
- import datasets
23
- from datasets.tasks import AutomaticSpeechRecognition
24
-
25
-
26
- _CITATION = """\
27
- @phdthesis{halabi2016modern,
28
- title={Modern standard Arabic phonetics for speech synthesis},
29
- author={Halabi, Nawar},
30
- year={2016},
31
- school={University of Southampton}
32
- }
33
- """
34
-
35
- _DESCRIPTION = """\
36
- This Speech corpus has been developed as part of PhD work carried out by Nawar Halabi at the University of Southampton.
37
- The corpus was recorded in south Levantine Arabic
38
- (Damascian accent) using a professional studio. Synthesized speech as an output using this corpus has produced a high quality, natural voice.
39
- Note that in order to limit the required storage for preparing this dataset, the audio
40
- is stored in the .flac format and is not converted to a float32 array. To convert, the audio
41
- file to a float32 array, please make use of the `.map()` function as follows:
42
-
43
-
44
- ```python
45
- import soundfile as sf
46
-
47
- def map_to_array(batch):
48
- speech_array, _ = sf.read(batch["file"])
49
- batch["speech"] = speech_array
50
- return batch
51
-
52
- dataset = dataset.map(map_to_array, remove_columns=["file"])
53
- ```
54
- """
55
-
56
- _URL = "http://en.arabicspeechcorpus.com/arabic-speech-corpus.zip"
57
-
58
-
59
- class ArabicSpeechCorpusConfig(datasets.BuilderConfig):
60
- """BuilderConfig for ArabicSpeechCorpu."""
61
-
62
- def __init__(self, **kwargs):
63
- """
64
- Args:
65
- data_dir: `string`, the path to the folder containing the files in the
66
- downloaded .tar
67
- citation: `string`, citation for the data set
68
- url: `string`, url for information about the data set
69
- **kwargs: keyword arguments forwarded to super.
70
- """
71
- super(ArabicSpeechCorpusConfig, self).__init__(version=datasets.Version("2.1.0", ""), **kwargs)
72
-
73
-
74
- class ArabicSpeechCorpus(datasets.GeneratorBasedBuilder):
75
- """ArabicSpeechCorpus dataset."""
76
-
77
- BUILDER_CONFIGS = [
78
- ArabicSpeechCorpusConfig(name="clean", description="'Clean' speech."),
79
- ]
80
-
81
- def _info(self):
82
- return datasets.DatasetInfo(
83
- description=_DESCRIPTION,
84
- features=datasets.Features(
85
- {
86
- "file": datasets.Value("string"),
87
- "text": datasets.Value("string"),
88
- "audio": datasets.Audio(sampling_rate=48_000),
89
- "phonetic": datasets.Value("string"),
90
- "orthographic": datasets.Value("string"),
91
- }
92
- ),
93
- supervised_keys=("file", "text"),
94
- homepage=_URL,
95
- citation=_CITATION,
96
- task_templates=[AutomaticSpeechRecognition(audio_column="audio", transcription_column="text")],
97
- )
98
-
99
- def _split_generators(self, dl_manager):
100
- archive_path = dl_manager.download_and_extract(_URL)
101
- archive_path = os.path.join(archive_path, "arabic-speech-corpus")
102
- return [
103
- datasets.SplitGenerator(name="train", gen_kwargs={"archive_path": archive_path}),
104
- datasets.SplitGenerator(name="test", gen_kwargs={"archive_path": os.path.join(archive_path, "test set")}),
105
- ]
106
-
107
- def _generate_examples(self, archive_path):
108
- """Generate examples from a Librispeech archive_path."""
109
- lab_dir = os.path.join(archive_path, "lab")
110
- wav_dir = os.path.join(archive_path, "wav")
111
- if "test set" in archive_path:
112
- phonetic_path = os.path.join(archive_path, "phonetic-transcript.txt")
113
- else:
114
- phonetic_path = os.path.join(archive_path, "phonetic-transcipt.txt")
115
-
116
- orthographic_path = os.path.join(archive_path, "orthographic-transcript.txt")
117
-
118
- phonetics = {}
119
- orthographics = {}
120
-
121
- with open(phonetic_path, "r", encoding="utf-8") as f:
122
- for line in f:
123
- wav_file, phonetic = line.split('"')[1::2]
124
- phonetics[wav_file] = phonetic
125
-
126
- with open(orthographic_path, "r", encoding="utf-8") as f:
127
- for line in f:
128
- wav_file, orthographic = line.split('"')[1::2]
129
- orthographics[wav_file] = orthographic
130
-
131
- for _id, lab_name in enumerate(sorted(os.listdir(lab_dir))):
132
- lab_path = os.path.join(lab_dir, lab_name)
133
- lab_text = open(lab_path, "r", encoding="utf-8").read()
134
-
135
- wav_name = lab_name[:-4] + ".wav"
136
- wav_path = os.path.join(wav_dir, wav_name)
137
-
138
- example = {
139
- "file": wav_path,
140
- "audio": wav_path,
141
- "text": lab_text,
142
- "phonetic": phonetics[wav_name],
143
- "orthographic": orthographics[wav_name],
144
- }
145
- yield str(_id), example