Skip to content

Commit

Permalink
Merge pull request #745 from pipecat-ai/mb/user-idle
Browse files Browse the repository at this point in the history
Only run the UserIdleProcessor while pipeline is running
  • Loading branch information
markbackman authored Dec 5, 2024
2 parents 672b1c6 + 897e024 commit 00fd381
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/pipecat/processors/user_idle_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
#

import asyncio

from typing import Awaitable, Callable

from pipecat.frames.frames import (
BotSpeakingFrame,
CancelFrame,
EndFrame,
Frame,
UserStartedSpeakingFrame,
UserStoppedSpeakingFrame,
Expand All @@ -32,20 +33,25 @@ def __init__(
**kwargs,
):
super().__init__(**kwargs)

self._callback = callback
self._timeout = timeout

self._interrupted = False

self._create_idle_task()

async def _stop(self):
self._idle_task.cancel()
await self._idle_task

async def process_frame(self, frame: Frame, direction: FrameDirection):
await super().process_frame(frame, direction)

# Check for end frames before processing
if isinstance(frame, (EndFrame, CancelFrame)):
await self._stop()

await self.push_frame(frame, direction)

# We shouldn't call the idle callback if the user or the bot are speaking.
# We shouldn't call the idle callback if the user or the bot are speaking
if isinstance(frame, UserStartedSpeakingFrame):
self._interrupted = True
self._idle_event.set()
Expand All @@ -56,8 +62,7 @@ async def process_frame(self, frame: Frame, direction: FrameDirection):
self._idle_event.set()

async def cleanup(self):
self._idle_task.cancel()
await self._idle_task
await self._stop()

def _create_idle_task(self):
self._idle_event = asyncio.Event()
Expand Down

0 comments on commit 00fd381

Please sign in to comment.