Datasets:

Languages:
English
ArXiv:
License:
sesge / sesge.py
Gabi00's picture
Upload sesge.py
4bd48fe verified
raw
history blame
4.5 kB
import csv
import os
import json
import datasets
from datasets.utils.py_utils import size_str
from tqdm import tqdm
from scipy.io.wavfile import read, write
import io
#from .release_stats import STATS
_CITATION = """\
@inproceedings{demint2024,
author = {Pérez-Ortiz, Juan Antonio and
Esplà-Gomis, Miquel and
Sánchez-Cartagena, Víctor M. and
Sánchez-Martínez, Felipe and
Chernysh, Roman and
Mora-Rodríguez, Gabriel and
Berezhnoy, Lev},
title = {{DeMINT}: Automated Language Debriefing for English Learners via {AI}
Chatbot Analysis of Meeting Transcripts},
booktitle = {Proceedings of the 13th Workshop on NLP for Computer Assisted Language Learning},
month = october,
year = {2024},
url = {https://aclanthology.org/volumes/2024.nlp4call-1/},
}
"""
class SesgeConfig(datasets.BuilderConfig):
def __init__(self, name, version, **kwargs):
self.language = kwargs.pop("language", None)
self.release_date = kwargs.pop("release_date", None)
"""
description = (
f"Common Voice speech to text dataset in {self.language} released on {self.release_date}. "
f"The dataset comprises {self.validated_hr} hours of validated transcribed speech data "
f"out of {self.total_hr} hours in total from {self.num_speakers} speakers. "
f"The dataset contains {self.num_clips} audio clips and has a size of {self.size_human}."
)
"""
super(SesgeConfig, self).__init__(
name=name,
**kwargs,
)
class Sesge():
BUILDER_CONFIGS = [
SesgeConfig(
name="sesge",
version=1.0,
language='eng',
release_date="2024-10-8",
)
]
def _info(self):
total_languages = 1
total_valid_hours = 1
description = (
"Common Voice is Mozilla's initiative to help teach machines how real people speak. "
f"The dataset currently consists of {total_valid_hours} validated hours of speech "
f" in {total_languages} languages, but more voices and languages are always added."
)
features = datasets.Features(
{
"audio": datasets.features.Audio(sampling_rate=48_000),
"sentence": datasets.Value("string"),
}
)
def _generate_examples(self, local_extracted_archive_paths, archives, meta_path, split):
archives = os.listdir(archives)
print(archives)
metadata = {}
with open(meta_path, encoding="utf-8") as f:
reader = csv.DictReader(f, delimiter=";", quoting=csv.QUOTE_NONE)
for row in tqdm(reader):
metadata[row["file_name"]] = row
#print(metadata)
for i, path in enumerate(archives):
#for path, file in audio_archive:
_, filename = os.path.split(path)
file = os.path.join("data", split, filename)
#print(filename)
if file in metadata:
result = dict(metadata[file])
print("Result: ", result)
with open(os.path.join(local_extracted_archive_paths, filename), 'rb') as wavfile:
input_wav = wavfile.read()
rate, data = read(io.BytesIO(input_wav))
# data is a numpy ND array representing the audio data. Let's do some stuff with it
reversed_data = data[::-1] #reversing it
#then, let's save it to a BytesIO object, which is a buffer for bytes object
bytes_wav = bytes()
byte_io = io.BytesIO(bytes_wav)
write(byte_io, rate, reversed_data)
output_wav = byte_io.read()
# set the audio feature and the path to the extracted file
path = os.path.join(local_extracted_archive_paths[i], path)
result["audio"] = {"path": path, "bytes": data}
result["path"] = path
yield path, result
else:
print("No file found")
yield None, None
if __name__ == '__main__':
data = Sesge()
gen = data._generate_examples("/Users/rafael/Desktop/TFM/Transformes/Demint/Base de datos/COnver/datos/", "/Users/rafael/Desktop/TFM/Transformes/Demint/Base de datos/COnver/datos/", "/Users/rafael/Desktop/TFM/Transformes/Demint/Base de datos/COnver/metadata.csv", "train")
print(next(gen))