Views
No views yet
| VIVOS | COMMON VOICE 7.0 | COMMON VOICE 8.0 | |
|---|---|---|---|
| without LM | 8.23 | 12.15 | 12.15 |
| with 4-grams LM | 3.70 | 5.57 | 5.76 |
1from speechbrain.pretrained import EncoderASR
2
3model = EncoderASR.from_hparams(source="dragonSwing/wav2vec2-base-vn-270h", savedir="pretrained_models/asr-wav2vec2-vi")
4model.transcribe_file('dragonSwing/wav2vec2-base-vn-270h/example.mp3')
5# Output: được hồ chí minh coi là một động lực lớn của sự phát triển đất nướcrun_opts={"device":"cuda"} when calling the from_hparams method.1import torch
2import torchaudio
3from datasets import load_dataset, load_metric, Audio
4from transformers import Wav2Vec2FeatureExtractor
5from speechbrain.pretrained import EncoderASR
6import re
7test_dataset = load_dataset("mozilla-foundation/common_voice_8_0", "vi", split="test", use_auth_token=True)
8test_dataset = test_dataset.cast_column("audio", Audio(sampling_rate=16_000))
9device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
10wer = load_metric("wer")
11extractor = Wav2Vec2FeatureExtractor.from_pretrained("dragonSwing/wav2vec2-base-vn-270h")
12model = EncoderASR.from_hparams(source="dragonSwing/wav2vec2-base-vn-270h", savedir="pretrained_models/asr-wav2vec2-vi", run_opts={'device': device})
13chars_to_ignore_regex = r'[,?.!\-;:"“%\'�]'
14# Preprocessing the datasets.
15# We need to read the audio files as arrays
16def speech_file_to_array_fn(batch):
17 audio = batch["audio"]
18 batch["target_text"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
19 batch['speech'] = audio['array']
20 return batch
21test_dataset = test_dataset.map(speech_file_to_array_fn)
22
23def evaluate(batch):
24 # For padding inputs only
25 inputs = extractor(
26 batch['speech'],
27 sampling_rate=16000,
28 return_tensors="pt",
29 padding=True,
30 do_normalize=False
31 ).input_values
32 input_lens = torch.ones(inputs.shape[0])
33 pred_str, pred_tokens = model.transcribe_batch(inputs, input_lens)
34 batch["pred_strings"] = pred_str
35
36 return batch
37result = test_dataset.map(evaluate, batched=True, batch_size=1)
38print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["target_text"])))@misc{SB2021,
author = {Ravanelli, Mirco and Parcollet, Titouan and Rouhe, Aku and Plantinga, Peter and Rastorgueva, Elena and Lugosch, Loren and Dawalatabad, Nauman and Ju-Chieh, Chou and Heba, Abdel and Grondin, Francois and Aris, William and Liao, Chien-Feng and Cornell, Samuele and Yeh, Sung-Lin and Na, Hwidong and Gao, Yan and Fu, Szu-Wei and Subakan, Cem and De Mori, Renato and Bengio, Yoshua },
title = {SpeechBrain},
year = {2021},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\\\\url{https://github.com/speechbrain/speechbrain}},
}