Skip to content

Commit

Permalink
Move stop frame task creation into TTSService.start
Browse files Browse the repository at this point in the history
  • Loading branch information
sharvil committed Aug 27, 2024
1 parent c979762 commit 87c4a1b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/pipecat/services/ai_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,20 @@ async def process_frame(self, frame: Frame, direction: FrameDirection):
else:
await self.push_frame(frame, direction)

async def start(self, frame: StartFrame):
await super().start(frame)
if self._push_stop_frames:
self._stop_frame_task = self.get_event_loop().create_task(self._stop_frame_handler())

async def stop(self, frame: EndFrame):
await super().stop(frame)
if self._stop_frame_task:
self._stop_frame_task.cancel()
await self._stop_frame_task
self._stop_frame_task = None

async def cancel(self, frame: CancelFrame):
await super().cancel(frame)
if self._stop_frame_task:
self._stop_frame_task.cancel()
await self._stop_frame_task
Expand All @@ -258,9 +265,6 @@ async def push_frame(self, frame: Frame, direction: FrameDirection = FrameDirect
isinstance(frame, TTSStartedFrame) or
isinstance(frame, AudioRawFrame) or
isinstance(frame, TTSStoppedFrame)):
if self._stop_frame_task is None:
event_loop = self.get_event_loop()
self._stop_frame_task = event_loop.create_task(self._stop_frame_handler())
await self._stop_frame_queue.put(frame)

async def _stop_frame_handler(self):
Expand Down

0 comments on commit 87c4a1b

Please sign in to comment.