from transformers import WhisperForConditionalGeneration, WhisperProcessor
import torch, soundfile as sf, torchaudio.functional as AF
proc = WhisperProcessor.from_pretrained("yehoshua01/waxal-sunbird51-lin-ft-r2")
model = WhisperForConditionalGeneration.from_pretrained("yehoshua01/waxal-sunbird51-lin-ft-r2").eval().cuda()
tok = proc.tokenizer
forced = [(1, tok.convert_tokens_to_ids("50353 # Sunbird card map: lin")),
(2, tok.convert_tokens_to_ids("<|transcribe|>")),
(3, tok.convert_tokens_to_ids("<|notimestamps|>"))]
wav, sr = sf.read("clip.wav", dtype="float32")
wav = AF.resample(torch.from_numpy(wav), sr, 16_000).numpy()[:30 * 16_000]
f = proc.feature_extractor(wav, sampling_rate=16_000, return_tensors="pt").input_features
out = model.generate(f.to("cuda", model.dtype), forced_decoder_ids=forced, max_new_tokens=220)
print(proc.batch_decode(out, skip_special_tokens=True)[0])