txya900619
commited on
Commit
•
ce380eb
1
Parent(s):
d5ac730
Upload ./AudioSCAN-StyleTTS2-female.py with huggingface_hub
Browse files- AudioSCAN-StyleTTS2-female.py +102 -0
AudioSCAN-StyleTTS2-female.py
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import os
|
3 |
+
|
4 |
+
import datasets
|
5 |
+
|
6 |
+
from .configs import CONFIGS_MAP
|
7 |
+
|
8 |
+
_BASE_URL = "https://huggingface.co/datasets/formospeech/AudioSCAN-StyleTTS2-female/resolve/main/"
|
9 |
+
_AUDIO_URL = _BASE_URL + "audio.tar.gz"
|
10 |
+
|
11 |
+
|
12 |
+
class AudioSCANConfig(datasets.BuilderConfig):
|
13 |
+
"""BuilderConfig for CommonVoice."""
|
14 |
+
|
15 |
+
def __init__(self, **kwargs):
|
16 |
+
super(AudioSCANConfig, self).__init__(
|
17 |
+
version=datasets.Version("0.1.0", ""), **kwargs
|
18 |
+
)
|
19 |
+
|
20 |
+
|
21 |
+
class LibrispeechASR(datasets.GeneratorBasedBuilder):
|
22 |
+
DEFAULT_WRITER_BATCH_SIZE = 256
|
23 |
+
DEFAULT_CONFIG_NAME = "addprim_jump"
|
24 |
+
BUILDER_CONFIGS = []
|
25 |
+
for config_name in CONFIGS_MAP.keys():
|
26 |
+
BUILDER_CONFIGS.append(
|
27 |
+
AudioSCANConfig(
|
28 |
+
name=config_name,
|
29 |
+
description=None,
|
30 |
+
)
|
31 |
+
)
|
32 |
+
|
33 |
+
def _info(self):
|
34 |
+
return datasets.DatasetInfo(
|
35 |
+
description="",
|
36 |
+
features=datasets.Features(
|
37 |
+
{
|
38 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
39 |
+
"out": datasets.Value("string"),
|
40 |
+
"in": datasets.Value("string"),
|
41 |
+
}
|
42 |
+
),
|
43 |
+
license=None,
|
44 |
+
supervised_keys=("audio", "out"),
|
45 |
+
homepage=None,
|
46 |
+
citation=None,
|
47 |
+
task_templates=None,
|
48 |
+
)
|
49 |
+
|
50 |
+
def _split_generators(self, dl_manager):
|
51 |
+
archive_path = dl_manager.download(_AUDIO_URL)
|
52 |
+
local_extracted_archive = (
|
53 |
+
dl_manager.extract(archive_path) if not dl_manager.is_streaming else {}
|
54 |
+
)
|
55 |
+
|
56 |
+
split_meta_urls = {
|
57 |
+
split_name: _BASE_URL + split_meta_path
|
58 |
+
for split_name, split_meta_path in CONFIGS_MAP[self.config.name].items()
|
59 |
+
}
|
60 |
+
|
61 |
+
split_meta_paths = dl_manager.download_and_extract(split_meta_urls)
|
62 |
+
splits = []
|
63 |
+
for split_name in CONFIGS_MAP[self.config.name].keys():
|
64 |
+
split = datasets.SplitGenerator(
|
65 |
+
name=split_name,
|
66 |
+
gen_kwargs={
|
67 |
+
"meta_path": split_meta_paths[split_name],
|
68 |
+
"local_extracted_archive": local_extracted_archive,
|
69 |
+
"files": dl_manager.iter_archive(archive_path),
|
70 |
+
},
|
71 |
+
)
|
72 |
+
splits.append(split)
|
73 |
+
|
74 |
+
return splits
|
75 |
+
|
76 |
+
def _generate_examples(self, meta_path, local_extracted_archive, files):
|
77 |
+
with open(meta_path, "r") as f:
|
78 |
+
metadata = json.loads("[" + ",".join(f.readlines()) + "]")
|
79 |
+
|
80 |
+
audio_data = {}
|
81 |
+
for path, file in files:
|
82 |
+
filename = os.path.basename(path)
|
83 |
+
audio_data[filename] = file.read()
|
84 |
+
key = 0
|
85 |
+
for item in metadata:
|
86 |
+
path = (
|
87 |
+
os.path.join(local_extracted_archive, item["audio_path"])
|
88 |
+
if local_extracted_archive
|
89 |
+
else item["audio_path"]
|
90 |
+
)
|
91 |
+
yield (
|
92 |
+
key,
|
93 |
+
{
|
94 |
+
"in": item["in"],
|
95 |
+
"out": item["out"],
|
96 |
+
"audio": {
|
97 |
+
"path": path,
|
98 |
+
"bytes": audio_data[item["audio_path"]],
|
99 |
+
},
|
100 |
+
},
|
101 |
+
)
|
102 |
+
key += 1
|