Views
No views yet
1import torch
2from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
3device = "cuda:0" if torch.cuda.is_available() else "cpu"
4torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
5model_id = "formospeech/whisper-large-v2-formosan-all"
6model = AutoModelForSpeechSeq2Seq.from_pretrained(
7 model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
8)
9model.to(device)
10processor = AutoProcessor.from_pretrained(model_id)
11pipe = pipeline(
12 "automatic-speech-recognition",
13 model=model,
14 tokenizer=processor.tokenizer,
15 feature_extractor=processor.feature_extractor,
16 max_new_tokens=128,
17 chunk_length_s=30,
18 batch_size=16,
19 torch_dtype=torch_dtype,
20 device=device,
21)
22generate_kwargs = {"language": "id"}
23transcription = pipe("path/to/my_audio.wav", generate_kwargs=generate_kwargs)
24print(transcription)