File size: 571 Bytes
e000cc1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from faster_whisper import WhisperModel
import torch

device = "cuda" if torch.cuda.is_available() else "cpu"
torch_dtype = "float32"

MODEL_NAME = "Systran/faster-whisper-large-v3"
model = WhisperModel(MODEL_NAME, compute_type=torch_dtype)

def generate(audio_path):
    #check audio lenght
    segments, _ = model.transcribe(
        audio_path, 
        # language="ca",
        # chunk_length=30,
        task="transcribe",
        word_timestamps=False,
    )

    text = ""
    for segment in segments:
        text += " " + segment.text.strip()
    return text