Views
No views yet
1
2import os
3import librosa
4import torch
5import torchaudio
6import numpy as np
7
8from transformers import WhisperTokenizer
9from transformers import WhisperProcessor
10from transformers import WhisperFeatureExtractor
11from transformers import WhisperForConditionalGeneration
12
13device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
14
15mp3_path = "https://huggingface.co/bangla-speech-processing/BanglaASR/resolve/main/mp3/common_voice_bn_31515636.mp3"
16
17model_path = "bangla-speech-processing/BanglaASR"
18
19
20feature_extractor = WhisperFeatureExtractor.from_pretrained(model_path)
21tokenizer = WhisperTokenizer.from_pretrained(model_path)
22processor = WhisperProcessor.from_pretrained(model_path)
23model = WhisperForConditionalGeneration.from_pretrained(model_path).to(device)
24
25
26speech_array, sampling_rate = torchaudio.load(mp3_path, format="mp3")
27speech_array = speech_array[0].numpy()
28speech_array = librosa.resample(np.asarray(speech_array), orig_sr=sampling_rate, target_sr=16000)
29input_features = feature_extractor(speech_array, sampling_rate=16000, return_tensors="pt").input_features
30
31# batch = processor.feature_extractor.pad(input_features, return_tensors="pt")
32predicted_ids = model.generate(inputs=input_features.to(device))[0]
33
34
35transcription = processor.decode(predicted_ids, skip_special_tokens=True)
36
37print(transcription)
38| Size | Layers | Width | Heads | Parameters | Bangla-only | Training Status |
|---|---|---|---|---|---|---|
| tiny | 4 | 384 | 6 | 39 M | X | X |
| base | 6 | 512 | 8 | 74 M | X | X |
| small | 12 | 768 | 12 | 244 M | ✓ | ✓ |
| medium | 24 | 1024 | 16 | 769 M | X | X |
| large | 32 | 1280 | 20 | 1550 M | X | X |
@misc{BanglaASR ,
title={Transformer Based Whisper Bangla ASR Model},
author={Md Saiful Islam},
howpublished={},
year={2023}
}