Implement UserStartedSpeakingFrame handling in voice pipeline

- Added support for UserStartedSpeakingFrame to enhance user interaction tracking.
- Updated the pipeline to reset idle prompt count when a user starts speaking, improving responsiveness during conversations.
- Integrated new event handlers for better management of user turn events and upstream frame processing.
This commit is contained in:
Xin Wang
2026-05-29 16:51:51 +08:00
parent 13f5f44f61
commit 6df6c16e1d

View File

@@ -10,6 +10,7 @@ from pipecat.frames.frames import (
LLMRunFrame,
OutputTransportMessageUrgentFrame,
TTSSpeakFrame,
UserStartedSpeakingFrame,
)
from pipecat.pipeline.pipeline import Pipeline
from pipecat.pipeline.runner import PipelineRunner
@@ -168,6 +169,7 @@ async def run_pipeline_with_serializer(
),
idle_timeout_secs=config.session.inactivity_timeout_sec,
)
task.set_reached_upstream_filter((UserStartedSpeakingFrame,))
idle_prompt_count = 0
@transport.event_handler("on_client_connected")
@@ -199,6 +201,11 @@ async def run_pipeline_with_serializer(
logger.info(f"{client_label} websocket session timed out")
await task.cancel()
@task.event_handler("on_frame_reached_upstream")
async def on_frame_reached_upstream(_task, _frame: UserStartedSpeakingFrame):
nonlocal idle_prompt_count
idle_prompt_count = 0
@user_aggregator.event_handler("on_user_turn_started")
async def on_user_turn_started(_aggregator, _strategy):
nonlocal idle_prompt_count