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.py into 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

  1. Ensure utils.py is present in your workspace β€” it contains the ASRModel and guj_char_tokenizer classes.

  2. The model expects 16 kHz audio.

  3. Mel-spectrogram configuration:

    • n_fft = 512
    • hop_length = 512
    • n_mels = 64
  4. Use .predict() to directly get the transcript from a WAV file.

Downloads last month
14
Safetensors
Model size
0.2B params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support