Views
No views yet
title:whisper-medium-AHao: Automatic Speech Recognition for Vietnamese
author: Bang Viet Hao
year: 2024
license: apache-2.0
language: vi1import torch
2import accelerate
3from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
4
5device = "cuda:0" if torch.cuda.is_available() else "cpu"
6torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
7
8model_id = "bavihao/whisper-medium-AHao"
9
10model = AutoModelForSpeechSeq2Seq.from_pretrained(
11 model_id, torch_dtype=torch_dtype, device_map = 'auto'
12)
13
14processor = AutoProcessor.from_pretrained(model_id)
15
16pipe = pipeline(
17 "automatic-speech-recognition",
18 model=model,
19 tokenizer=processor.tokenizer,
20 feature_extractor=processor.feature_extractor,
21 batch_size=16,
22 return_timestamps=True,
23 torch_dtype=torch_dtype,
24)
25result = pipe(audio_path, generate_kwargs={"language": "vietnamese"})
26print(result["text"])