Datasets:
Khmer Speech Dataset Processing
This repository contains scripts and instructions for preparing a Khmer speech dataset for machine learning tasks, such as automatic speech recognition (ASR). It demonstrates how to process a collection of audio files and metadata, and save them as Parquet files for efficient use in your training pipelines—without needing torchcodec.
All dataset audio and transcripts in this project are sourced from https://wmc.org.kh/, the official website of Women's Media Centre of Cambodia.
Overview
The workflow:
- Load metadata from a JSON file (e.g.
khmer_dataset.json). - Validate and collect audio file paths.
- Store metadata and paths in a HuggingFace Dataset—using string paths instead of encoded audio.
- Split dataset into train/test sets.
- Save the resulting datasets as Parquet files.
Note: Because
torchcodecis not installed or available, the dataset stores the paths to audio files, not the files themselves or their encoded waveforms.
Directory Structure
dataset/
├── audio_sharded/
│ ├── test-00000-of-00001.parquet
│ ├── train-00000-of-00001.parquet
├── data/
│ └── wmc/ # Directory with all Khmer audio files
├── khmer_dataset.json # Metadata for audio/transcripts
├── README.md
Requirements
Install required packages:
pip install torch datasets tqdm pandas pyarrow
Usage
Step 1: Prepare Input Files
- Ensure
khmer_dataset.jsonis in thedatasetdirectory. - Audio files should be in
../scrape_audio/wmc/. - All original audio content and transcripts in these files are downloaded directly from https://wmc.org.kh/.
Step 2: Run the Data Preparation Script
python data_preparation.py
- This script checks for GPU availability (for torch), reads metadata and audio paths, verifies the existence of audio files, then creates and splits the dataset, finally saving it as Parquet files.
Step 3: Parquet Outputs
- Train:
audio_sharded/train-00000-of-00001.parquet - Test:
audio_sharded/test-00000-of-00001.parquet
Viewing Parquet File Structure
Inspect Parquet column names and samples using pandas:
import pandas as pd
df = pd.read_parquet("audio_sharded/train-00000-of-00001.parquet")
print(df.columns) # Show structure
print(df.head()) # Show first few rows
Or using pyarrow:
import pyarrow.parquet as pq
table = pq.read_table("audio_sharded/train-00000-of-00001.parquet")
print(table.schema)
print(table.to_pandas().head())
Or reload using HuggingFace Datasets:
from datasets import Dataset
ds = Dataset.from_parquet("audio_sharded/train-00000-of-00001.parquet")
print(ds.features)
print(ds[0])
Manual Audio Loading Example
Since audio files are stored as paths in the dataset, load them as follows:
import torchaudio
# Suppose you loaded your train dataset as 'ds'
for sample in ds:
audio_path = sample["audio"]
waveform, sample_rate = torchaudio.load(audio_path)
# waveform: Tensor representation of audio
# sample_rate: Sampling rate of audio
Use this approach for training, inference, or further processing.
Notes
- All data (audio and transcripts) are originally from https://wmc.org.kh/.
- If you want automatic audio encoding and easier integration with HuggingFace models, you must install torchcodec and use
Audio()as a feature. This script instead stores paths to avoid codec dependency. - Double-check that all audio files referenced in your JSON exist in your audio directory.
- Adjust directories and file names as needed for your environment.
- Downloads last month
- 16