diff --git a/changelog/3207.added.md b/changelog/3207.added.md new file mode 100644 index 000000000..3b480a561 --- /dev/null +++ b/changelog/3207.added.md @@ -0,0 +1 @@ +- Added `on_conversation_detected` event to `VoicemaiDetector`. diff --git a/examples/foundational/44-voicemail-detection.py b/examples/foundational/44-voicemail-detection.py index 711c2591f..3d12151da 100644 --- a/examples/foundational/44-voicemail-detection.py +++ b/examples/foundational/44-voicemail-detection.py @@ -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 diff --git a/src/pipecat/extensions/voicemail/voicemail_detector.py b/src/pipecat/extensions/voicemail/voicemail_detector.py index e79520cb5..3849bc983 100644 --- a/src/pipecat/extensions/voicemail/voicemail_detector.py +++ b/src/pipecat/extensions/voicemail/voicemail_detector.py @@ -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)