voicemail_detector

Voicemail detection for outbound calls.

A bot that places a call needs to know whether a person answered or the call went to voicemail. VoicemailDetector listens to what the other side says and asks a classifier; until it has an answer, TTSGate holds the bot’s speech back so a voicemail greeting is never talked over.

Any classifier will do. An LLMClassifier needs a service with run_inference(), so a realtime LLM cannot back the detector.

pipecat.extensions.voicemail.voicemail_detector.VOICEMAIL_QUESTION = ChoiceQuestion(instructions='A bot has placed an outbound phone call. This is what was heard after the call connected. Decide whether a person answered or the call went to voicemail.', options={'conversation': "a person answered: a greeting such as 'hello?', 'hi', 'yeah?' or 'John speaking'; a question to the caller such as 'who is this?' or 'can I help you?'; spontaneous speech that expects a reply", 'voicemail': "an automated greeting or carrier message: 'you've reached', 'leave a message', 'I'm not available right now', 'call me back', 'mailbox is full', 'not in service', 'all circuits are busy', 'our office is currently closed'"})

The question put to the classifier, with the transcript so far as the state.

class pipecat.extensions.voicemail.voicemail_detector.TTSGate(conversation_notifier: BaseNotifier, voicemail_notifier: BaseNotifier)[source]

Bases: FrameProcessor

Holds the bot’s speech until the voicemail decision is made.

Placed right after the TTS service. TTS frames are buffered while the decision is pending; every other frame passes through. A conversation verdict releases the buffered frames in order, a voicemail verdict discards them, since they were meant for a person.

__init__(conversation_notifier: BaseNotifier, voicemail_notifier: BaseNotifier)[source]

Initialize the TTS gate.

Parameters:
  • conversation_notifier – Signals that a person answered and the buffered frames should play.

  • voicemail_notifier – Signals that the call went to voicemail and the buffered frames should be dropped.

async setup(setup: FrameProcessorSetup)[source]

Set up the processor with required components.

Parameters:

setup – Configuration object containing setup parameters.

async cleanup()[source]

Clean up the processor resources.

async process_frame(frame: Frame, direction: FrameDirection)[source]

Buffer TTS frames while the decision is pending; pass the rest.

Parameters:
  • frame – The frame to process.

  • direction – The direction of frame flow in the pipeline.

class pipecat.extensions.voicemail.voicemail_detector.VoicemailDetector(*, classifier: BaseClassifier | None = None, voicemail_response_delay: float = 2.0, decision_timeout: float = 1.0, llm: LLMService | None = None, custom_system_prompt: str | None = None)[source]

Bases: FrameProcessor

Decides whether a person answered an outbound call or it went to voicemail.

Placed after the STT service. It passes every frame through and collects what the other side says. After each transcription it asks its classifier, in the background, whether the call reached a person or a voicemail, and keeps asking as more is said. Once the caller has been quiet for decision_timeout, the latest answer decides and the detector acts:

  • CONVERSATION: the bot’s held-back speech is released and the call goes on as normal.

  • VOICEMAIL: the held-back speech is dropped, the pipeline is interrupted, no further input reaches the conversation, and on_voicemail_detected fires once the greeting has finished, so the handler can leave a message.

Example:

detector = VoicemailDetector(classifier=JevClassifier(api_key=...))

@detector.event_handler("on_voicemail_detected")
async def handle_voicemail(processor):
    await processor.push_frame(TTSSpeakFrame("Please call me back."))

pipeline = Pipeline([
    transport.input(),
    stt,
    detector.detector(),          # Classification
    context_aggregator.user(),
    llm,
    tts,
    detector.gate(),              # TTS gating
    transport.output(),
    context_aggregator.assistant(),
])

Event handlers available:

  • on_conversation_detected: A person answered. The handler receives the detector, which it can push frames through.

  • on_voicemail_detected: The call went to voicemail and the greeting has been quiet for voicemail_response_delay seconds. The handler receives the detector, which it can push frames through.

__init__(*, classifier: BaseClassifier | None = None, voicemail_response_delay: float = 2.0, decision_timeout: float = 1.0, llm: LLMService | None = None, custom_system_prompt: str | None = None)[source]

Initialize the voicemail detector.

Parameters:
  • classifier – What decides between a person and a voicemail. It is asked a choice question with the transcript so far.

  • voicemail_response_delay – Seconds of silence after a voicemail verdict before on_voicemail_detected fires, so the message is left after the greeting ends and the recording starts.

  • decision_timeout – Seconds of silence after the caller stops speaking before the latest answer decides. A greeting resumes after its pauses while a person stays quiet, so a verdict on a fragment such as “hi, this is Sam” is not acted on until the caller has really stopped.

  • llm –

    LLM service used for the classification.

    Deprecated since version 1.12.0: Use classifier instead. Will be removed in 2.0.0.

  • custom_system_prompt –

    System prompt for the llm.

    Deprecated since version 1.12.0: Use classifier instead. Will be removed in 2.0.0.

detector() → VoicemailDetector[source]

The processor to place after the STT service.

Returns:

This detector.

gate() → TTSGate[source]

The processor to place after the TTS service.

Returns:

The gate that holds speech until the decision is made.

async setup(setup: FrameProcessorSetup)[source]

Set up the processor and its classifier.

Parameters:

setup – Configuration object containing setup parameters.

async cleanup()[source]

Clean up the processor and its classifier.

async process_frame(frame: Frame, direction: FrameDirection)[source]

Collect transcriptions, keep the voicemail timer, and gate after a voicemail.

Parameters:
  • frame – The frame to process.

  • direction – The direction of frame flow in the pipeline.