Spaces:
Sleeping
Sleeping
| import os | |
| import time | |
| from fastapi import APIRouter, Depends, HTTPException, status | |
| from libs.convert_to_audio import convert_to_audio | |
| from libs.header_api_auth import get_api_key | |
| from libs.transformer.open_ai_whisper import open_ai_whisper_api | |
| from libs.transformer.get_transcript_gradio_api import api_gradio_transcribe | |
| router = APIRouter(prefix="/get-transcript-gradio", tags=["transcript"]) | |
| def get_transcript(audio_path: str, model_size: str = "distil-whisper/distil-small.en", api_key: str = Depends(get_api_key)): | |
| st = time.time() | |
| output_audio_folder = f"./cached/audio" | |
| # if not os.path.exists(output_audio_folder): | |
| # os.makedirs(output_audio_folder) | |
| # output_file = f"{output_audio_folder}/{audio_path.split('/')[-1].split(".")[0]}.mp3" | |
| # convert_to_audio(audio_path.strip(), output_file) | |
| try: | |
| # text, chunks = open_ai_whisper_api(audio_path) | |
| text = api_gradio_transcribe(audio_path) | |
| except Exception as error: | |
| raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=f"error>>>: {error}") | |
| # finally: | |
| # if os.path.exists(output_file): | |
| # os.remove(output_file) | |
| listSentences = [] | |
| # for chunk in chunks: | |
| # listSentences.append({ | |
| # "start_time": chunk.get("timestamp")[0], | |
| # "end_time": chunk.get("timestamp")[1], | |
| # "text": chunk.get("text") | |
| # }) | |
| et = time.time() | |
| elapsed_time = et - st | |
| return {"text": text, | |
| 'list_sentence': listSentences, | |
| 'elapsed_time': round(elapsed_time, 2) | |
| } | |