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
- Variables
- type Config
- type Detector
- func (d *Detector) Classifier() classifier.Classifier
- func (d *Detector) Cleanup(ctx context.Context) error
- func (d *Detector) Detector() *Detector
- func (d *Detector) Gate() *TTSGate
- func (d *Detector) ProcessFrame(ctx context.Context, f frames.Frame, dir processor.Direction) error
- func (d *Detector) Setup(ctx context.Context, s processor.Setup) error
- type TTSGate
Constants ¶
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 ¶
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; zero uses 2s.
VoicemailResponseDelay time.Duration `validate:"min=0"`
// DecisionTimeout is how long the caller must be quiet after they stop
// speaking before the latest answer decides; zero uses 1s. 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:"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
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 (*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
Cleanup stops the classifying and the timers, and cleans up the classifier.
func (*Detector) Detector ¶ added in v0.3.0
Detector is the processor to place after the STT service: the detector itself.
func (*Detector) Gate ¶ added in v0.3.0
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
ProcessFrame collects transcriptions, keeps the silence timers, and holds everything but the frames that end or control the pipeline back after a voicemail verdict.
type TTSGate ¶ added in v0.3.0
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
NewTTSGate builds a gate released by conversation and emptied by voicemail.
func (*TTSGate) ProcessFrame ¶ added in v0.3.0
ProcessFrame buffers TTS frames while the decision is pending, and passes the rest.