From c3244fdd7a3b224f0cd2b0a2fac6daaafb5cf7f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Fri, 28 Jun 2024 15:10:19 -0700 Subject: [PATCH] transports(websocket): don't send data if websocket closed --- CHANGELOG.md | 5 +++++ src/pipecat/transports/network/fastapi_websocket.py | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e7e7f87b..634be9b69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 processing metrics indicate the time a processor needs to generate all its output. Note that not all processors generate these kind of metrics. +### Fixed + +- Fixed an issue in `FastAPIWebsocketTransport` where it would still try to send + data to the websocket after being closed. + ## [0.0.35] - 2024-06-28 ### Changed diff --git a/src/pipecat/transports/network/fastapi_websocket.py b/src/pipecat/transports/network/fastapi_websocket.py index cf71ee021..8b9877d09 100644 --- a/src/pipecat/transports/network/fastapi_websocket.py +++ b/src/pipecat/transports/network/fastapi_websocket.py @@ -12,7 +12,6 @@ from typing import Awaitable, Callable from pydantic.main import BaseModel -from pipecat.serializers.twilio import TwilioFrameSerializer from pipecat.frames.frames import AudioRawFrame, StartFrame from pipecat.processors.frame_processor import FrameProcessor from pipecat.serializers.base_serializer import FrameSerializer @@ -114,7 +113,7 @@ async def write_raw_audio_frames(self, frames: bytes): frame = wav_frame payload = self._params.serializer.serialize(frame) - if payload: + if payload and self._websocket.client_state == WebSocketState.CONNECTED: await self._websocket.send_text(payload) self._audio_buffer = self._audio_buffer[self._params.audio_frame_size:]