Views
No views yet
1from datasets import load_dataset
2from transformers import WhisperProcessor, WhisperForConditionalGeneration
3
4# Load the validation split of the Common Voice dataset for Portuguese
5common_voice = load_dataset("mozilla-foundation/common_voice_11_0", "pt", split="validation")
6
7# Load the pretrained model and processor
8processor = WhisperProcessor.from_pretrained("freds0/distil-whisper-large-v3-ptbr")
9model = WhisperForConditionalGeneration.from_pretrained("freds0/distil-whisper-large-v3-ptbr")
10
11# Select a sample from the dataset
12sample = common_voice[0] # You can change the index to select a different sample
13
14# Get the audio array and sampling rate
15audio_input = sample["audio"]["array"]
16sampling_rate = sample["audio"]["sampling_rate"]
17
18# Preprocess the audio
19input_features = processor(audio_input, sampling_rate=sampling_rate, return_tensors="pt").input_features
20
21# Generate transcription
22predicted_ids = model.generate(input_features)
23transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
24print("Transcription:", transcription[0])