This model is a fine-tuned version of
facebook/wav2vec2-xls-r-300m on the MOZILLA-FOUNDATION/COMMON_VOICE_8_0 - AR dataset.
It achieves the following results on the evaluation set:
1from transformers import (Wav2Vec2Processor, Wav2Vec2ForCTC)
2import torchaudio
3import torch
4
5def speech_file_to_array_fn(voice_path, resampling_to=16000):
6 speech_array, sampling_rate = torchaudio.load(voice_path)
7 resampler = torchaudio.transforms.Resample(sampling_rate, resampling_to)
8
9 return resampler(speech_array)[0].numpy(), sampling_rate
10
11# load the model
12cp = "bakrianoo/sinai-voice-ar-stt"
13processor = Wav2Vec2Processor.from_pretrained(cp)
14model = Wav2Vec2ForCTC.from_pretrained(cp)
15
16# recognize the text in a sample sound file
17sound_path = './my_voice.mp3'
18
19sample, sr = speech_file_to_array_fn(sound_path)
20inputs = processor([sample], sampling_rate=16_000, return_tensors="pt", padding=True)
21
22with torch.no_grad():
23 logits = model(inputs.input_values,).logits
24
25predicted_ids = torch.argmax(logits, dim=-1)
26
27print("Prediction:", processor.batch_decode(predicted_ids))