Skip to content

Commit d7a87f0

Browse files
authored
merge: fast-api → develop
[김도은] whisper text 변환
2 parents 248d3b7 + 66cc8eb commit d7a87f0

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

api/routers/api.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class AudioRequest(BaseModel):
1010
file_path: str # JSON 본문에서 파일 경로를 받기 위한 모델
1111

1212
@router.post("/process")
13-
async def process_audio_to_text(request: AudioRequest) -> dict:
13+
async def process_audio_to_function(request: AudioRequest) -> dict:
1414
"""
1515
OpenAI Whisper를 사용하여 음성 파일을 텍스트로 변환한 후 GPT 처리로 전달하는 함수.
1616
:param file_path: 변환할 음성 파일의 경로
@@ -33,5 +33,29 @@ async def process_audio_to_text(request: AudioRequest) -> dict:
3333

3434
return gpt_response
3535

36+
except Exception as e:
37+
return {"status": "error", "message": str(e)}
38+
39+
@router.post("/text")
40+
async def process_audio_to_function(request: AudioRequest) -> dict:
41+
"""
42+
OpenAI Whisper를 사용하여 음성 파일을 텍스트로 변환 후 전달
43+
"""
44+
try:
45+
whisper_response = whisper_service.transcribe_audio(request.file_path) # Whisper를 사용한 변환 수행
46+
if whisper_response["status"] != "success":
47+
return whisper_response # 오류 발생 시 바로 반환
48+
49+
# print(f"🔍 [DEBUG] whisper_response: {whisper_response}") # 응답 값 확인
50+
# print(f"🔍 [DEBUG] whisper_response 타입: {type(whisper_response)}") # 타입 확인
51+
52+
result = whisper_response["text"]
53+
# print(f"🔍 [DEBUG] 변환된 텍스트: {result}")
54+
55+
if isinstance(result, str):
56+
result = {"result": result} # ✅ 문자열을 JSON으로 변환
57+
58+
return result # ✅ 이제 gpt_response는 딕셔너리이므로 오류 해결
59+
3660
except Exception as e:
3761
return {"status": "error", "message": str(e)}

0 commit comments

Comments
 (0)