ai4bharat/Kathbath
Viewer โข Updated โข 806k โข 8.24k โข 42
How to use vanshnawander/whisper-small-hindi-asr with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("automatic-speech-recognition", model="vanshnawander/whisper-small-hindi-asr") # pip install -U transformers accelerate
# Load model directly
from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq
processor = AutoProcessor.from_pretrained("vanshnawander/whisper-small-hindi-asr")
model = AutoModelForSpeechSeq2Seq.from_pretrained("vanshnawander/whisper-small-hindi-asr", device_map="auto")This is a fine-tuned version of openai/whisper-small for Hindi automatic speech recognition (ASR).
Evaluated on the LAHAJA benchmark - a multi-accent Hindi ASR benchmark with 12.5 hours of audio from 132 speakers across 83 districts of India.
| Model | WER | CER | Improvement |
|---|---|---|---|
| Base (whisper-small) | 145.67% | 101.57% | - |
| This Model | 36.17% | 11.36% | 75.2% |
from transformers import WhisperProcessor, WhisperForConditionalGeneration
import librosa
# Load model and processor
processor = WhisperProcessor.from_pretrained("vanshnawander/whisper-small-hindi-asr")
model = WhisperForConditionalGeneration.from_pretrained("vanshnawander/whisper-small-hindi-asr")
# Load audio
audio, sr = librosa.load("audio.wav", sr=16000)
# Transcribe
input_features = processor(audio, sampling_rate=16000, return_tensors="pt").input_features
generated_ids = model.generate(input_features, language="hi", task="transcribe")
transcription = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(transcription)
from transformers import pipeline
pipe = pipeline(
"automatic-speech-recognition",
model="vanshnawander/whisper-small-hindi-asr",
chunk_length_s=30,
)
result = pipe("audio.wav", generate_kwargs={"language": "hi", "task": "transcribe"})
print(result["text"])