# Native mode

Stream raw audio frames from your own server and get clean frames at your bot.

Use native mode when your own server holds the raw audio. Send one 20 ms frame per message; the clean frame arrives at your redirect URL with the same `frame_id`.

## Message sequence

1. Connect to the Enhancer URL with your key and redirect.
2. You receive `{"type":"connected","message":"connected successfully"}`.
3. Send the config. You can skip it and use URL parameters or the defaults; a config message wins over URL parameters.

```json
{"type":"config","sample_rate":8000,"frame_duration":20,"suppression_level":100}
```

4. Your redirect URL is opened and receives `{"type":"ready","message":"Denoise service initialized and ready"}`.
5. Send audio, one frame per message, in real time (one every 20 ms). `data` is 16-bit signed samples as JSON numbers: 160 per frame at 8 kHz and 20 ms.

```json
{"type":"audio","data":[12,-40,301],"frame_id":0}
```

6. Your redirect receives each clean frame with the same `frame_id`:

```json
{"type":"audio","data":[3,-11,280],"frame_id":0}
```

7. To finish, send `{"type":"close"}`. The last frames go to your redirect, then both sockets close.

The `data` arrays above are cut short; real frames hold 160 samples. Nothing else comes back on your own socket: clean audio and any `{"type":"error"}` message go to the redirect.

## Minimal client (Python)

```python
import asyncio, json, websockets

async def run(url, frames):  # frames: lists of 160 int16 samples
    async with websockets.connect(url) as ws:
        await ws.recv()  # {"type":"connected"}
        await ws.send(json.dumps({"type": "config", "sample_rate": 8000,
                                  "frame_duration": 20, "suppression_level": 100}))
        for i, f in enumerate(frames):
            await ws.send(json.dumps({"type": "audio", "data": f, "frame_id": i}))
            await asyncio.sleep(0.02)  # keep real-time pace
        await ws.send(json.dumps({"type": "close"}))
```
