Spaces:
Sleeping
Sleeping
File size: 1,472 Bytes
341ac47 c67b30e 8ee91c9 341ac47 66b630d 341ac47 f68dcc5 8ee91c9 c67b30e 8ee91c9 f68dcc5 8ee91c9 341ac47 8ee91c9 f68dcc5 8ee91c9 341ac47 8ee91c9 f68dcc5 341ac47 8ee91c9 c67b30e 8ee91c9 341ac47 c67b30e 341ac47 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
#!/usr/bin/python
# -*- coding: utf-8 -*-
import gc
from time import time
import torch
import whisperx as wx
from .config import (
DEVICE,
COMPUTE_TYPE,
BATCH_SIZE,
)
# -->> Tunables <<---------------------
# -->> Definitions <<------------------
# -->> API <<--------------------------
def transcribe_audio(audio_file, audio_path, transcript_folder_path):
# Transcribe the audio
print("Starting transcription...")
print("Loading model...")
time_1 = time()
model = wx.load_model(
"large-v2", device=DEVICE, compute_type=COMPUTE_TYPE, language="en"
)
time_2 = time()
print("Loading audio...")
time_3 = time()
audio = wx.load_audio(audio_path)
time_4 = time()
print("Transcribing...")
time_5 = time()
result = model.transcribe(audio, batch_size=BATCH_SIZE)
time_6 = time()
print("Transcription complete!")
print("\nTime Report: ")
print("Loading model: ", round(time_2 - time_1, 2), " [s]")
print("Loading audio: ", round(time_4 - time_3, 2), " [s]")
print("Transcribing: ", round(time_6 - time_5, 2), " [s]")
print("Total: ", round(time_6 - time_1, 2), " [s]")
# Save the transcript to a file
text = "\n ".join([i["text"] for i in result["segments"]])
# Free memory
gc.collect()
torch.cuda.empty_cache()
del model
return text
# -->> Execute <<----------------------
# -->> Export <<-----------------------
|