Automatic Speech Recognition
Transformers
Safetensors
Welsh
English
wav2vec2
Inference Endpoints
File size: 2,181 Bytes
820d04f
 
 
 
 
f2bdd30
 
8aaa6d9
f2bdd30
 
 
 
820d04f
 
f48d0ef
820d04f
3d462e5
 
 
 
 
 
f2bdd30
3d462e5
 
 
f2bdd30
 
 
f48d0ef
f2bdd30
 
 
 
 
 
f48d0ef
f2bdd30
f48d0ef
 
f2bdd30
f48d0ef
f2bdd30
 
 
 
 
 
f48d0ef
 
 
 
 
f2bdd30
f48d0ef
 
 
 
f2bdd30
f48d0ef
 
 
 
f2bdd30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
license: apache-2.0
base_model: facebook/wav2vec2-large-xlsr-53
metrics:
- wer
datasets:
- techiaith/commonvoice_16_1_en_cy
- techiaith/banc-trawsgrifiadau-bangor
language:
- cy
- en
pipeline_tag: automatic-speech-recognition
---

# wav2vec2-xlsr-53-ft-cy-en-withlm

An acoustic encoder model for Welsh and English speech recognition accompanied with a n-gram language model. 
The acoustic model is fine-tuned from 
[facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) using transcribed
spontaneous speech from 
[techiaith/banc-trawsgrifiadau-bangor (v24.01)](https://huggingface.co/datasets/techiaith/banc-trawsgrifiadau-bangor/tree/24.01) and 
Welsh and English speech data derived from version 16.1 the Common Voice datasets [techiaith/commonvoice_16_1_en_cy](https://huggingface.co/datasets/techiaith/commonvoice_16_1_en_cy)

The accompanying language model is a single KenLM n-gram model trained with a balanced 
collection of Welsh and English texts from [OSCAR](https://huggingface.co/datasets/oscar), thus avoiding language specific models 
and language detection during CTC decoding. 

## Usage

The `wav2vec2-xlsr-53-ft-cy-en-withlm` model can be used directly as follows:

```python
import torch
import torchaudio
import librosa

from transformers import Wav2Vec2ForCTC, Wav2Vec2ProcessorWithLM

processor = Wav2Vec2ProcessorWithLM.from_pretrained("techiaith/wav2vec2-xlsr-53-ft-cy-en-withlm")
model = Wav2Vec2ForCTC.from_pretrained("techiaith/wav2vec2-xlsr-53-ft-cy-en-withlm")

audio, rate = librosa.load(<path/to/audio_file>, sr=16000)

inputs = processor(audio, sampling_rate=16_000, return_tensors="pt", padding=True)

with torch.no_grad():
  tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits

print("Prediction: ", processor.batch_decode(tlogits.numpy(), beam_width=10).text[0].strip())

```

Usage with a pipeline is even simpler...

```
from transformers import pipeline

transcriber = pipeline("automatic-speech-recognition", model="techiaith/wav2vec2-xlsr-53-ft-cy-en-withlm")

def transcribe(audio):
    return transcriber(audio)["text"]

transcribe(<path/or/url/to/any/audiofile>)
```