Skip to content

Commit

Permalink
transports(websocket): fix _audio_buffer being accidentally overwri…
Browse files Browse the repository at this point in the history
…tten

`BaseOutputTransport` declares an `_audio_buffer` instance variable.
`WebsocketServerOutputTransport` accidentally reuses that variable
internally assuming it's class-local and not inherited.

This PR renames the variable in `WebsocketServerOutputTransport`
to avoid the name collision.
  • Loading branch information
sharvil committed Aug 17, 2024
1 parent d2dfa93 commit 374f1e7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/pipecat/transports/network/websocket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(self, params: WebsocketServerParams, **kwargs):

self._websocket: websockets.WebSocketServerProtocol | None = None

self._audio_buffer = bytes()
self._websocket_audio_buffer = bytes()

async def set_client_connection(self, websocket: websockets.WebSocketServerProtocol | None):
if self._websocket:
Expand All @@ -132,10 +132,10 @@ async def write_raw_audio_frames(self, frames: bytes):
if not self._websocket:
return

self._audio_buffer += frames
while len(self._audio_buffer) >= self._params.audio_frame_size:
self._websocket_audio_buffer += frames
while len(self._websocket_audio_buffer) >= self._params.audio_frame_size:
frame = AudioRawFrame(
audio=self._audio_buffer[:self._params.audio_frame_size],
audio=self._websocket_audio_buffer[:self._params.audio_frame_size],
sample_rate=self._params.audio_out_sample_rate,
num_channels=self._params.audio_out_channels
)
Expand All @@ -159,7 +159,7 @@ async def write_raw_audio_frames(self, frames: bytes):
if proto:
await self._websocket.send(proto)

self._audio_buffer = self._audio_buffer[self._params.audio_frame_size:]
self._websocket_audio_buffer = self._websocket_audio_buffer[self._params.audio_frame_size:]


class WebsocketServerTransport(BaseTransport):
Expand Down

0 comments on commit 374f1e7

Please sign in to comment.