#!/usr/bin/env python3 """Transcribe one Urdu call-audio file with PakUrdu-Conversational-ASR-r12. Usage: python inference_example.py call.wav [more.wav ...] Loads the public base model from the HF hub, applies this LoRA adapter, merges, and decodes with the certified settings (language=ur, greedy). """ import sys import soundfile as sf import torch from peft import PeftModel from transformers import WhisperForConditionalGeneration, WhisperProcessor BASE = "openai/whisper-large-v3-turbo" ADAPTER = "KhiredNetworks/PakUrdu-Conversational-ASR" if len(sys.argv) < 2: sys.exit(__doc__) processor = WhisperProcessor.from_pretrained(BASE) model = WhisperForConditionalGeneration.from_pretrained(BASE) model = PeftModel.from_pretrained(model, ADAPTER).merge_and_unload() for path in sys.argv[1:]: speech, sr = sf.read(path, dtype="float32") if speech.ndim > 1: speech = speech.mean(axis=1) inputs = processor(speech, sampling_rate=sr, return_tensors="pt") with torch.no_grad(): ids = model.generate(inputs.input_features, language="ur", task="transcribe", do_sample=False) text = processor.batch_decode(ids, skip_special_tokens=True)[0].strip() print(f"{path}: {text}")