Gujarati ASR Model
This repository contains a Gujarati ASR (Automatic Speech Recognition) model trained with CTC loss and a BiLSTM architecture, along with a character-level tokenizer (guj_char_tokenizer).
It allows transcription of Gujarati speech from WAV files into text.
Repo Structure
GujaratiASR/
βββ model.safetensors # Trained model weights in SafeTensors format
βββ config.json # Model configuration (input/output shapes)
βββ tokenizer_config.json # Tokenizer configuration
βββ utils.py # ASRModel + guj_char_tokenizer classes
βββ README.md
βββ guf_06536_00606444525.wav
Quick Start: Download & Predict
Important: Copy
utils.pyinto your workspace before running the script below.
# ----------------------------
# Step 1: Imports
# ----------------------------
import os
import torch
from huggingface_hub import hf_hub_download
from utils import ASRModel, guj_char_tokenizer
import torchaudio
from safetensors.torch import load_file
# ----------------------------
# Step 2: Download model files from Hugging Face
# ----------------------------
REPO_ID = "Dhruven19/GujaratiASR"
LOCAL_DIR = "GujaratiASR_download"
os.makedirs(LOCAL_DIR, exist_ok=True)
hf_hub_download(repo_id=REPO_ID, filename="model.safetensors", local_dir=LOCAL_DIR)
hf_hub_download(repo_id=REPO_ID, filename="config.json", local_dir=LOCAL_DIR)
hf_hub_download(repo_id=REPO_ID, filename="tokenizer_config.json", local_dir=LOCAL_DIR)
hf_hub_download(repo_id=REPO_ID, filename="guf_06536_00606444525.wav", local_dir=LOCAL_DIR)
# ----------------------------
# Step 3: Load model & tokenizer
# ----------------------------
FILENAME = "model.safetensors"
file_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
state_dict = load_file(file_path)
tokenizer = guj_char_tokenizer.from_pretrained(LOCAL_DIR)
model = ASRModel(input_shape=64, output_shape=256, tokenizer=tokenizer)
model.load_state_dict(state_dict)
# ----------------------------
# Step 4: Prepare mel spectrogram transform
# ----------------------------
mel_spectogram = torchaudio.transforms.MelSpectrogram(
sample_rate=16000,
n_fft=512,
hop_length=512,
n_mels=64
)
# ----------------------------
# Step 5: Run prediction
# ----------------------------
transcript = model.predict(
audio_path=f"{LOCAL_DIR}/guf_06536_00606444525.wav",
tokenizer=tokenizer,
device="cpu",
mel_spectrogram_fn=mel_spectogram # pass your mel_spectrogram transform
)
print("Predicted Transcript:", transcript)
Notes
Ensure
utils.pyis present in your workspace β it contains the ASRModel and guj_char_tokenizer classes.The model expects 16 kHz audio.
Mel-spectrogram configuration:
n_fft = 512hop_length = 512n_mels = 64
Use
.predict()to directly get the transcript from a WAV file.
- Downloads last month
- 14