模型:
alokmatta/wav2vec2-large-xlsr-53-sw
在以下数据集上进行了Swahili的微调:
使用该模型时,请确保语音输入采样率为16kHz。
可以直接使用该模型(无需语言模型)如下:
import torch import torchaudio from datasets import load_dataset from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor processor = Wav2Vec2Processor.from_pretrained("alokmatta/wav2vec2-large-xlsr-53-sw") model = Wav2Vec2ForCTC.from_pretrained("alokmatta/wav2vec2-large-xlsr-53-sw").to("cuda") resampler = torchaudio.transforms.Resample(48_000, 16_000) resampler = torchaudio.transforms.Resample(orig_freq=48_000, new_freq=16_000) def load_file_to_data(file): batch = {} speech, _ = torchaudio.load(file) batch["speech"] = resampler.forward(speech.squeeze(0)).numpy() batch["sampling_rate"] = resampler.new_freq return batch def predict(data): features = processor(data["speech"], sampling_rate=data["sampling_rate"], padding=True, return_tensors="pt") input_values = features.input_values.to("cuda") attention_mask = features.attention_mask.to("cuda") with torch.no_grad(): logits = model(input_values, attention_mask=attention_mask).logits pred_ids = torch.argmax(logits, dim=-1) return processor.batch_decode(pred_ids) predict(load_file_to_data('./demo.wav'))
测试结果:40%
训练所使用的脚本可以在此处找到 here