Commit
•
212b70c
1
Parent(s):
e6f8c5a
initial commit
Browse files- README.md +19 -0
- babelbox_voice.py +127 -0
README.md
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
annotations_creators:
|
2 |
+
- crowdsourced
|
3 |
+
language:
|
4 |
+
- sv-SE
|
5 |
+
language_creators:
|
6 |
+
- crowdsourced
|
7 |
+
license:
|
8 |
+
- cc0-1.0
|
9 |
+
multilinguality:
|
10 |
+
- monolingual
|
11 |
+
pretty_name: Babelbox Voice
|
12 |
+
size_categories:
|
13 |
+
- 100K<n<1M
|
14 |
+
source_datasets: []
|
15 |
+
tags:
|
16 |
+
- NST
|
17 |
+
task_categories:
|
18 |
+
- automatic-speech-recognition
|
19 |
+
task_ids: []
|
babelbox_voice.py
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
""" Babelbox Voice Dataset"""
|
2 |
+
|
3 |
+
import csv
|
4 |
+
import os
|
5 |
+
import urllib
|
6 |
+
|
7 |
+
import datasets
|
8 |
+
import requests
|
9 |
+
import glob
|
10 |
+
import gzip
|
11 |
+
from typing import List
|
12 |
+
from datasets.utils.py_utils import size_str
|
13 |
+
logger = datasets.logging.get_logger(__name__)
|
14 |
+
import torchaudio
|
15 |
+
import torch
|
16 |
+
from tqdm import tqdm
|
17 |
+
|
18 |
+
_CITATION = """\
|
19 |
+
@inproceedings{babelboxvoice:2022,
|
20 |
+
author = {Andersson, O. and Bjelkenhed, M. and Bielsa, M. et al},
|
21 |
+
title = {Babelbox Voice: A Speech Corpus for training Whisper},
|
22 |
+
year = 2022
|
23 |
+
}
|
24 |
+
"""
|
25 |
+
|
26 |
+
class BabelboxVoiceConfig(datasets.BuilderConfig):
|
27 |
+
"""BuilderConfig for BabelboxVoice."""
|
28 |
+
|
29 |
+
def __init__(self, name, version, **kwargs):
|
30 |
+
self.name = name
|
31 |
+
self.version = version
|
32 |
+
self.features = kwargs.pop("features", None)
|
33 |
+
self.description = kwargs.pop("description", None)
|
34 |
+
self.archive_url = kwargs.pop("archive_url", None)
|
35 |
+
self.meta_url = kwargs.pop("meta_url", None)
|
36 |
+
|
37 |
+
description = (
|
38 |
+
f"Babelbox Voice speech to text dataset."
|
39 |
+
)
|
40 |
+
super(BabelboxVoiceConfig, self).__init__(
|
41 |
+
name=name,
|
42 |
+
version=version,
|
43 |
+
**kwargs,
|
44 |
+
)
|
45 |
+
|
46 |
+
|
47 |
+
class BabelboxVoice(datasets.GeneratorBasedBuilder):
|
48 |
+
|
49 |
+
VERSION = datasets.Version("1.0.0")
|
50 |
+
|
51 |
+
BUILDER_CONFIGS = [
|
52 |
+
BabelboxVoiceConfig(
|
53 |
+
name="nst",
|
54 |
+
version=VERSION,
|
55 |
+
description="This part of Pandora Voice includes data from National Library of Norway",
|
56 |
+
features=["path", "audio", "sentence"],
|
57 |
+
archive_url="/home/jovyan/shared-data/data/nst/archive",
|
58 |
+
meta_url="/home/jovyan/shared-data/data/nst/NST_se.csv"
|
59 |
+
)
|
60 |
+
]
|
61 |
+
|
62 |
+
DEFAULT_CONFIG_NAME = "nst"
|
63 |
+
|
64 |
+
def _info(self):
|
65 |
+
description = (
|
66 |
+
"Babelbox Voice is an initiative to help teach machines how real people speak. "
|
67 |
+
)
|
68 |
+
if self.config.name == "nst":
|
69 |
+
features = datasets.Features(
|
70 |
+
{
|
71 |
+
"path": datasets.Value("string"),
|
72 |
+
"audio": datasets.features.Audio(sampling_rate=16_000),
|
73 |
+
"sentence": datasets.Value("string")
|
74 |
+
}
|
75 |
+
)
|
76 |
+
|
77 |
+
return datasets.DatasetInfo(
|
78 |
+
description=description,
|
79 |
+
features=features,
|
80 |
+
supervised_keys=None,
|
81 |
+
version=self.config.version
|
82 |
+
)
|
83 |
+
|
84 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
85 |
+
|
86 |
+
archive_dir="/home/jovyan/shared-data/data/nst/archive"
|
87 |
+
archive_files = sorted(glob.glob(archive_dir + '/**.tar.gz'), reverse=False)
|
88 |
+
|
89 |
+
archive_paths = dl_manager.download(archive_files)
|
90 |
+
|
91 |
+
local_extracted_archive_paths = dl_manager.extract(archive_paths) if not dl_manager.is_streaming else {}
|
92 |
+
|
93 |
+
meta_url = self.config.meta_url
|
94 |
+
|
95 |
+
meta_path = dl_manager.download_and_extract(meta_url)
|
96 |
+
|
97 |
+
metadata = {}
|
98 |
+
with open(meta_path, encoding="utf-8") as f:
|
99 |
+
reader = csv.DictReader(f)
|
100 |
+
for row in tqdm(reader, desc="Reading metadata..."):
|
101 |
+
filename = row['filename_channel_1']
|
102 |
+
sentence = row['text']
|
103 |
+
metadata[filename] = sentence
|
104 |
+
|
105 |
+
return [
|
106 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN,
|
107 |
+
gen_kwargs={
|
108 |
+
"local_extracted_archive_paths": local_extracted_archive_paths,
|
109 |
+
"archives": [dl_manager.iter_archive(path) for path in archive_paths],
|
110 |
+
"metadata": metadata
|
111 |
+
})
|
112 |
+
]
|
113 |
+
|
114 |
+
def _generate_examples(self, local_extracted_archive_paths, archives, metadata):
|
115 |
+
|
116 |
+
sampling_rate = 16000
|
117 |
+
|
118 |
+
for i, audio_archive in enumerate(archives):
|
119 |
+
for path, file in audio_archive:
|
120 |
+
if local_extracted_archive_paths == False:
|
121 |
+
path = os.path.join(local_extracted_archive_paths[i], path)
|
122 |
+
result = dict()
|
123 |
+
result["path"] = path
|
124 |
+
result["audio"] = {"path": path, "bytes": file.read()}
|
125 |
+
result["sentence"] = metadata[path]
|
126 |
+
yield path, result
|
127 |
+
|