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