Views
No views yet
s2t-wav2vec2-large-en-ca is a Speech to Text Transformer model trained for end-to-end Speech Translation (ST).
The S2T2 model was proposed in Large-Scale Self- and Semi-Supervised Learning for Speech Translation and officially released in
Fairseq.generate method to generate the
transcripts by passing the speech features to the model.1from datasets import load_dataset
2from transformers import pipeline
3
4librispeech_en = load_dataset("patrickvonplaten/librispeech_asr_dummy", "clean", split="validation")
5asr = pipeline("automatic-speech-recognition", model="facebook/s2t-wav2vec2-large-en-ca", feature_extractor="facebook/s2t-wav2vec2-large-en-ca")
6
7translation = asr(librispeech_en[0]["file"])1import torch
2from transformers import Speech2Text2Processor, SpeechEncoderDecoder
3from datasets import load_dataset
4
5import soundfile as sf
6model = SpeechEncoderDecoder.from_pretrained("facebook/s2t-wav2vec2-large-en-ca")
7processor = Speech2Text2Processor.from_pretrained("facebook/s2t-wav2vec2-large-en-ca")
8
9def map_to_array(batch):
10 speech, _ = sf.read(batch["file"])
11 batch["speech"] = speech
12 return batch
13
14ds = load_dataset("patrickvonplaten/librispeech_asr_dummy", "clean", split="validation")
15ds = ds.map(map_to_array)
16
17inputs = processor(ds["speech"][0], sampling_rate=16_000, return_tensors="pt")
18generated_ids = model.generate(input_ids=inputs["input_features"], attention_mask=inputs["attention_mask"])
19transcription = processor.batch_decode(generated_ids)1@article{DBLP:journals/corr/abs-2104-06678,
2 author = {Changhan Wang and
3 Anne Wu and
4 Juan Miguel Pino and
5 Alexei Baevski and
6 Michael Auli and
7 Alexis Conneau},
8 title = {Large-Scale Self- and Semi-Supervised Learning for Speech Translation},
9 journal = {CoRR},
10 volume = {abs/2104.06678},
11 year = {2021},
12 url = {https://arxiv.org/abs/2104.06678},
13 archivePrefix = {arXiv},
14 eprint = {2104.06678},
15 timestamp = {Thu, 12 Aug 2021 15:37:06 +0200},
16 biburl = {https://dblp.org/rec/journals/corr/abs-2104-06678.bib},
17 bibsource = {dblp computer science bibliography, https://dblp.org}
18}
19