amd

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package amd implements classic Answering Machine Detection (AMD) by analysing the first few seconds of audio on an outbound call. It measures initial silence, greeting duration and speech/silence patterns to classify the answerer as human, machine, no-speech or not-sure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Analyzer

type Analyzer struct {
	// contains filtered or unexported fields
}

Analyzer performs answering machine detection on a 16 kHz PCM audio stream.

func New

func New(params Params) *Analyzer

New creates an Analyzer with the given parameters.

func (*Analyzer) Params

func (a *Analyzer) Params() Params

Params returns the analyzer's configuration.

func (*Analyzer) Run

func (a *Analyzer) Run(ctx context.Context, reader io.Reader) Detection

Run blocks while reading 16 kHz 16-bit mono PCM from reader, analysing up to TotalAnalysisTime of audio. It returns a Detection when a determination is made or the context is cancelled.

func (*Analyzer) WaitForBeep

func (a *Analyzer) WaitForBeep(ctx context.Context, reader io.Reader) BeepResult

WaitForBeep continues reading audio after a "machine" classification, looking for the voicemail beep tone (800–1200 Hz). It blocks until the beep is found, the timeout expires, or the context is cancelled.

type BeepResult

type BeepResult struct {
	Detected bool
	BeepMs   int // ms from start of beep waiting to detection (0 if not detected)
}

BeepResult holds the outcome of beep detection after a machine classification.

type Detection

type Detection struct {
	Result             Result
	InitialSilenceMs   int
	GreetingDurationMs int
	TotalAnalysisMs    int
}

Detection holds the AMD result and timing measurements.

type Params

type Params struct {
	InitialSilenceTimeout time.Duration // max silence before no_speech
	GreetingDuration      time.Duration // speech length threshold for machine
	AfterGreetingSilence  time.Duration // silence after speech to declare human
	TotalAnalysisTime     time.Duration // hard analysis deadline
	MinimumWordLength     time.Duration // min speech burst to count as a word

	// Beep detection — after classifying "machine", continue listening for
	// the voicemail beep tone so the caller knows when to start speaking.
	// Set to 0 to disable beep detection (default).
	BeepTimeout time.Duration // max time to wait for beep after machine detection
}

Params controls the AMD analysis thresholds.

func DefaultParams

func DefaultParams() Params

DefaultParams returns AMD parameters with sensible defaults matching industry-standard answering machine detection (Asterisk, FreeSWITCH).

func MergeMillis

func MergeMillis(defaults Params, initialSilenceMs, greetingMs, afterGreetingMs, totalMs, minWordMs, beepTimeoutMs int) Params

MergeMillis builds Params by starting from defaults, then overriding with any non-zero millisecond values from the per-call API request.

func (Params) Validate

func (p Params) Validate() error

Validate checks that all parameters are positive and internally consistent.

type Result

type Result string

Result is the AMD classification outcome.

const (
	ResultHuman    Result = "human"
	ResultMachine  Result = "machine"
	ResultNoSpeech Result = "no_speech"
	ResultNotSure  Result = "not_sure"
)

Jump to

Keyboard shortcuts

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