Datasets:

Modalities:
Audio
Text
Formats:
parquet
Languages:
Kazakh
DOI:
Libraries:
Datasets
Dask
License:

Fix. streaming=True. Maybe - file ID is "dataset/audio3/41/512_84"

#2
by DiDustin - opened

from datasets import load_dataset, Audio
sampling_rate = 16000
cache_dir = "./ft_data/"

kk_dataset = load_dataset("farabi-lab/kazakh-stt", split="train", streaming=True, cache_dir=cache_dir)
kk_dataset = kk_dataset.cast_column("audio", Audio(sampling_rate=sampling_rate))
kk_samples = select_audio_files(kk_dataset, target_duration_hours=8, max_duration=7)

def select_audio_files(dataset, target_duration_hours=8, max_duration=7):
selected_samples = []
total_duration = 0 # in seconds
target_duration = target_duration_hours * 60 * 60

for sample in dataset:
    # any code, and rise error after 160. on 
    pass
return selected_samples

LibsndfileError: Error opening <_io.BytesIO object at 0x7af484dde1b0>: Format not recognised.

same iss/
https://discuss.huggingface.co/t/stuck-in-preprocessing-audio-data-in-hgs-audio-course-while-following-filtering-the-dataset/67909


File ~/server_jupyter/venv/lib/python3.12/site-packages/soundfile.py:1216, in SoundFile._open(self, file, mode_int, closefd)
   1213 if file_ptr == _ffi.NULL:
   1214     # get the actual error code
   1215     err = _snd.sf_error(file_ptr)
-> 1216     raise LibsndfileError(err, prefix="Error opening {0!r}: ".format(self.name))
   1217 if mode_int == _snd.SFM_WRITE:
   1218     # Due to a bug in libsndfile version <= 1.0.25, frames != 0
   1219     # when opening a named pipe in SFM_WRITE mode.
   1220     # See http://github.com/erikd/libsndfile/issues/77.
   1221     self._info.frames = 0

LibsndfileError: Error opening <_io.BytesIO object at 0x7af484dde1b0>: Format not recognised.

datasets==3.0.1

Try running this code to process audio files with streaming data.

download is work, but stream with err.

Fix: File num.id 161 - in second list of preview, file ID is "dataset/audio3/41/512_84"

AL-FARABI KAZAKH NATIONAL UNIVERSITY org

Thank you for informing,

Here is reply for your questions.

  1. File streaming:

This is may due to the uploaded audio file will be turned into numpy array like following:

{'path': '349_123.wav', 'array': array([-0.0007019 , -0.00115967, -0.00115967, ..., 0.00231934,
0.00259399, 0.00198364]), 'sampling_rate': 16000}

Hence, to download the raw source file, here need the decode step like following:

from datasets import load_dataset, Audio
import librosa
import soundfile as sf # For saving audio
import os

cache_dir = "./ft_data/"
sampling_rate = 16000
kk_dataset = load_dataset("farabi-lab/kazakh-stt", split="train", streaming=True, cache_dir=cache_dir)

kk_dataset = kk_dataset.cast_column("audio", Audio(sampling_rate=sampling_rate, decode=True))

def save_multiple_decoded_files_librosa(dataset, num_samples=5, output_dir="./decoded_samples", sampling_rate=16000):
os.makedirs(output_dir, exist_ok=True)
for i, sample in enumerate(dataset):
if i >= num_samples:
break

    audio_data = sample['audio']['array']
    output_path = os.path.join(output_dir, f"sample_{i + 1}.wav")
    sf.write(output_path, audio_data, sampling_rate)
    print(f"Sample {i + 1} saved to {output_path}")

save_multiple_decoded_files_librosa(kk_dataset, num_samples=5, output_dir=os.path.join(cache_dir, "decoded_samples"), sampling_rate=sampling_rate)

This also could be done with torchaudio.

  1. For the sample ID,

Here i checked the the viewer from preview:

"dataset/audio3/41/512_84
бұлардың мінгендері кәкір-шүкір тай-тұяқ емес он күн желіске шыдай алар аласа бойлы тоқпақ жалды құшақ құйрықты кілең сайгүлік"

The text and audio file is match, then the id and path is match with the source audio files.
Could you please provide the detailed information.

Regards,

Sign up or log in to comment