Delete nanospeech.py
Browse files- nanospeech.py +0 -55
nanospeech.py
DELETED
|
@@ -1,55 +0,0 @@
|
|
| 1 |
-
import tarfile
|
| 2 |
-
import json
|
| 3 |
-
from datasets import GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split, Features, Value
|
| 4 |
-
|
| 5 |
-
class Nanospeech(GeneratorBasedBuilder):
|
| 6 |
-
def _info(self):
|
| 7 |
-
return DatasetInfo(
|
| 8 |
-
description="NanoSpeech WebDataset archive with mp3 and JSON metadata",
|
| 9 |
-
features=Features({
|
| 10 |
-
"audio": Value("binary"),
|
| 11 |
-
"text": Value("string"),
|
| 12 |
-
"duration": Value("float32"),
|
| 13 |
-
}),
|
| 14 |
-
)
|
| 15 |
-
|
| 16 |
-
def _split_generators(self, dl_manager):
|
| 17 |
-
base_url = "https://huggingface.co/datasets/manojkmk/nanospeech/resolve/main"
|
| 18 |
-
|
| 19 |
-
shard_files = [
|
| 20 |
-
"shard-000000.tar",
|
| 21 |
-
"shard-000001.tar",
|
| 22 |
-
"shard-000002.tar",
|
| 23 |
-
"shard-000003.tar",
|
| 24 |
-
"shard-000004.tar",
|
| 25 |
-
]
|
| 26 |
-
|
| 27 |
-
shard_urls = [f"{base_url}/{filename}" for filename in shard_files]
|
| 28 |
-
shard_paths = dl_manager.download(shard_urls)
|
| 29 |
-
|
| 30 |
-
return [
|
| 31 |
-
SplitGenerator(
|
| 32 |
-
name=Split.TRAIN,
|
| 33 |
-
gen_kwargs={"shard_paths": shard_paths},
|
| 34 |
-
),
|
| 35 |
-
]
|
| 36 |
-
|
| 37 |
-
def _generate_examples(self, shard_paths):
|
| 38 |
-
key_id = 0
|
| 39 |
-
for tar_path in shard_paths:
|
| 40 |
-
with tarfile.open(tar_path, "r") as tar:
|
| 41 |
-
members = tar.getnames()
|
| 42 |
-
for name in members:
|
| 43 |
-
if name.endswith(".mp3"):
|
| 44 |
-
key = name.rsplit(".", 1)[0]
|
| 45 |
-
json_name = f"{key}.json"
|
| 46 |
-
|
| 47 |
-
mp3_data = tar.extractfile(name).read()
|
| 48 |
-
meta = json.loads(tar.extractfile(json_name).read())
|
| 49 |
-
|
| 50 |
-
yield key_id, {
|
| 51 |
-
"audio": mp3_data,
|
| 52 |
-
"text": meta["text"],
|
| 53 |
-
"duration": float(meta["duration"]),
|
| 54 |
-
}
|
| 55 |
-
key_id += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|