Views
No views yet
s2t-small-covost2-ca-en-st is a Speech to Text Transformer (S2T) model trained for end-to-end Speech Translation (ST).
The S2T model was proposed in this paper and released in
this repositorygenerate method to generate the
transcripts by passing the speech features to the model.Speech2TextProcessor object uses torchaudio to extract the
filter bank features. Make sure to install the torchaudio package before running this example.pip install transformers"[speech, sentencepiece]" or install the packages seperatly
with pip install torchaudio sentencepiece.1import torch
2from transformers import Speech2TextProcessor, Speech2TextForConditionalGeneration
3from datasets import load_dataset
4import soundfile as sf
5
6model = Speech2TextForConditionalGeneration.from_pretrained("facebook/s2t-small-covost2-ca-en-st")
7processor = Speech2TextProcessor.from_pretrained("facebook/s2t-small-covost2-ca-en-st")
8
9def map_to_array(batch):
10 speech, _ = sf.read(batch["file"])
11 batch["speech"] = speech
12 return batch
13
14ds = load_dataset(
15 "patrickvonplaten/librispeech_asr_dummy",
16 "clean",
17 split="validation"
18)
19ds = ds.map(map_to_array)
20
21inputs = processor(
22 ds["speech"][0],
23 sampling_rate=48_000,
24 return_tensors="pt"
25)
26generated_ids = model.generate(input_ids=inputs["input_features"], attention_mask=inputs["attention_mask"])
27
28translation = processor.batch_decode(generated_ids, skip_special_tokens=True)1@inproceedings{wang2020fairseqs2t,
2 title = {fairseq S2T: Fast Speech-to-Text Modeling with fairseq},
3 author = {Changhan Wang and Yun Tang and Xutai Ma and Anne Wu and Dmytro Okhonko and Juan Pino},
4 booktitle = {Proceedings of the 2020 Conference of the Asian Chapter of the Association for Computational Linguistics (AACL): System Demonstrations},
5 year = {2020},
6}
7