Inference Example
from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
import torch
import librosa
import os
model_name = "guymandude/MMS-ASR-ZA-11"
def load_audio_file(path):
audio_array, sampling_rate = librosa.load(path, sr=None)
return {"array": audio_array, "sampling_rate": sampling_rate}
model = Wav2Vec2ForCTC.from_pretrained(model_name,ignore_mismatched_sizes=True).to("cuda")
processor = Wav2Vec2Processor.from_pretrained(model_name)
# change to supported languages [eng, afr, sot, zul, xho, nso, nbl, tso, tsn, ven, ssw]
model.load_adapter("tsn")
processor.tokenizer.set_target_lang("tsn")
audio = load_audio_file("<AUDIO PATH>")
input_dict = processor(audio["array"], sampling_rate=16_000, return_tensors="pt", padding=True)
logits = model(input_dict.input_values.to("cuda")).logits
pred_ids = torch.argmax(logits, dim=-1)[0]
print(processor.decode(pred_ids))
- Downloads last month
- 134
Unable to determine this model's library. Check the
docs
.
Model tree for guymandude/MMS-ASR-South-African-11
Base model
facebook/mms-1b-all