whisper-small-bn / test.py
Noobbbbb's picture
Add test script
f415910
raw
history blame contribute delete
801 Bytes
# Test script for Whisper Small Bengali
import torch
from transformers import WhisperForConditionalGeneration, WhisperTokenizer, WhisperProcessor
import librosa
# Load model
model = WhisperForConditionalGeneration.from_pretrained("Noobbbbb/whisper-small-bn")
tokenizer = WhisperTokenizer.from_pretrained("Noobbbbb/whisper-small-bn")
processor = WhisperProcessor.from_pretrained("openai/whisper-small")
# Load audio
audio, sr = librosa.load("test_audio.wav", sr=16000)
# Transcribe
input_features = processor.feature_extractor(audio, sampling_rate=16000, return_tensors="pt").input_features
with torch.no_grad():
generated_ids = model.generate(input_features, max_length=448)
transcription = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
print(f"Transcription: {transcription}")