Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -73,10 +73,17 @@ class OpenAIHandler(AsyncStreamHandler):
|
|
73 |
async def receive(self, frame: tuple[int, np.ndarray]) -> None:
|
74 |
if not self.connection:
|
75 |
return
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
async def emit(self) -> tuple[int, np.ndarray] | AdditionalOutputs | None:
|
82 |
return await wait_for_item(self.output_queue)
|
|
|
73 |
async def receive(self, frame: tuple[int, np.ndarray]) -> None:
|
74 |
if not self.connection:
|
75 |
return
|
76 |
+
try:
|
77 |
+
_, array = frame
|
78 |
+
array = array.squeeze()
|
79 |
+
audio_message = base64.b64encode(array.tobytes()).decode("utf-8")
|
80 |
+
await self.connection.input_audio_buffer.append(audio=audio_message) # type: ignore
|
81 |
+
except Exception as e:
|
82 |
+
# 연결이 이미 닫혔거나 다른 오류가 발생한 경우 로그만 남기고 계속 진행
|
83 |
+
print(f"Error in receive: {e}")
|
84 |
+
# 연결이 끊어진 것 같으면 connection을 None으로 설정
|
85 |
+
if "ConnectionClosed" in str(e):
|
86 |
+
self.connection = None
|
87 |
|
88 |
async def emit(self) -> tuple[int, np.ndarray] | AdditionalOutputs | None:
|
89 |
return await wait_for_item(self.output_queue)
|