Spaces:
Sleeping
Sleeping
import time | |
from fastapi import APIRouter, Depends, HTTPException, status | |
from faster_whisper import WhisperModel | |
from libs.header_api_auth import get_api_key | |
router = APIRouter(prefix="/get-transcript", tags=["transcript"]) | |
# model_size: distil-large-v2 | |
# model_size: distil-large-v3 | |
def get_transcript(audio_path: str, model_size: str = "distil-large-v3", api_key: str = Depends(get_api_key)): | |
# Run on GPU with FP16 | |
# model = WhisperModel(model_size, device="cuda", compute_type="float16") | |
# or run on GPU with INT8 | |
# model = WhisperModel(model_size, device="cuda", cosmpute_type="int8_float16") | |
# or run on CPU with INT8 | |
# model_run = WhisperModel(model_size, device="cpu", compute_type="int8") | |
print(f"model>>>: {model_size}") | |
st = time.time() | |
try: | |
model_run = WhisperModel(model_size, device="cpu", compute_type="int8") | |
segments, info = model_run.transcribe( | |
audio_path, | |
beam_size=16, | |
language="en", | |
condition_on_previous_text=False, | |
) | |
except Exception as error: | |
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=f"error>>>: {error}") | |
text = "" | |
for segment in segments: | |
text += segment.text | |
et = time.time() | |
elapsed_time = et - st | |
return {"text": text} | |