# audio.duck

> Lowers a music item while speech sounds, with ramps before and after.

Source: https://stuarty.com/docs/mcp/tools/edit/audio.duck/

Writes volume keyframes on the music item: its volume drops by gain_db over attack before each stretch of speech and returns over release after it. Speech stretches closer than the ramps are held low across the gap. The speech comes from the analysis of the speech items and is supplied by the service in resolved; the command never starts a job. The item must have no volume keyframes yet; keyframe.clear on volume undoes the ducking.

## Arguments

| Argument | Type | Required | Notes |
| --- | --- | --- | --- |
| `attack` | `string` | no | A length, may be 0; the ramp down before speech. Default "0.2s". |
| `gain_db` | `number` | no | Change of volume while speech sounds, -40 to -1; default -12.; min -40; max -1 |
| `item_id` | `string` | yes | The music: an audio item with no volume keyframes.; pattern `^itm_[0123456789abcdefghjkmnpqrstvwxyz]{10}$` |
| `release` | `string` | no | A length, may be 0; the ramp up after speech. Default "0.5s". |
| `speech_item_ids` | array of `string` | yes | Clips or audio items that carry the speech.; at least 1 items; at most 20 items |

## Errors

- [`E_VALIDATION`](/docs/reference/error-codes#e_validation)
- [`E_INVALID_TIME`](/docs/reference/error-codes#e_invalid_time)
- [`E_NOT_FOUND`](/docs/reference/error-codes#e_not_found)
- [`E_TYPE_MISMATCH`](/docs/reference/error-codes#e_type_mismatch)
- [`E_INVALID_STATE`](/docs/reference/error-codes#e_invalid_state)
- [`E_LIMIT`](/docs/reference/error-codes#e_limit)

## Scope

Scope `edit`. The scope is the one an API key needs in network mode. Run `stuarty command:help audio.duck` for the same description from the binary, or call the [`command_help`](/docs/mcp/tools/command_help) tool.

## Next steps

- [The edit tool](/docs/mcp/tools/edit)
- [Batches, revisions and idempotency](/docs/agents/batches)

**As an MCP call**

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "edit",
    "arguments": {
      "project_id": "prj_7k2m9x4q1b",
      "base_revision": 12,
      "operations": [
        {
          "op": "audio.duck",
          "args": {
            "gain_db": -12,
            "item_id": "itm_s6t7v8w9x0",
            "speech_item_ids": [
              "itm_m1n2p3q4r5"
            ]
          }
        }
      ]
    }
  }
}
```

**As a batch file for the CLI**

```json
[
  {
    "op": "audio.duck",
    "args": {
      "gain_db": -12,
      "item_id": "itm_s6t7v8w9x0",
      "speech_item_ids": [
        "itm_m1n2p3q4r5"
      ]
    }
  }
]
```

```bash
stuarty edit --project prj_7k2m9x4q1b --ops batch.json --json
```

**Over HTTP**

```bash
curl -X POST "http://127.0.0.1:7878/api/v1/projects/prj_7k2m9x4q1b/edit" \
  -H "Authorization: Bearer $STUARTY_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "base_revision": 12,
  "operations": [
    {
      "op": "audio.duck",
      "args": {
        "gain_db": -12,
        "item_id": "itm_s6t7v8w9x0",
        "speech_item_ids": [
          "itm_m1n2p3q4r5"
        ]
      }
    }
  ]
}'
```

The ids in the example are illustrative: read the real ones with `project_get`.
