Views
No views yet
bond005/wav2vec2-large-ru-golos-with-lmtorch 2.8.0torchaudio 2.8.0transformers 4.49.0kenlm and pyctcdecode:1pip install kenlm
2pip install pyctcdecode1from transformers import AutoModel, AutoProcessor
2import torch
3import torchaudio
4
5# load audio
6wav, sr = torchaudio.load("audio.wav")
7# resample if necessary
8wav = torchaudio.functional.resample(wav, sr, 16000)
9
10# load model and processor
11processor = AutoProcessor.from_pretrained("waveletdeboshir/gigaam-v3-ctc-with-lm", trust_remote_code=True)
12model = AutoModel.from_pretrained("waveletdeboshir/gigaam-v3-ctc-with-lm", trust_remote_code=True)
13model.eval()
14
15input_features = processor(wav[0], sampling_rate=16000, return_tensors="pt")
16
17# predict
18with torch.no_grad():
19 logits = model(**input_features).logits
20
21# decoding with beamseach and LM (tune alpha, beta, beam_width for your data)
22transcription = processor.batch_decode(
23 logits=logits.numpy(),
24 beam_width=64,
25 alpha=0.5,
26 beta=0.5,
27).text[0]
28output_word_offsets=True.MODEL_STRIDE = 40 ms per timestamp.1MODEL_STRIDE = 40
2outputs = processor.batch_decode(
3 logits=logits.numpy(),
4 beam_width=64,
5 alpha=0.5,
6 beta=0.5,
7 output_word_offsets=True
8)
9word_ts = [
10 {
11 "word": d["word"],
12 "start": round(d["start_offset"] * MODEL_STRIDE / 1000, 2),
13 "end": round(d["end_offset"] * MODEL_STRIDE / 1000, 2),
14 }
15 for d in outputs.word_offsets[0]
16]