Views
No views yet
1
2from transformers import AutoTokenizer, Wav2Vec2ForCTC
3
4tokenizer = AutoTokenizer.from_pretrained("Edresson/wav2vec2-large-100k-voxpopuli-ft-Common_Voice_plus_TTS-Dataset_plus_Data_Augmentation-russian")
5
6model = Wav2Vec2ForCTC.from_pretrained("Edresson/wav2vec2-large-100k-voxpopuli-ft-Common_Voice_plus_TTS-Dataset_plus_Data_Augmentation-russian")1dataset = load_dataset("common_voice", "ru", split="test", data_dir="./cv-corpus-7.0-2021-07-21")
2
3resampler = torchaudio.transforms.Resample(orig_freq=48_000, new_freq=16_000)
4
5def map_to_array(batch):
6 speech, _ = torchaudio.load(batch["path"])
7 batch["speech"] = resampler.forward(speech.squeeze(0)).numpy()
8 batch["sampling_rate"] = resampler.new_freq
9 batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower().replace("’", "'")
10 return batch1ds = dataset.map(map_to_array)
2result = ds.map(map_to_pred, batched=True, batch_size=1, remove_columns=list(ds.features.keys()))
3print(wer.compute(predictions=result["predicted"], references=result["target"]))