Merge pull request #3207 from pipecat-ai/aleix/voicemail-conversation-detected-event

VoicemailDetector: add on_conversation_detected event
This commit is contained in:
Aleix Conchillo Flaqué
2025-12-08 11:59:45 -08:00
committed by GitHub
3 changed files with 13 additions and 3 deletions

1
changelog/3207.added.md Normal file
View File

@@ -0,0 +1 @@
- Added `on_conversation_detected` event to `VoicemaiDetector`.

View File

@@ -113,8 +113,12 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
logger.info(f"Client disconnected")
await task.cancel()
@voicemail.event_handler("on_conversation_detected")
async def on_conversation_detected(processor):
logger.info("Conversation detected!")
@voicemail.event_handler("on_voicemail_detected")
async def handle_voicemail(processor):
async def on_voicemail_detected(processor):
logger.info("Voicemail detected! Leaving a message...")
# Push frames using standard Pipecat pattern

View File

@@ -252,7 +252,8 @@ class ClassificationProcessor(FrameProcessor):
self._voicemail_notifier = voicemail_notifier
self._voicemail_response_delay = voicemail_response_delay
# Register the voicemail detected event
# Register the conversation and voicemail detected events
self._register_event_handler("on_conversation_detected")
self._register_event_handler("on_voicemail_detected")
# Aggregation state for collecting complete LLM responses
@@ -350,6 +351,7 @@ class ClassificationProcessor(FrameProcessor):
logger.info(f"{self}: CONVERSATION detected")
await self._gate_notifier.notify() # Close the classifier gate
await self._conversation_notifier.notify() # Release buffered TTS frames
await self._call_event_handler("on_conversation_detected")
elif "VOICEMAIL" in response:
# Voicemail detected - trigger voicemail handling
@@ -539,6 +541,9 @@ class VoicemailDetector(ParallelPipeline):
custom_prompt = "Your custom classification logic here. " + VoicemailDetector.CLASSIFIER_RESPONSE_INSTRUCTION
Events:
on_conversation_detected: Triggered when a human conversation is detected. The
event handler receives one argument: the ClassificationProcessor instance
which can be used to push frames.
on_voicemail_detected: Triggered when voicemail is detected after the configured
delay. The event handler receives one argument: the ClassificationProcessor
instance which can be used to push frames.
@@ -701,7 +706,7 @@ VOICEMAIL SYSTEM (respond "VOICEMAIL"):
event_name: The name of the event to handle.
handler: The function to call when the event occurs.
"""
if event_name == "on_voicemail_detected":
if event_name in ("on_conversation_detected", "on_voicemail_detected"):
self._classification_processor.add_event_handler(event_name, handler)
else:
super().add_event_handler(event_name, handler)