> ## Documentation Index
> Fetch the complete documentation index at: https://www.voiceflow.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Audio input and transcription

> Send microphone audio and receive partial and committed transcriptions.

Use speech recognition on an [initialized Voice session](/docs/api-reference/conversations-api/interact-socket#initialization-sequence). Configure input and output formats separately: `asr.start.audio` selects microphone input; `client.start.config.audioEncoding` selects agent output.

## Start and stop recognition

Register listeners before starting. Wait for `asr.started` before forwarding audio. Stop forwarding when `asr.stopped` arrives.

```js title="Start recognition on the connected socket"
socket.on('asr.started', ({ audio, turns }) => {
  // Start forwarding frames encoded in the acknowledged audio format.
  console.log(audio, turns);
});
socket.on('asr.stopped', ({ reason }) => {
  // Stop forwarding input. Resolve quota or error before restarting.
  console.log(reason);
});
socket.emit('asr.start', {
  audio: { encoding: 'audio/pcm', sampleRate: 16000 },
  turns: 'server',
  stopWhenIdle: false,
});
// When listening ends:
// socket.emit('asr.stop', {});
```

Send raw binary frames with `asr.audio.send`. Base64 and JSON strings are rejected. A browser MediaRecorder container is not raw PCM; encode audio in the acknowledged format before sending it.

## Choose turn handling

| Mode | Who submits recognized speech | Your application |
| --- | --- | --- |
| `server` | The runtime | Display transcripts; do not submit the same utterance again as a text action. |
| `client` (default) | Your client | Submit the committed transcript using [`action.send`](/docs/api-reference/conversations-api/interact-socket#action-send). |

Partial transcripts can change; the committed `asr.transcript` replaces them. Speech-recognition provider settings come from the selected Environment. With `stopWhenIdle: false`, recognition remains open through silence. For output and interruption handling, see [Playback and responses](/docs/api-reference/agent-runtime/voice/playback).

## Recognition events

### `asr.start`

**Client → server.** Open speech recognition on the ready session. The server replies with asr.started or asr.stopped. Speech-recognition provider settings come from the selected Environment.

| Field | Type | Required | Default |
| --- | --- | --- | --- |
| `audio` | SocketASRAudioFormat | no | `{"encoding":"audio/pcm","sampleRate":16000}` |
| `stopWhenIdle` | boolean | no | `true` |
| `turns` | SocketASRTurnsEnum | no | `"client"` |

Supported input formats:

| Encoding | Sample rate |
| --- | --- |
| `"audio/x-mulaw"` | 8000 Hz |
| `"audio/pcm"` | 16000 Hz |
| `"audio/pcm"` | 8000 Hz |

`SocketASRTurnsEnum`: `"client"`, `"server"`.

### `asr.audio.send`

**Client → server.** Send a binary frame in the format acknowledged by asr.started. ArrayBuffer, typed-array and Buffer frames are accepted; JSON strings and base64 text are not.

Payload: a raw binary audio frame in the format selected by `asr.start`.

### `asr.started`

**Server → client.** Recognition is ready. The payload echoes the audio format and turn-handling options the server applied. Begin forwarding audio after this event.

| Field | Type | Required | Default |
| --- | --- | --- | --- |
| `audio` | SocketASRAudioFormat | yes | — |
| `stopWhenIdle` | boolean | yes | — |
| `turns` | SocketASRTurnsEnum | yes | — |

Supported input formats:

| Encoding | Sample rate |
| --- | --- |
| `"audio/x-mulaw"` | 8000 Hz |
| `"audio/pcm"` | 16000 Hz |
| `"audio/pcm"` | 8000 Hz |

`SocketASRTurnsEnum`: `"client"`, `"server"`.

### `asr.stop`

**Client → server.** Close speech recognition. The server replies with asr.stopped.

Payload: `{}`.

### `asr.stopped`

**Server → client.** Recognition has stopped, or could not start. Stop forwarding audio and inspect the reason: client, idle, max_duration, error or quota.

| Field | Type | Required | Default |
| --- | --- | --- | --- |
| `reason` | SocketASRStopReasonEnum | yes | — |

`SocketASRStopReasonEnum`: `"client"`, `"idle"`, `"max_duration"`, `"error"`, `"quota"`.

### `asr.transcript`

**Server → client.** A committed transcription of the customer’s utterance. Server turns submit it automatically; client turns require your application to submit it.

| Field | Type | Required | Default |
| --- | --- | --- | --- |
| `text` | string | yes | — |
| `confidence` | number | yes | — |
| `reason` | string | yes | — |

### `asr.transcript.partial`

**Server → client.** Revisable words heard so far. Use them for a live transcript display; the committed asr.transcript supersedes them.

| Field | Type | Required | Default |
| --- | --- | --- | --- |
| `words` | object[] | yes | — |

`words` item fields:

| Field | Type | Required | Default |
| --- | --- | --- | --- |
| `word` | string | yes | — |
| `start` | number | yes | — |
| `end` | number | yes | — |
