Views
No views yet
1import torch
2from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
3
4device = "cuda:0" if torch.cuda.is_available() else "cpu"
5torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
6
7model_id = "Svetozar1993/MultilingualSTT"
8
9model = AutoModelForSpeechSeq2Seq.from_pretrained(
10 model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
11)
12model.to(device)
13
14processor = AutoProcessor.from_pretrained(model_id)
15
16pipe = pipeline(
17 "automatic-speech-recognition",
18 model=model,
19 tokenizer=processor.tokenizer,
20 feature_extractor=processor.feature_extractor,
21 torch_dtype=torch_dtype,
22 device=device,
23)
24
25result = pipe("audio.mp3")
26print(result["text"])result = pipe(sample, generate_kwargs={"language": "french"})result = pipe(sample, generate_kwargs={"task": "translate"})1result = pipe(sample, return_timestamps=True)
2print(result["chunks"])result = pipe(sample, return_timestamps="word")pip install flash-attn --no-build-isolation1model = AutoModelForSpeechSeq2Seq.from_pretrained(
2 model_id,
3 torch_dtype=torch_dtype,
4 low_cpu_mem_usage=True,
5 attn_implementation="flash_attention_2"
6)