Detection in a few lines of code.
The libraries send the callee’s audio to the API and hand back each verdict as it comes. They hold audio until the connection opens, split frames that are too large and give every failure a code you can act on.
- Node.jsNode.js 22 or newer. One dependency,
ws. - PythonPython 3.10 or newer, with a regular and an asyncio client. One dependency,
websockets.
Both are open source under Apache-2.0.
Install
npm install voicemaildetector
pip install voicemaildetectorCreate a key in the dashboard and put it in VD_API_KEY; the clients read it from there.
Live calls
Open one stream per call when it is answered and send the callee’s audio as it arrives. The call goes on at once: frames sent before the connection opens are held and sent once it does.
import {VoicemailDetector} from 'voicemaildetector'
const vd = new VoicemailDetector() // reads VD_API_KEY
// When the call is answered: your agent starts talking, and detection runs beside it.
const detection = vd.stream({encoding: 'mulaw'})
detection.on('result', result => {
if (result.verdict === 'machine') call.hangUp()
})
call.on('calleeAudio', frame => detection.send(frame)) // 20 ms frames
call.on('end', () => detection.end())A call can get a second result. When a machine shows up after a human verdict, an after_human machine result arrives while watch_ms lasts, so keep sending audio until then.
Recordings
Send a whole file of up to 8 MiB: a path, bytes or a file object. A WAV carries its own format; raw audio needs encoding.
const result = await vd.detect('call-0193.wav')
console.log(result.verdict) // machineErrors
Every failure is a VoicemailDetectorError. Its code is the API’s error code, such as payment_required, too_many_calls or busy, or connection and timeout for the network, and retryable says whether the same call can go through shortly. A refused call is refused at once, so your dialer can fall back right away.
import {VoicemailDetectorError} from 'voicemaildetector'
try {
await detection.verdict
} catch (err) {
if (err instanceof VoicemailDetectorError && err.code === 'payment_required') notifyBilling()
// err.retryable is true for busy, not_ready, connection and timeout
}Twilio and Telnyx
Twilio and Telnyx send call audio as JSON over their own WebSocket. Each library has a relay example that forwards that audio and hangs up on machines through the platform’s API.
Code and other languages
Code, releases and examples: voicemaildetector-node and voicemaildetector-python. From any other language, use the WebSocket or gRPC API in the reference. On Asterisk and Vicidial, the connector needs no code at all.