Views
No views yet
1import torch
2import torchaudio
3from transformers import WhisperProcessor, WhisperForConditionalGeneration
4
5# Load the model and processor
6model_name = "DILHTWD/whisper-large-v3-turbo-hsb"
7processor_name = "openai/whisper-large-v3-turbo"
8processor = WhisperProcessor.from_pretrained(processor_name)
9model = WhisperForConditionalGeneration.from_pretrained(model_name)
10
11# Load and preprocess the audio
12audio, sample_rate = torchaudio.load("test.mp3")
13if sample_rate != 16000:
14 audio = torchaudio.transforms.Resample(orig_freq=sample_rate, new_freq=16000)(audio)
15input_features = processor(audio.squeeze().numpy(), sampling_rate=16000, return_tensors="pt").input_features
16
17# Generate transcription
18with torch.no_grad():
19 predicted_ids = model.generate(input_features)
20 transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
21
22# Print the transcription
23print("Transcription:", transcription)