baneks-speech / baneks-speech.py
zeio's picture
fix(dependencies): moved dependency installation command upper
4e594cb verified
raw
history blame
No virus
2.57 kB
import os
from glob import glob
from pathlib import Path
import datasets
from datasets import Features, Value, Audio
os.system('pip install music-tag')
from music_tag import load_file
_DESCRIPTION = """
This dataset contains speech generated for anecdotes from the [baneks dataset](https://huggingface.co/datasets/zeio/baneks)
"""
_HOMEPAGE = "https://huggingface.co/datasets/zeio/baneks-speech"
_LICENSE = "Apache License Version 2.0"
_URL = "https://huggingface.co/datasets/zeio/baneks-speech/resolve/main/speech/{first:06d}-{last:06d}.tar.xz"
_N_TOTAL = 46_554
_N_BATCH = 1_000
class BaneksSpeech(datasets.GeneratorBasedBuilder):
"""Speech generated for anecdotes from the baneks dataset"""
VERSION = datasets.Version("10.10.2023")
def _info(self):
return datasets.DatasetInfo(
description = _DESCRIPTION,
features = Features(
{
"text": Value("string"),
"audio": Audio(sampling_rate = 22_050),
"artist": Value("string"),
"id": Value("int32"),
"source": Value("string")
}
),
homepage = _HOMEPAGE,
license = _LICENSE
)
def _split_generators(self, dl_manager):
offset = 0
paths = []
while offset < _N_TOTAL:
url = _URL.format(first = offset + 1, last = min(offset := offset + _N_BATCH, _N_TOTAL))
paths.append(dl_manager.download_and_extract(url))
break
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"paths": paths
}
)
]
def _generate_examples(self, paths: list[str]):
for path in paths:
for file in sorted(glob(os.path.join(path, "*"))):
components = Path(file).stem.split('.', maxsplit = 1)
assert len(components) == 2, f'Incorrect file name: {file}'
id_ = int(components[0])
source = components[1]
meta = load_file(file)
# artist = meta['artist']
# text = meta['lyrics']
# print(id_, source, artist, text)
yield f'{id_:08d}-{source}', {
'text': meta['lyrics'],
'audio': file,
'artist': meta['artist'],
'id': id_,
'source': source
}