|
# whisper-medium-AHao: Automatic Speech Recognition for Vietnamese |
|
``` |
|
title:whisper-medium-AHao: Automatic Speech Recognition for Vietnamese |
|
author: Bang Viet Hao |
|
year: 2024 |
|
license: apache-2.0 |
|
language: vi |
|
``` |
|
|
|
# Usage |
|
```python |
|
import torch |
|
import accelerate |
|
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline |
|
|
|
device = "cuda:0" if torch.cuda.is_available() else "cpu" |
|
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32 |
|
|
|
model_id = "bavihao/whisper-medium-AHao" |
|
|
|
model = AutoModelForSpeechSeq2Seq.from_pretrained( |
|
model_id, torch_dtype=torch_dtype, device_map = 'auto' |
|
) |
|
|
|
processor = AutoProcessor.from_pretrained(model_id) |
|
|
|
pipe = pipeline( |
|
"automatic-speech-recognition", |
|
model=model, |
|
tokenizer=processor.tokenizer, |
|
feature_extractor=processor.feature_extractor, |
|
batch_size=16, |
|
return_timestamps=True, |
|
torch_dtype=torch_dtype, |
|
) |
|
result = pipe(audio_path, generate_kwargs={"language": "vietnamese"}) |
|
print(result["text"]) |
|
``` |