From f9d2d28e2f536a4eed37b67f0860a5ffbd62f786 Mon Sep 17 00:00:00 2001 From: zzuhannn Date: Sun, 7 Sep 2025 01:44:09 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=ED=95=84=EC=9A=94=ED=95=9C=20?= =?UTF-8?q?=EB=9D=BC=EC=9D=B4=EB=B8=8C=EB=9F=AC=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/requirements.txt b/requirements.txt index 3d4b1eb..75bd0b8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,5 +8,8 @@ httpx # 설정 관리 pydantic-settings +# 폼 데이터(파일 업로드) 지원 +python-multipart + # 테스트용 앱 streamlit \ No newline at end of file From 030b5e5bf9839a30bb7e4a4ca527c2712541e167 Mon Sep 17 00:00:00 2001 From: zzuhannn Date: Sun, 7 Sep 2025 01:44:59 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=EC=9D=8C=EC=84=B1=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=EC=9D=84=20=ED=85=8D=EC=8A=A4=ED=8A=B8=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=ED=99=98=ED=95=98=EB=8A=94=20stt=20=ED=98=B8=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 3f79a27..a2c389d 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,9 @@ from typing import List, Optional # 타입 힌트: 리스트, Optional import httpx # 비동기 HTTP 클라이언트 (LLM API 호출용) +from fastapi import UploadFile, File # 파일 업로드 처리용 +from stt import transcribe_audio # STT 처리 함수 임포트 + from config import settings # 환경설정/비밀키를 담은 settings 객체 임포트 # FastAPI 앱 및 모델 정의 @@ -129,4 +132,15 @@ async def get_recommendations(request: RecommendationRequest): return RecommendationResponse( category=main_category, recommended_sentences=final_sentences - ) \ No newline at end of file + ) + +@app.post("/stt/transcribe", summary="음성 파일을 텍스트로 변환 (STT)") +async def stt_transcribe(file: UploadFile = File(...)): + """ + 업로드된 음성 파일을 OpenAI Whisper로 텍스트 변환합니다. + """ + try: + text = await transcribe_audio(file) + return {"transcription": text} + except Exception as e: + raise HTTPException(status_code=500, detail=f"STT 처리 중 오류: {e}") \ No newline at end of file From e91429cdedb57d5fd1bbf5cfa3b8efaf8ea0e496 Mon Sep 17 00:00:00 2001 From: zzuhannn Date: Sun, 7 Sep 2025 01:46:18 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20config=EC=97=90=20open=5Fapi=5Fkey?= =?UTF-8?q?=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 8edba04..f7e5d50 100644 --- a/config.py +++ b/config.py @@ -7,7 +7,7 @@ class Settings(BaseSettings): """ GOOGLE_API_KEY: str KAKAO_API_KEY: str - + OPENAI_API_KEY: str model_config = SettingsConfigDict(env_file=".env", extra='ignore') # 설정 객체를 생성합니다. From 6c906bee0d0235e31b9342f210b551cb18ebb47e Mon Sep 17 00:00:00 2001 From: zzuhannn Date: Sun, 7 Sep 2025 01:47:01 +0900 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20OpenAI=20Whisper=20=EA=B8=B0?= =?UTF-8?q?=EB=B0=98=20STT=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stt.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 stt.py diff --git a/stt.py b/stt.py new file mode 100644 index 0000000..38fe366 --- /dev/null +++ b/stt.py @@ -0,0 +1,19 @@ +import httpx +from fastapi import UploadFile +from config import settings + +async def transcribe_audio(file: UploadFile) -> str: + """ + OpenAI Whisper API를 사용하여 음성 파일을 텍스트로 변환합니다. + """ + api_url = "https://api.openai.com/v1/audio/transcriptions" + headers = {"Authorization": f"Bearer {settings.OPENAI_API_KEY}"} + files = { + "file": (file.filename, await file.read(), file.content_type), + } + data = {"model": "whisper-1"} + + async with httpx.AsyncClient() as client: + response = await client.post(api_url, headers=headers, files=files, data=data) + response.raise_for_status() + return response.json()["text"] \ No newline at end of file