Add test script
Browse files
test.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Test script for Whisper Small Bengali
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import WhisperForConditionalGeneration, WhisperTokenizer, WhisperProcessor
|
| 4 |
+
import librosa
|
| 5 |
+
|
| 6 |
+
# Load model
|
| 7 |
+
model = WhisperForConditionalGeneration.from_pretrained("Noobbbbb/whisper-small-8k")
|
| 8 |
+
tokenizer = WhisperTokenizer.from_pretrained("Noobbbbb/whisper-small-8k")
|
| 9 |
+
processor = WhisperProcessor.from_pretrained("openai/whisper-small")
|
| 10 |
+
|
| 11 |
+
# Load audio
|
| 12 |
+
audio, sr = librosa.load("test_audio.wav", sr=16000)
|
| 13 |
+
|
| 14 |
+
# Transcribe
|
| 15 |
+
input_features = processor.feature_extractor(audio, sampling_rate=16000, return_tensors="pt").input_features
|
| 16 |
+
with torch.no_grad():
|
| 17 |
+
generated_ids = model.generate(input_features, max_length=448)
|
| 18 |
+
transcription = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
|
| 19 |
+
|
| 20 |
+
print(f"Transcription: {transcription}")
|