RELAYCall

detect

View as MarkdownOpen in Claude

Start audio detection on the call. Detects answering machines, fax tones, or DTMF digits. Returns a DetectAction that resolves on the first detection result or when the operation finishes.

The DetectAction resolves on the first detection result, not when the detect operation finishes. This means await action.wait() returns as soon as a result is available.

This method emits calling.call.detect events. See Call Events for payload details.

Parameters

detect
dictRequired

Detection configuration object.

detect.type
strRequired

Detection type. Valid values:

  • "machine" — answering machine detection (AMD)
  • "fax" — fax tone detection (CNG/CED)
  • "digit" — DTMF digit detection
detect.params
dict

Type-specific detection parameters.

timeout
Optional[float]

Maximum seconds to run the detector before stopping.

control_id
Optional[str]

Custom control ID. Auto-generated if not provided.

on_completed
Optional[Callable[[RelayEvent], Any]]

Callback invoked when detection completes.

Returns

DetectAction — An action handle with stop() and wait() methods.

Example

1from signalwire.relay import RelayClient
2
3client = RelayClient(
4 project="your-project-id",
5 token="your-api-token",
6 host="your-space.signalwire.com",
7 contexts=["default"],
8)
9
10@client.on_call
11async def handle_call(call):
12 await call.answer()
13
14 # Answering machine detection
15 action = await call.detect(
16 detect={"type": "machine", "params": {}},
17 timeout=30,
18 )
19 event = await action.wait()
20
21 detect_result = event.params.get("detect", {})
22 if detect_result.get("type") == "machine":
23 print("Answering machine detected")
24 await call.hangup()
25 else:
26 print("Human answered")
27 action = await call.play([{"type": "tts", "text": "Hello! This is a call from..."}])
28 await action.wait()
29
30client.run()