File size: 2,429 Bytes
989405b 0eddd56 989405b 8d6264f 989405b fb9c787 989405b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
## -*- coding: utf-8 -*-
#"""dataset.ipynb
#Automatically generated by Colaboratory.
#Original file is located at
# https://colab.research.google.com/drive/1wOuPHcfW52hoC68q5L32HM1uFqNSXvAl
#"""
import csv
import os
import datasets
logger = datasets.logging.get_logger(__name__)
_DESCRIPTION = "Custom dataset for extracting audio files and matching sentences."
_DATA_URL = "https://huggingface.co/datasets/ugshanyu/jambal2/resolve/main" # Replace with the URL of your data
class CustomDataset(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
def _info(self):
features = datasets.Features(
{
"audio": datasets.Audio(sampling_rate=16_000),
"sentence": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=("audio", "sentence"),
homepage=None,
citation=None,
)
def _split_generators(self, dl_manager):
audio_path = dl_manager.download_and_extract(_DATA_URL+"/test.zip")
csv_path = dl_manager.download_and_extract(_DATA_URL+"/col.csv")
# dir_inside_zip = os.listdir(audio_path)[0] # Assume the first directory is the one you're interested in
# audio_path = os.path.join(audio_path, dir_inside_zip)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"audio_path": audio_path, "csv_path": csv_path},
)
]
def _generate_examples(self, audio_path, csv_path):
print(audio_path)
print(csv_path)
key = 0
print(os.listdir(audio_path))
with open(csv_path, encoding="utf-8") as csv_file:
csv_reader = csv.DictReader(csv_file)
for row in csv_reader:
original_sentence_id, sentence = row.values()
if(original_sentence_id == "01524c04b1e47dbcd27c8828c8a58b75f83e188495e7ad24f99a19fade08dc8a"):
continue
audio_file = f"{original_sentence_id}.mp3"
audio_file_path = os.path.join(audio_path, audio_file)
yield key, {
"audio": audio_file_path,
"sentence": sentence,
}
key += 1
#!pip install datasets |