[UC]임종현 8 kuukautta sitten
vanhempi
sitoutus
b41b3e9e42
1 muutettua tiedostoa jossa 9 lisäystä ja 4 poistoa
  1. 9 4
      stt_whisper.py

+ 9 - 4
stt_whisper.py

@@ -8,7 +8,7 @@ from fastapi import FastAPI, WebSocket, WebSocketDisconnect
 app = FastAPI()
 
 # Whisper 모델 로드 (tiny 모델로 실시간성 유지)
-model = whisper.load_model("base")
+model = whisper.load_model("tiny")
 
 # 클라이언트 관리
 clients = {}
@@ -24,6 +24,7 @@ async def websocket_endpoint(websocket: WebSocket):
     try:
         while True:
             # 오디오 청크 수신
+            print("클라이언트 대기중......")
             audio_chunk = await websocket.receive_bytes()
 
             # 오디오 데이터를 새로운 버퍼에 저장 (기존 데이터 누적 방지)
@@ -41,12 +42,16 @@ async def websocket_endpoint(websocket: WebSocket):
             wavfile.write(output_file, 16000, audio_np)
 
             # STT 처리
+            print("STT 처리중.....")
             stt_result = model.transcribe(output_file, language="ko")
             transcription = stt_result["text"]
+            print("STT 처리완료!")
 
-            # 클라이언트에 데이터 전송
-            print("클라이언트에 데이터 전송")
-            await websocket.send_text(transcription)
+            # 빈 문자열이 아닌 경우만 전송
+            if transcription.strip():
+                print("클라이언트에 데이터 전송")
+                await websocket.send_text(transcription)
+            print("=================== END =======================")
     except WebSocketDisconnect:
         print(f"Client {client_id} disconnected")
         del clients[client_id]