Skip to content

Commit

Permalink
Merge pull request #390 from sharvil/pr/websocket-fix
Browse files Browse the repository at this point in the history
transports(websocket): fix `_audio_buffer` being accidentally overwritten
  • Loading branch information
aconchillo authored Aug 18, 2024
2 parents cf5720f + 374f1e7 commit 9e7c0e6
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 9e7c0e6

Please sign in to comment.