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
float | NoneDefaults to None

Maximum seconds to run the detector before stopping.

control_id
str | NoneDefaults to None

Custom control ID. Auto-generated if not provided.

on_completed
Callable[[RelayEvent], Any] | NoneDefaults to None

Callback invoked when detection completes.

Returns

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

Example

from signalwire.relay import RelayClient
client = RelayClient(
project="your-project-id",
token="your-api-token",
contexts=["default"],
)
@client.on_call
async def handle_call(call):
await call.answer()
# Answering machine detection
action = await call.detect(
detect={"type": "machine", "params": {}},
timeout=30,
)
event = await action.wait()
detect_result = event.params.get("detect", {})
if detect_result.get("type") == "machine":
print("Answering machine detected")
await call.hangup()
else:
print("Human answered")
action = await call.play([{"type": "tts", "params": {"text": "Hello! This is a call from..."}}])
await action.wait()
client.run()