Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- sv
|
4 |
+
pipeline_tag: automatic-speech-recognition
|
5 |
+
license: apache-2.0
|
6 |
+
datasets:
|
7 |
+
- KBLab/rixvox-v2
|
8 |
+
---
|
9 |
+
## KB-Whisper Tiny
|
10 |
+
|
11 |
+
The National Library of Sweden's new Whisper models trained on over 50,000 hours of Swedish speech.
|
12 |
+
|
13 |
+
### Usage
|
14 |
+
|
15 |
+
```python
|
16 |
+
import torch
|
17 |
+
from datasets import load_dataset
|
18 |
+
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
19 |
+
|
20 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
21 |
+
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
22 |
+
model_id = "KBLab/kb-whisper-tiny-beta"
|
23 |
+
|
24 |
+
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
25 |
+
model_id, torch_dtype=torch_dtype, use_safetensors=True, cache_dir="cache"
|
26 |
+
)
|
27 |
+
model.to(device)
|
28 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
29 |
+
|
30 |
+
pipe = pipeline(
|
31 |
+
"automatic-speech-recognition",
|
32 |
+
model=model,
|
33 |
+
tokenizer=processor.tokenizer,
|
34 |
+
feature_extractor=processor.feature_extractor,
|
35 |
+
torch_dtype=torch_dtype,
|
36 |
+
device=device,
|
37 |
+
)
|
38 |
+
|
39 |
+
generate_kwargs = {"task": "transcribe", "language": "sv"}
|
40 |
+
# Add return_timestamps=True for output with timestamps
|
41 |
+
res = pipe("audio.mp3",
|
42 |
+
chunk_length_s=30,
|
43 |
+
generate_kwargs={"task": "transcribe", "language": "sv"})
|
44 |
+
```
|