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/llmclassifier classifier needs a service that runs a one-shot inference, so a realtime LLM cannot back the detector.
Index ¶
- Constants
- func Question() classifier.ChoiceQuestion
- 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 ¶
This section is empty.
Functions ¶
func Question ¶ added in v0.3.0
func Question() classifier.ChoiceQuestion
Question returns the question put to the classifier. The copy is the caller's to change.
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"`
}
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})
event.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.