Views
No views yet
sox record.wav -r 16k record-normalized.wav norm -0.5 compand 0.3,1 -90,-90,-70,-70,-60,-20,0,0 -5 0 0.21import torch
2from transformers import WhisperForConditionalGeneration, WhisperProcessor, pipeline
3
4torch_dtype = torch.bfloat16 # set your preferred type here
5
6device = 'cpu'
7if torch.cuda.is_available():
8 device = 'cuda'
9elif torch.backends.mps.is_available():
10 device = 'mps'
11 setattr(torch.distributed, "is_initialized", lambda : False) # monkey patching
12device = torch.device(device)
13
14whisper = WhisperForConditionalGeneration.from_pretrained(
15 "antony66/whisper-large-v3-russian", torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True,
16 # add attn_implementation="flash_attention_2" if your GPU supports it
17)
18
19processor = WhisperProcessor.from_pretrained("antony66/whisper-large-v3-russian")
20
21asr_pipeline = pipeline(
22 "automatic-speech-recognition",
23 model=whisper,
24 tokenizer=processor.tokenizer,
25 feature_extractor=processor.feature_extractor,
26 max_new_tokens=256,
27 chunk_length_s=30,
28 batch_size=16,
29 return_timestamps=True,
30 torch_dtype=torch_dtype,
31 device=device,
32)
33
34# read your wav file into variable wav. For example:
35from io import BufferIO
36wav = BytesIO()
37with open('record-normalized.wav', 'rb') as f:
38 wav.write(f.read())
39wav.seek(0)
40
41# get the transcription
42asr = asr_pipeline(wav, generate_kwargs={"language": "russian", "max_new_tokens": 256}, return_timestamps=False)
43
44print(asr['text'])
45