transports(websocket): don't send data if websocket closed

This commit is contained in:
Aleix Conchillo Flaqué
2024-06-28 15:10:19 -07:00
parent e8f58938b0
commit c3244fdd7a
2 changed files with 6 additions and 2 deletions

View File

@@ -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

View File

@@ -12,7 +12,6 @@ import wave
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 @@ class FastAPIWebsocketOutputTransport(BaseOutputTransport):
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:]