Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,49 @@
|
|
1 |
---
|
2 |
license: apache-2.0
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
+
language:
|
4 |
+
- th
|
5 |
+
pipeline_tag: automatic-speech-recognition
|
6 |
---
|
7 |
+
|
8 |
+
# Whisper-base Thai finetuned
|
9 |
+
|
10 |
+
## 1) Environment Setup
|
11 |
+
```bash
|
12 |
+
# visit https://pytorch.org/get-started/locally/ to install pytorch
|
13 |
+
pip3 install transformers librosa
|
14 |
+
```
|
15 |
+
|
16 |
+
## 2) Usage
|
17 |
+
```python
|
18 |
+
from transformers import WhisperForConditionalGeneration, WhisperProcessor
|
19 |
+
import librosa
|
20 |
+
|
21 |
+
device = "cuda" # cpu, cuda
|
22 |
+
|
23 |
+
model = WhisperForConditionalGeneration.from_pretrained("juierror/whisper-base-thai").to(device)
|
24 |
+
processor = WhisperProcessor.from_pretrained("juierror/whisper-base-thai", language="Thai", task="transcribe")
|
25 |
+
|
26 |
+
path = "/path/to/audio/file"
|
27 |
+
|
28 |
+
def inference(path: str) -> str:
|
29 |
+
"""
|
30 |
+
Get the transcription from audio path
|
31 |
+
|
32 |
+
Args:
|
33 |
+
path(str): path to audio file (can be load with librosa)
|
34 |
+
|
35 |
+
Returns:
|
36 |
+
str: transcription
|
37 |
+
"""
|
38 |
+
audio, sr = librosa.load(path, sr=16000)
|
39 |
+
input_features = processor(audio, sampling_rate=16000, return_tensors="pt").input_features
|
40 |
+
generated_tokens = model.generate(
|
41 |
+
input_features=input_features.to(device),
|
42 |
+
max_new_tokens=255,
|
43 |
+
language="Thai"
|
44 |
+
).cpu()
|
45 |
+
transcriptions = processor.tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
|
46 |
+
return transcriptions[0]
|
47 |
+
|
48 |
+
print(inference(path=path))
|
49 |
+
```
|