Views
No views yet
1from transformers import WhisperForConditionalGeneration, WhisperProcessor
2import torch
3
4# Load model and processor
5model = WhisperForConditionalGeneration.from_pretrained("TheirStory-Inc/whisper-small-xhosa")
6processor = WhisperProcessor.from_pretrained("TheirStory-Inc/whisper-small-xhosa")
7
8# Prepare your audio file (16kHz sampling rate)
9audio_input = ... # Load your audio file here
10
11# Process the audio
12input_features = processor(audio_input, sampling_rate=16000, return_tensors="pt").input_features
13
14# Generate token ids
15predicted_ids = model.generate(input_features)
16
17# Decode the token ids to text
18transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
19
20print(transcription)De Vries, N.J., Davel, M.H., Badenhorst, J., Basson, W.D., de Wet, F., Barnard, E. and de Waal, A. (2014). A smartphone-based ASR data collection tool for under-resourced languages. Speech Communication, 56, 119-131. https://hdl.handle.net/20.500.12185/279