> ## Documentation Index
> Fetch the complete documentation index at: https://developer.sanas.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# State Callbacks

State callbacks let you react to audio processor state changes in real time, without polling `GetState()`. You pass a callback function when creating a processor, and the SDK calls it whenever the processor transitions between states (for example, from `INITIALIZING` to `READY`, or to `DISCONNECTED` if the connection drops).

<Note>Without callbacks, you will not receive processor status updates automatically and will need to poll `GetState()` manually. Callbacks are the recommended approach for handling state changes.</Note>

## Callback Signature

```python theme={null}
def state_callback(state: int, reason: str) -> None
```

| Parameter | Type     | Description                                  |
| --------- | -------- | -------------------------------------------- |
| `state`   | `int`    | A `ProcessorState` enum value                |
| `reason`  | `string` | A human-readable reason for the state change |

## Example

Define a callback function and pass it when creating a processor. The SDK will call it whenever the processor state changes:

```python theme={null}
import sanas_remote_sdk

def on_state_change(state, reason):
    if state == sanas_remote_sdk.ProcessorState.READY:
        print("Processor ready for audio processing")
    elif state == sanas_remote_sdk.ProcessorState.FAILED:
        print(f"Processor failed: {reason}")
    elif state == sanas_remote_sdk.ProcessorState.DISCONNECTED:
        print(f"Processor disconnected: {reason}")

# Pass the callback when creating a processor
processor, result = sdk.CreateAudioProcessor(audio_params, on_state_change)
```

## See Also

<CardGroup cols={2}>
  <Card title="ProcessorState" icon="signal" href="/API-Reference/Reference/State-Enums/ProcessorState">
    All possible state values your callback can receive
  </Card>

  <Card title="RemoteSDK" icon="server" href="/API-Reference/Reference/Core-Classes/RemoteSDK">
    The `CreateAudioProcessor()` method accepts the callback parameter
  </Card>
</CardGroup>
