Views
No views yet
| Item | Value |
|---|---|
| Task | Automatic speech recognition (ASR / STT) |
| Language | Balochi (Latin orthography) |
| Base model | Whisper-small |
| Sample rate | 16 kHz, mono |
| Best eval WER | ~4.5% |
| Training data | 5,237 clips (~3 hours) from wavs/wavs + wavs/wavs.txt |
1balochi_whisper/
2├── README.md
3├── best_model/
4│ ├── model/ # Whisper weights + config
5│ ├── processor/ # tokenizer + feature extractor
6│ └── eval_metrics.txt
7└── checkpoints/ # training checkpoints (optional)best_model/ for inference.source ~/venvs/torch/bin/activatetorch, transformers, soundfile, torchaudio, numpy.1from pathlib import Path
2import numpy as np
3import soundfile as sf
4import torch
5import torchaudio
6from transformers import WhisperForConditionalGeneration, WhisperProcessor
7
8ROOT = Path("balochi_whisper/best_model")
9device = "cuda" if torch.cuda.is_available() else "cpu"
10
11processor = WhisperProcessor.from_pretrained(ROOT / "processor")
12model = WhisperForConditionalGeneration.from_pretrained(ROOT / "model").to(device)
13model.eval()
14model.config.forced_decoder_ids = None
15model.generation_config.forced_decoder_ids = None
16model.generation_config.pad_token_id = processor.tokenizer.pad_token_id
17
18def load_16k(path: str) -> np.ndarray:
19 wav, sr = sf.read(path, always_2d=False)
20 if wav.ndim > 1:
21 wav = wav.mean(axis=1)
22 wav = np.asarray(wav, dtype=np.float32)
23 if sr != 16000:
24 wav = (
25 torchaudio.functional.resample(
26 torch.from_numpy(wav).unsqueeze(0), sr, 16000
27 )
28 .squeeze(0)
29 .numpy()
30 )
31 return wav
32
33wav = load_16k("your_audio.wav")
34inputs = processor(
35 wav, sampling_rate=16000, return_tensors="pt", return_attention_mask=True
36)
37with torch.no_grad():
38 ids = model.generate(
39 inputs.input_features.to(device),
40 attention_mask=inputs.attention_mask.to(device),
41 max_new_tokens=224,
42 )
43text = processor.batch_decode(ids.cpu(), skip_special_tokens=True)[0].strip()
44print(text)1cd ~/Balochi_tts
2source ~/venvs/torch/bin/activate
3python infer_stt.py /path/to/audio.wavpython stt_gui.py1wavs/wavs/1.wav … N.wav
2wavs/wavs.txt # line i → transcript for (i+1).wavá, é, ó allowed).python train_stt.pybalochi_whisper/checkpoints/. The best model (lowest WER) is copied to balochi_whisper/best_model/.1# from Balochi_tts project root
2bash scripts/push_models_to_hf.sh YOUR_HF_USERYOUR_HF_USER/balochi-whisper-stt with model/ and processor/.1from transformers import WhisperForConditionalGeneration, WhisperProcessor
2
3repo = "YOUR_HF_USER/balochi-whisper-stt"
4processor = WhisperProcessor.from_pretrained(repo, subfolder="processor")
5model = WhisperForConditionalGeneration.from_pretrained(repo, subfolder="model")subfolder=....1best_model/model/config.json
2best_model/model/generation_config.json
3best_model/model/model.safetensors
4best_model/processor/ # full processor directorycheckpoints/ is only needed to resume training.