From c44455796590202fc45a1fcc0b362825c0994144 Mon Sep 17 00:00:00 2001 From: Vaibhav159 Date: Fri, 17 Jan 2025 19:50:53 +0530 Subject: [PATCH 1/2] fixing IdleFrameProcessor and UserIdleProcessor init logic --- CHANGELOG.md | 3 +++ src/pipecat/processors/idle_frame_processor.py | 7 ++++--- src/pipecat/processors/user_idle_processor.py | 6 ++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a47979a85..be58657a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -95,6 +95,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed an issue where setting the voice and model for `RimeHttpTTSService` wasn't working. +- Fixed an issue where `IdleFrameProcessor` and `UserIdleProcessor` were getting + initialized before the start of the pipeline. + ## [0.0.52] - 2024-12-24 ### Added diff --git a/src/pipecat/processors/idle_frame_processor.py b/src/pipecat/processors/idle_frame_processor.py index 3ed52c354..3f5f51e45 100644 --- a/src/pipecat/processors/idle_frame_processor.py +++ b/src/pipecat/processors/idle_frame_processor.py @@ -7,7 +7,7 @@ import asyncio from typing import Awaitable, Callable, List -from pipecat.frames.frames import Frame +from pipecat.frames.frames import Frame, StartFrame from pipecat.processors.frame_processor import FrameDirection, FrameProcessor @@ -31,11 +31,12 @@ class IdleFrameProcessor(FrameProcessor): self._timeout = timeout self._types = types - self._create_idle_task() - async def process_frame(self, frame: Frame, direction: FrameDirection): await super().process_frame(frame, direction) + if isinstance(frame, StartFrame): + self._create_idle_task() + await self.push_frame(frame, direction) # If we are not waiting for any specific frame set the event, otherwise diff --git a/src/pipecat/processors/user_idle_processor.py b/src/pipecat/processors/user_idle_processor.py index 44027787a..754bbca20 100644 --- a/src/pipecat/processors/user_idle_processor.py +++ b/src/pipecat/processors/user_idle_processor.py @@ -14,6 +14,7 @@ from pipecat.frames.frames import ( Frame, UserStartedSpeakingFrame, UserStoppedSpeakingFrame, + StartFrame, ) from pipecat.processors.frame_processor import FrameDirection, FrameProcessor @@ -36,7 +37,6 @@ class UserIdleProcessor(FrameProcessor): self._callback = callback self._timeout = timeout self._interrupted = False - self._create_idle_task() async def _stop(self): self._idle_task.cancel() @@ -46,7 +46,9 @@ class UserIdleProcessor(FrameProcessor): await super().process_frame(frame, direction) # Check for end frames before processing - if isinstance(frame, (EndFrame, CancelFrame)): + if isinstance(frame, StartFrame): + self._create_idle_task() + elif isinstance(frame, (EndFrame, CancelFrame)): await self._stop() await self.push_frame(frame, direction) From 80779c48d619f5a192cfeccfb329cac90fe252ca Mon Sep 17 00:00:00 2001 From: Vaibhav159 Date: Fri, 17 Jan 2025 20:07:25 +0530 Subject: [PATCH 2/2] sort fix --- src/pipecat/processors/user_idle_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pipecat/processors/user_idle_processor.py b/src/pipecat/processors/user_idle_processor.py index 754bbca20..8f40fd52e 100644 --- a/src/pipecat/processors/user_idle_processor.py +++ b/src/pipecat/processors/user_idle_processor.py @@ -12,9 +12,9 @@ from pipecat.frames.frames import ( CancelFrame, EndFrame, Frame, + StartFrame, UserStartedSpeakingFrame, UserStoppedSpeakingFrame, - StartFrame, ) from pipecat.processors.frame_processor import FrameDirection, FrameProcessor