detectAnsweringMachine

View as Markdown

detectAnsweringMachine

  • detectAnsweringMachine(params?): Promise<CallDetect>

Detects the presence of an answering machine.

Parameters

params
object

Object containing the parameters for answering machine detection.

timeout
numberDefaults to 30.0

Number of seconds to run the detector for.

waitForBeep
booleanDefaults to false

Whether to wait until the device is ready for voicemail delivery.

initialTimeout
numberDefaults to 4.5

Number of seconds to wait for initial voice before giving up.

endSilenceTimeout
numberDefaults to 1.0

Number of seconds to wait for voice to finish.

machineReadyTimeout
number

Number of seconds to wait for voice to finish before firing the READY event. Default is the value of endSilenceTimeout.

machineVoiceThreshold
numberDefaults to 1.25

How many seconds of voice to decide it is a machine.

machineWordsThreshold
numberDefaults to 6

How many words to count to decide it is a machine.

detectInterruptions
booleanDefaults to false

If set to true, a NOT_READY event is fired if speech is detected after the READY event. This allows the application to restart message delivery to the answering machine.

listen
object

Callback to listen for events. List of detect events can be found here. Example event: onStarted.

Returns

Promise<CallDetect>

A promise that resolves to a CallDetect object that you can use to view the current state and results of the detect session.

Example

In this example, we dial a phone number and wait for the answering machine detection to finish. Once the detection is finished, we log the result and then play a TTS message. At the end of the TTS message, we hangup the call.

1import { SignalWire } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
4
5const voiceClient = client.voice;
6
7try {
8 // Outbound Dial
9 const call = await voiceClient.dialPhone({
10 from: "SignalWire From Number Here",
11 to: "Destination Number Here",
12 timeout: 30,
13 listen: {
14 onStateChanged: (call) => {
15 console.log("Call state changed:", call.state);
16 }
17 }
18 });
19
20 // Answering machine detection
21 await call.detectAnsweringMachine({
22 waitForBeep: true,
23 endSilenceTimeout: 4,
24 listen: {
25 onStarted: () => {
26 console.log("Answering machine detection started");
27 },
28 onUpdated: (event) => {
29 console.log("Answering machine detection updated:", event.result);
30 },
31 onEnded: async (event) => {
32 console.log("Answering machine detection ended:", event.result);
33 }
34 }
35 });
36 // Plays a TTS message after the answering machine detection is finished.
37 // Then the Call will hangup after the TTS message is finished.
38 await call.playTTS({ text: "Hello, this is a test call from SignalWire!" });
39 call.hangup();
40} catch (e) {
41 console.log("Call not answered.", e);
42}