# audio

> `const` **audio**: `object`

Defined in: [sdk/js/src/audio.ts:29](https://github.com/zaunchat/zaun-bot/blob/main/sdk/js/src/audio.ts#L29)

The bot's audio output stream. Errors throw `ZaunError`.

## Type Declaration

### bufferedMs()

> **bufferedMs**(): `number`

The audio written and not yet played, in ms (0 without a stream).

#### Returns

`number`

### clear()

> **clear**(): `void`

Drops everything buffered at once; the stream stays open.

#### Returns

`void`

### close()

> **close**(`drain?`): `void`

Closes the stream, after the buffer has played (`drain`, the default) or at once.

#### Parameters

##### drain?

`boolean` = `true`

#### Returns

`void`

### open()

> **open**(`options`): `void`

Opens the stream, pausing the player. `CONFLICT` when the bot is in no voice channel or a
stream is open; `UNSUPPORTED` for a format the host cannot take (PCM without an encoder).

#### Parameters

##### options

[`AudioStreamOptions`](/docs/reference/js/zaun-bot/interfaces/audiostreamoptions/)

#### Returns

`void`

### writeOpus()

> **writeOpus**(`packets`): `number`

Opus packets (2.5–120 ms each, ≤ 1000 bytes); returns the ms buffered (`BUSY` past 3 s).

#### Parameters

##### packets

`Uint8Array`\<`ArrayBufferLike`\>[]

#### Returns

`number`

### writePcm()

> **writePcm**(`samples`): `number`

Interleaved samples, any count; returns the ms buffered (`BUSY` past 3 s).

#### Parameters

##### samples

`Int16Array`

#### Returns

`number`
