File size: 1,034 Bytes
eb4c285 |
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 |
---
license: apache-2.0
datasets:
- ASCEND
language:
- zh
metrics:
- cer
tags:
- audio
- automatic-speech-recognition
- speech
- xlsr-fine-tuning-week
---
## inference
The model can be used directly (without a language model) as follows...
Using the [HuggingSound](https://github.com/jonatasgrosman/huggingsound) library:
```python
from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
from datasets import load_dataset
import torch
import torchaudio
# load model and processor
processor = Wav2Vec2Processor.from_pretrained("gymeee/demo_code_switching")
model = Wav2Vec2ForCTC.from_pretrained("gymeee/demo_code_switching")
# load speech
speech_array, sampling_rate = torchaudio.load("speech.wav")
# tokenize
input_values = processor(speech_array[0], return_tensors="pt", padding="longest").input_values # Batch size 1
# retrieve logits
logits = model(input_values).logits
# take argmax and decode
predicted_ids = torch.argmax(logits, dim=-1)
transcription = processor.batch_decode(predicted_ids)
print(transcription) |