voicemail

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: BSD-2-Clause Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package voicemail detects whether an outbound call reached a person or went to voicemail.

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

Any classifier will do. A classifier/llm classifier needs a service that runs a one-shot inference, so a realtime LLM cannot back the detector.

Index

Constants

View Source
const (
	// EventConversationDetected is raised when a person answered.
	EventConversationDetected = "on_conversation_detected"
	// EventVoicemailDetected is raised when the call went to voicemail and the
	// greeting has been quiet for VoicemailResponseDelay.
	EventVoicemailDetected = "on_voicemail_detected"
)

The events a Detector raises. Each handler receives the detector as its source, which it can push frames through.

Variables

View Source
var Question = classifier.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: []classifier.Option{
		{
			Name: verdictConversation,
			Description: "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",
		},
		{
			Name: verdictVoicemail,
			Description: "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'",
		},
	},
}

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

Functions

This section is empty.

Types

type Config

type Config struct {
	// Classifier decides between a person and a voicemail. It is asked a choice
	// question with the transcript so far. Required, unless LLM is given.
	Classifier classifier.Classifier
	// VoicemailResponseDelay is how long the greeting must be quiet after a
	// voicemail verdict before EventVoicemailDetected is raised, so the message
	// is left after the greeting ends and the recording starts. Nil uses 2s,
	// and zero raises it as soon as the verdict is in.
	VoicemailResponseDelay *time.Duration `validate:"omitnil,min=0"`
	// DecisionTimeout is how long the caller must be quiet after they stop
	// speaking before the latest answer decides. Nil uses 1s, and zero decides
	// as soon as the answer is in. 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.
	DecisionTimeout *time.Duration `validate:"omitnil,min=0"`

	// LLM is a service to build the classifier from, when Classifier is nil.
	//
	// Deprecated: build a classifier/llm classifier and pass it as Classifier.
	LLM llm.Inferencer
	// CustomSystemPrompt is put ahead of the classifier's own instructions for
	// the LLM.
	//
	// Deprecated: build a classifier/llm classifier with the instructions you
	// want and pass it as Classifier.
	CustomSystemPrompt string
}

Config configures a Detector.

type Detector added in v0.3.0

type Detector struct {
	*processor.Base
	// contains filtered or unexported fields
}

Detector 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 DecisionTimeout, the latest answer decides and the detector acts:

  • conversation: the bot's held-back speech is released and the call goes on as normal, and EventConversationDetected is raised.
  • voicemail: the held-back speech is dropped, the pipeline is interrupted, no further input reaches the conversation, and EventVoicemailDetected is raised once the greeting has finished, so the handler can leave a message.

The pipeline places the detector after the STT service and its gate after the TTS service:

detector, err := voicemail.New(voicemail.Config{Classifier: c})
events.OnSignal(detector.Events(), voicemail.EventVoicemailDetected, func(ctx context.Context) {
	_ = detector.PushFrame(ctx, frames.NewTTSSpeakFrame("Please call me back."), processor.Downstream)
})
pipe := pipeline.New(in, stt, detector.Detector(), userAgg, llm, tts, detector.Gate(), out, assistantAgg)

func New

func New(cfg Config) (*Detector, error)

New builds a voicemail detector.

func (*Detector) Classifier added in v0.3.0

func (d *Detector) Classifier() classifier.Classifier

Classifier is what decides between a person and a voicemail.

func (*Detector) Cleanup added in v0.3.0

func (d *Detector) Cleanup(ctx context.Context) error

Cleanup stops the classifying and the timers, and cleans up the classifier.

func (*Detector) Detector added in v0.3.0

func (d *Detector) Detector() *Detector

Detector is the processor to place after the STT service: the detector itself.

func (*Detector) Gate added in v0.3.0

func (d *Detector) Gate() *TTSGate

Gate is the processor to place after the TTS service, holding speech until the decision is made.

func (*Detector) ProcessFrame added in v0.3.0

func (d *Detector) ProcessFrame(ctx context.Context, f frames.Frame, dir processor.Direction) error

ProcessFrame collects transcriptions, keeps the silence timers, and holds everything but the frames that end or control the pipeline back after a voicemail verdict.

func (*Detector) Setup added in v0.3.0

func (d *Detector) Setup(ctx context.Context, s processor.Setup) error

Setup sets up the processor and its classifier, and starts classifying.

type TTSGate added in v0.3.0

type TTSGate struct {
	*processor.Base
	// contains filtered or unexported fields
}

TTSGate 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.

func NewTTSGate added in v0.3.0

func NewTTSGate(conversation, voicemail notify.Notifier) *TTSGate

NewTTSGate builds a gate released by conversation and emptied by voicemail.

func (*TTSGate) Cleanup added in v0.3.0

func (g *TTSGate) Cleanup(ctx context.Context) error

Cleanup stops waiting for the verdict.

func (*TTSGate) ProcessFrame added in v0.3.0

func (g *TTSGate) ProcessFrame(ctx context.Context, f frames.Frame, dir processor.Direction) error

ProcessFrame buffers TTS frames while the decision is pending, and passes the rest.

func (*TTSGate) Setup added in v0.3.0

func (g *TTSGate) Setup(ctx context.Context, s processor.Setup) error

Setup sets up the processor and starts waiting for the verdict.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL