from transformers import WhisperProcessor, WhisperForConditionalGeneration
import librosa
import torch
model_name = "basharalrfooh/whisper-samll-quran"
processor = WhisperProcessor.from_pretrained(model_name)
model = WhisperForConditionalGeneration.from_pretrained(model_name)
model.config.forced_decoder_ids = None
audio_file = "Your .wav file"
speech_array, sampling_rate = librosa.load(audio_file, sr=16000)
inputs = processor(speech_array, return_tensors="pt", sampling_rate=sampling_rate)
with torch.no_grad():
predicted_ids = model.generate(inputs["input_features"])
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
print(f"Transcription: {transcription}")