Views
No views yet
1# visit https://pytorch.org/get-started/locally/ to install pytorch
2pip3 install transformers librosa1from transformers import WhisperForConditionalGeneration, WhisperProcessor
2import librosa
3
4device = "cuda" # cpu, cuda
5
6model = WhisperForConditionalGeneration.from_pretrained("juierror/whisper-base-thai").to(device)
7processor = WhisperProcessor.from_pretrained("juierror/whisper-base-thai", language="Thai", task="transcribe")
8
9path = "/path/to/audio/file"
10
11def inference(path: str) -> str:
12 """
13 Get the transcription from audio path
14
15 Args:
16 path(str): path to audio file (can be load with librosa)
17
18 Returns:
19 str: transcription
20 """
21 audio, sr = librosa.load(path, sr=16000)
22 input_features = processor(audio, sampling_rate=16000, return_tensors="pt").input_features
23 generated_tokens = model.generate(
24 input_features=input_features.to(device),
25 max_new_tokens=255,
26 language="Thai"
27 ).cpu()
28 transcriptions = processor.tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
29 return transcriptions[0]
30
31print(inference(path=path))@techreport{gowajee,
title = {{Gowajee Corpus}},
author = {Ekapol Chuangsuwanich and Atiwong Suchato and Korrawe Karunratanakul and Burin Naowarat and Chompakorn CChaichot
and Penpicha Sangsa-nga and Thunyathon Anutarases and Nitchakran Chaipojjana},
year = {2020},
institution = {Chulalongkorn University, Faculty of Engineering, Computer Engineering Department},
month = {12},
Date-Added = {2021-07-20},
url = {https://github.com/ekapolc/gowajee_corpus}
note = {Version 0.9.2}
}| Dataset | WER | CER |
|---|---|---|
| Common Voice 13 | 15.89 | 4.32 |
| Gowajee | 19.58 | 9.01 |
| Thai Elderly Speech (Smart Home) | 7.13 | 2.21 |
| Thai Elderly Speech (Health Care) | 6.75 | 1.89 |