diff --git a/.dockerignore b/.dockerignore index 59e2f8386f8955874a170b9f43bd6d2574b9a1e1..d578562e979176d511865e31c0d5391b4ec4878e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ .git .venv -venv \ No newline at end of file +venv +/audio_files \ No newline at end of file diff --git a/.gitignore b/.gitignore index 35e58693279343c7e00e2efa392a6bf0e95b9973..537f535ab636ed4b5c0c21c18812f92efdd988c0 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,5 @@ pip-wheel-metadata poetry/core/* public + +/audio_files diff --git a/app/webservice.py b/app/webservice.py index d0c39b952868adae5d54993e1f6de1ec6c22f16d..c12a651dc7f14394c27c57a14a3d12facaf06b1e 100644 --- a/app/webservice.py +++ b/app/webservice.py @@ -1,5 +1,6 @@ import importlib.metadata import os +import io from os import path from typing import Annotated, Optional, Union from urllib.parse import quote @@ -54,8 +55,9 @@ async def index(): @app.post("/asr", tags=["Endpoints"]) + async def asr( - audio_file: UploadFile = File(...), # noqa: B008 + file_name: str = Query(..., description="path to Audio or video file to transcribe"), encode: bool = Query(default=True, description="Encode audio first through ffmpeg"), task: Union[str, None] = Query(default="transcribe", enum=["transcribe", "translate"]), language: Union[str, None] = Query(default=None, enum=LANGUAGE_CODES), @@ -89,9 +91,21 @@ async def asr( ), output: Union[str, None] = Query(default="txt", enum=["txt", "vtt", "srt", "tsv", "json"]), ): + + print("filename", file_name) + # Get the current working directory + current_directory = os.getcwd() + # construct file path + audio_path = os.path.join(f'{current_directory}/audio_files', file_name) + + # Print the current working directory + print("file path", audio_path) + # Run transcription in a background thread to keep the event loop responsive def _run_transcription(): - audio = load_audio(audio_file.file, encode) + + audio = load_audio(open(audio_path, 'rb'), encode) + return asr_model.transcribe( audio, task, @@ -110,7 +124,7 @@ async def asr( media_type="text/plain", headers={ "Asr-Engine": CONFIG.ASR_ENGINE, - "Content-Disposition": f'attachment; filename="{quote(audio_file.filename)}.{output}"', + "Content-Disposition": f'attachment; filename="{quote(file_name)}.{output}"', }, )