***

title: detect
slug: /reference/python/relay/call/detect
description: Detect answering machines, fax tones, or digits on a call.
max-toc-depth: 3
---------------------

For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

[detectaction]: /docs/server-sdks/reference/python/relay/actions

[calling-call-detect]: /docs/server-sdks/reference/python/relay/call#events

[call-events]: /docs/server-sdks/reference/python/relay/call#events

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

<Note>
  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.
</Note>

<Info>
  This method emits [`calling.call.detect`][calling-call-detect] events. See [Call Events][call-events] for payload details.
</Info>

## **Parameters**

<ParamField path="detect" type="dict" required={true} toc={true}>
  Detection configuration object.
</ParamField>

<Indent>
  <ParamField path="detect.type" type="str" required={true} toc={true}>
    Detection type. Valid values:

    * `"machine"` -- answering machine detection (AMD)
    * `"fax"` -- fax tone detection (CNG/CED)
    * `"digit"` -- DTMF digit detection
  </ParamField>

  <ParamField path="detect.params" type="dict" toc={true}>
    Type-specific detection parameters.
  </ParamField>
</Indent>

<ParamField path="timeout" type="Optional[float]" toc={true}>
  Maximum seconds to run the detector before stopping.
</ParamField>

<ParamField path="control_id" type="Optional[str]" toc={true}>
  Custom control ID. Auto-generated if not provided.
</ParamField>

<ParamField path="on_completed" type="Optional[Callable[[RelayEvent], Any]]" toc={true}>
  Callback invoked when detection completes.
</ParamField>

## **Returns**

[`DetectAction`][detectaction] -- An action handle with
`stop()` and `wait()` methods.

## **Example**

```python {15}
from signalwire.relay import RelayClient

client = RelayClient(
    project="your-project-id",
    token="your-api-token",
    host="your-space.signalwire.com",
    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", "text": "Hello! This is a call from..."}])
        await action.wait()

client.run()
```