Sdab
Khmer Automatic Speech Recognition (Whisper + Wav2Vec2)
Sdab is a lightweight helper around Hugging Face ASR models with a focus on Khmer language. It can load sequence-to-sequence Whisper checkpoints (default) or CTC-style Wav2Vec2 models, convert audio to the expected format, and return a transcription in a single call.
- License: Apache-2.0
- Default Whisper model: metythorn/whisper-large-v3
- Optional turbo Whisper model: metythorn/whisper-large-v3-turbo
- Example Wav2Vec2 model: metythorn/wav2vec2-xls-r-300m
Features
- 🔁 Automatically detects Whisper vs Wav2Vec2 when you pass a Hugging Face repo ID or local directory.
- 🎧 Handles loading, mono conversion, and resampling to 16 kHz with
torchaudio. - ⚙️ Lets you pick CPU/GPU device and numerical precision to match your hardware.
- 🧪 Includes a sample audio clip for quick testing.
Installation
It is highly recommended to work inside a virtual environment.
python -m pip install --upgrade pip
pip install torch torchaudio transformers soundfile
pip install sdab
GPU users should install the right torch/torchaudio binaries for their CUDA version as described on https://pytorch.org/get-started/locally/.
To install from source:
git clone https://github.com/MetythornPenn/sdab.git
cd sdab
pip install -e .
Quick Start
Download the bundled sample audio (Khmer speech, 16 kHz WAV):
wget -O audio.wav https://raw.githubusercontent.com/MetythornPenn/sdab/main/sample/audio.wav
Whisper (default)
from sdab import Sdab
sd = Sdab("audio.wav") # defaults to metythorn/whisper-large-v3
print(sd.transcribe())
Explicit Whisper model
from sdab import Sdab
sd = Sdab(
"audio.wav",
model_name="metythorn/whisper-large-v3",
device="cuda:0", # or "cpu"
)
print(sd.transcribe())
Need the faster turbo checkpoint? Provide it explicitly:
sd = Sdab("audio.wav", model_name="metythorn/whisper-large-v3-turbo")
print(sd.transcribe())
Wav2Vec2 / CTC model
from sdab import Sdab
sd = Sdab(
"audio.wav",
model_name="metythorn/wav2vec2-xls-r-300m",
model_type="wav2vec2", # optional; Sdab will infer from the model name
)
print(sd.transcribe())
Important parameters
file_path: Path to your WAV/FLAC/etc. file.model_name: Hugging Face repo ID or local directory with the pretrained model.model_type: Force"whisper"or"wav2vec2"if autodetect is not correct.device:"cpu"or any PyTorch device string (for example"cuda:0").torch_dtype: Override the dtype (defaults tofloat32on CPU andfloat16on CUDA).
Tips
- Whisper expects mono 16 kHz input; Sdab automatically downsamples and squeezes channels.
- Models are downloaded from Hugging Face the first time you reference them. Keep an eye on cache size in
~/.cache/huggingface. - For long recordings consider chunking/streaming outside of Sdab to stay within GPU memory.
- Results are returned from
sd.transcribe()directly; the class no longer stores a separatesd.result. - Errors while loading a model are wrapped in a helpful
RuntimeErrorwith the model name.
References
- Inspired by Bong Vitou Phy and the accompanying Techcast episode.
- Khmer word segmentation libraries from SeangHay: khmercut and khmersegment.
- Whisper: paper | Hugging Face models.
- Wav2Vec2 paper and resources from Facebook AI Research: fairseq examples.
Metadata
Release files for sdab 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sdab-1.0.1.tar.gz | 9.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sdab-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.3 kB
Release files / sdab-1.0.1.tar.gz
| Download URL | sdab-1.0.1.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
614d892f47bfa2c291456f05b350ecd2e21e03eb30e2395eeb7278d4b8ac3dbb
|
|
BLAKE2b-256 checksum How to use checksums |
afacfee69425b8f970cd0ba00d651450636b02f4153e440f35428e3c6da3b4ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / sdab-1.0.1-py3-none-any.whl
| Download URL | sdab-1.0.1-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
736cd1b44ff7410c75f8b42df038355183a217df31976dc7975b75e94a4ff96a
|
|
BLAKE2b-256 checksum How to use checksums |
ce4173ff0fa901defacd4eaac61a915614f6b1408a05edf08a03a2bf4e045d19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Security for sdab 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.