aannabellee commited on
Commit
6cb9e6f
·
1 Parent(s): cc6d035

Delete test.py

Browse files
Files changed (1) hide show
  1. test.py +0 -132
test.py DELETED
@@ -1,132 +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
- """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
- @inproceedings{panayotov2015librispeech,
29
- title={Librispeech: an ASR corpus based on public domain audio books},
30
- author={Panayotov, Vassil and Chen, Guoguo and Povey, Daniel and Khudanpur, Sanjeev},
31
- booktitle={Acoustics, Speech and Signal Processing (ICASSP), 2015 IEEE International Conference on},
32
- pages={5206--5210},
33
- year={2015},
34
- organization={IEEE}
35
- }
36
- """
37
-
38
- _DESCRIPTION = """\
39
- LibriSpeech is a corpus of approximately 1000 hours of read English speech with sampling rate of 16 kHz,
40
- prepared by Vassil Panayotov with the assistance of Daniel Povey. The data is derived from read
41
- audiobooks from the LibriVox project, and has been carefully segmented and aligned.
42
- Note that in order to limit the required storage for preparing this dataset, the audio
43
- is stored in the .flac format and is not converted to a float32 array. To convert, the audio
44
- file to a float32 array, please make use of the `.map()` function as follows:
45
- ```python
46
- import soundfile as sf
47
- def map_to_array(batch):
48
- speech_array, _ = sf.read(batch["file"])
49
- batch["speech"] = speech_array
50
- return batch
51
- dataset = dataset.map(map_to_array, remove_columns=["file"])
52
- ```
53
- """
54
-
55
- _URL = "http://www.openslr.org/12"
56
- _DL_URL = "https://s3.amazonaws.com/datasets.huggingface.co/librispeech_asr/2.1.0/"
57
- _DL_URL = "https://s3.amazonaws.com/datasets.huggingface.co/librispeech_asr/2.1.0/"
58
-
59
- _DL_URLS = {
60
- "clean": {
61
- "dev": _DL_URL + "dev_clean.tar.gz",
62
- }
63
- }
64
-
65
-
66
- class LibrispeechASRConfig(datasets.BuilderConfig):
67
- """BuilderConfig for LibriSpeechASR."""
68
-
69
- def __init__(self, **kwargs):
70
- """
71
- Args:
72
- data_dir: `string`, the path to the folder containing the files in the
73
- downloaded .tar
74
- citation: `string`, citation for the data set
75
- url: `string`, url for information about the data set
76
- **kwargs: keyword arguments forwarded to super.
77
- """
78
- super(LibrispeechASRConfig, self).__init__(version=datasets.Version("2.1.0", ""), **kwargs)
79
-
80
-
81
- class LibrispeechASR(datasets.GeneratorBasedBuilder):
82
- """Librispeech dataset."""
83
-
84
- BUILDER_CONFIGS = [
85
- LibrispeechASRConfig(name="clean", description="'Clean' speech."),
86
- LibrispeechASRConfig(name="other", description="'Other', more challenging, speech."),
87
- ]
88
-
89
- def _info(self):
90
- return datasets.DatasetInfo(
91
- description=_DESCRIPTION,
92
- features=datasets.Features(
93
- {
94
- "file": datasets.Value("string"),
95
- "audio": datasets.features.Audio(sampling_rate=16_000),
96
- "text": datasets.Value("string"),
97
- "speaker_id": datasets.Value("int64"),
98
- "chapter_id": datasets.Value("int64"),
99
- "id": datasets.Value("string"),
100
- }
101
- ),
102
- supervised_keys=("speech", "text"),
103
- homepage=_URL,
104
- citation=_CITATION,
105
- )
106
-
107
- def _split_generators(self, dl_manager):
108
- archive_path = dl_manager.download_and_extract(_DL_URLS[self.config.name])
109
- return [
110
- datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"archive_path": archive_path["dev"], "split_name": f"dev_{self.config.name}"}),
111
- ]
112
-
113
- def _generate_examples(self, archive_path, split_name):
114
- """Generate examples from a Librispeech archive_path."""
115
- transcripts_glob = os.path.join(archive_path, split_name, "*/*/*.txt")
116
- for transcript_file in glob.glob(transcripts_glob):
117
- path = os.path.dirname(transcript_file)
118
- with open(os.path.join(path, transcript_file)) as f:
119
- for line in f:
120
- line = line.strip()
121
- key, transcript = line.split(" ", 1)
122
- audio_file = f"{key}.flac"
123
- speaker_id, chapter_id = [int(el) for el in key.split("-")[:2]]
124
- example = {
125
- "id": key,
126
- "speaker_id": speaker_id,
127
- "chapter_id": chapter_id,
128
- "file": os.path.join(path, audio_file),
129
- "audio": os.path.join(path, audio_file),
130
- "text": transcript,
131
- }
132
- yield key, example